Skip to content

Commit 37130cd

Browse files
committed
Changed to use INVALID_SOCKET
1 parent 75285e8 commit 37130cd

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

httplib.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#endif
4040

4141
typedef SOCKET socket_t;
42-
constexpr socket_t kInvalidSocket = INVALID_SOCKET;
4342
#else
4443
#include <pthread.h>
4544
#include <unistd.h>
@@ -52,7 +51,7 @@ constexpr socket_t kInvalidSocket = INVALID_SOCKET;
5251
#include <sys/select.h>
5352

5453
typedef int socket_t;
55-
constexpr socket_t kInvalidSocket = -1;
54+
#define INVALID_SOCKET (-1)
5655
#endif
5756

5857
#include <fstream>
@@ -562,13 +561,13 @@ socket_t create_socket(const char* host, int port, Fn fn, int socket_flags = 0)
562561
auto service = std::to_string(port);
563562

564563
if (getaddrinfo(host, service.c_str(), &hints, &result)) {
565-
return kInvalidSocket;
564+
return INVALID_SOCKET;
566565
}
567566

568567
for (auto rp = result; rp; rp = rp->ai_next) {
569568
// Create a socket
570569
auto sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
571-
if (sock == kInvalidSocket) {
570+
if (sock == INVALID_SOCKET) {
572571
continue;
573572
}
574573

@@ -586,7 +585,7 @@ socket_t create_socket(const char* host, int port, Fn fn, int socket_flags = 0)
586585
}
587586

588587
freeaddrinfo(result);
589-
return kInvalidSocket;
588+
return INVALID_SOCKET;
590589
}
591590

592591
inline void set_nonblocking(socket_t sock, bool nonblocking)
@@ -1417,7 +1416,7 @@ inline std::string SocketStream::get_remote_addr() {
14171416
inline Server::Server(HttpVersion http_version)
14181417
: http_version_(http_version)
14191418
, is_running_(false)
1420-
, svr_sock_(kInvalidSocket)
1419+
, svr_sock_(INVALID_SOCKET)
14211420
, running_threads_(0)
14221421
{
14231422
#ifndef _WIN32
@@ -1502,10 +1501,10 @@ inline bool Server::is_running() const
15021501
inline void Server::stop()
15031502
{
15041503
if (is_running_) {
1505-
assert(svr_sock_ != kInvalidSocket);
1504+
assert(svr_sock_ != INVALID_SOCKET);
15061505
detail::shutdown_socket(svr_sock_);
15071506
detail::close_socket(svr_sock_);
1508-
svr_sock_ = kInvalidSocket;
1507+
svr_sock_ = INVALID_SOCKET;
15091508
}
15101509
}
15111510

@@ -1626,7 +1625,7 @@ inline int Server::bind_internal(const char* host, int port, int socket_flags)
16261625
}
16271626

16281627
svr_sock_ = create_server_socket(host, port, socket_flags);
1629-
if (svr_sock_ == kInvalidSocket) {
1628+
if (svr_sock_ == INVALID_SOCKET) {
16301629
return -1;
16311630
}
16321631

@@ -1652,7 +1651,7 @@ inline bool Server::listen_internal()
16521651
auto val = detail::select_read(svr_sock_, 0, 100000);
16531652

16541653
if (val == 0) { // Timeout
1655-
if (svr_sock_ == kInvalidSocket) {
1654+
if (svr_sock_ == INVALID_SOCKET) {
16561655
// The server socket was closed by 'stop' method.
16571656
break;
16581657
}
@@ -1661,8 +1660,8 @@ inline bool Server::listen_internal()
16611660

16621661
socket_t sock = accept(svr_sock_, NULL, NULL);
16631662

1664-
if (sock == kInvalidSocket) {
1665-
if (svr_sock_ != kInvalidSocket) {
1663+
if (sock == INVALID_SOCKET) {
1664+
if (svr_sock_ != INVALID_SOCKET) {
16661665
detail::close_socket(svr_sock_);
16671666
ret = false;
16681667
} else {
@@ -1896,7 +1895,7 @@ inline bool Client::send(Request& req, Response& res)
18961895
}
18971896

18981897
auto sock = create_client_socket();
1899-
if (sock == kInvalidSocket) {
1898+
if (sock == INVALID_SOCKET) {
19001899
return false;
19011900
}
19021901

0 commit comments

Comments
 (0)