Fixed problem with closing socket.

This commit is contained in:
yhirose 2012-10-04 00:52:12 -04:00
parent 1d0b3504bd
commit d187cdef50
2 changed files with 6 additions and 15 deletions

View File

@ -217,7 +217,7 @@ inline socket_t create_server_socket(const char* host, int port)
});
}
inline int close_server_socket(socket_t sock)
inline int close_socket(socket_t sock)
{
#ifdef _WIN32
shutdown(sock, SD_BOTH);
@ -241,15 +241,6 @@ inline socket_t create_client_socket(const char* host, int port)
});
}
inline int close_client_socket(socket_t sock)
{
#ifdef _WIN32
return closesocket(sock);
#else
return close(sock);
#endif
}
inline const char* status_message(int status)
{
const char* s = NULL;
@ -485,7 +476,7 @@ inline bool Server::run()
return true;
}
close_server_socket(sock_);
close_socket(sock_);
return false;
}
@ -496,7 +487,7 @@ inline bool Server::run()
process_request(fp_read, fp_write);
fflush(fp_write);
close_server_socket(fd);
close_socket(fd);
}
// NOTREACHED
@ -504,7 +495,7 @@ inline bool Server::run()
inline void Server::stop()
{
close_server_socket(sock_);
close_socket(sock_);
sock_ = -1;
}
@ -674,7 +665,7 @@ inline bool Client::send(const Request& req, Response& res)
return false;
}
close_client_socket(sock);
close_socket(sock);
return true;
}

View File

@ -46,7 +46,7 @@ TEST(SocketTest, OpenClose)
socket_t sock = create_server_socket("localhost", 1914);
ASSERT_NE(-1, sock);
auto ret = close_server_socket(sock);
auto ret = close_socket(sock);
EXPECT_EQ(0, ret);
}