Fixed problem with closing socket.
This commit is contained in:
parent
1d0b3504bd
commit
d187cdef50
19
httplib.h
19
httplib.h
@ -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
|
#ifdef _WIN32
|
||||||
shutdown(sock, SD_BOTH);
|
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)
|
inline const char* status_message(int status)
|
||||||
{
|
{
|
||||||
const char* s = NULL;
|
const char* s = NULL;
|
||||||
@ -485,7 +476,7 @@ inline bool Server::run()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
close_server_socket(sock_);
|
close_socket(sock_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,7 +487,7 @@ inline bool Server::run()
|
|||||||
process_request(fp_read, fp_write);
|
process_request(fp_read, fp_write);
|
||||||
|
|
||||||
fflush(fp_write);
|
fflush(fp_write);
|
||||||
close_server_socket(fd);
|
close_socket(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTREACHED
|
// NOTREACHED
|
||||||
@ -504,7 +495,7 @@ inline bool Server::run()
|
|||||||
|
|
||||||
inline void Server::stop()
|
inline void Server::stop()
|
||||||
{
|
{
|
||||||
close_server_socket(sock_);
|
close_socket(sock_);
|
||||||
sock_ = -1;
|
sock_ = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -674,7 +665,7 @@ inline bool Client::send(const Request& req, Response& res)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
close_client_socket(sock);
|
close_socket(sock);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ TEST(SocketTest, OpenClose)
|
|||||||
socket_t sock = create_server_socket("localhost", 1914);
|
socket_t sock = create_server_socket("localhost", 1914);
|
||||||
ASSERT_NE(-1, sock);
|
ASSERT_NE(-1, sock);
|
||||||
|
|
||||||
auto ret = close_server_socket(sock);
|
auto ret = close_socket(sock);
|
||||||
EXPECT_EQ(0, ret);
|
EXPECT_EQ(0, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user