Skip to content

Commit ae63b89

Browse files
committed
Use SOCK_CLOEXEC instead of __linux__
1 parent ff038f9 commit ae63b89

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

httplib.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -3252,7 +3252,8 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
32523252
if (addrlen > sizeof(sockaddr_un::sun_path)) { return INVALID_SOCKET; }
32533253

32543254
#ifdef SOCK_CLOEXEC
3255-
auto sock = socket(hints.ai_family, hints.ai_socktype | SOCK_CLOEXEC, hints.ai_protocol);
3255+
auto sock = socket(hints.ai_family, hints.ai_socktype | SOCK_CLOEXEC,
3256+
hints.ai_protocol);
32563257
#else
32573258
auto sock = socket(hints.ai_family, hints.ai_socktype, hints.ai_protocol);
32583259
#endif
@@ -3316,7 +3317,8 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
33163317
#else
33173318

33183319
#ifdef SOCK_CLOEXEC
3319-
auto sock = socket(rp->ai_family, rp->ai_socktype | SOCK_CLOEXEC, rp->ai_protocol);
3320+
auto sock =
3321+
socket(rp->ai_family, rp->ai_socktype | SOCK_CLOEXEC, rp->ai_protocol);
33203322
#else
33213323
auto sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
33223324
#endif
@@ -6521,9 +6523,10 @@ inline bool Server::listen_internal() {
65216523
#endif
65226524

65236525
#if defined _WIN32
6524-
// sockets conneced via WASAccept inherit flags NO_HANDLE_INHERIT, OVERLAPPED
6526+
// sockets conneced via WASAccept inherit flags NO_HANDLE_INHERIT,
6527+
// OVERLAPPED
65256528
socket_t sock = WSAAccept(svr_sock_, nullptr, nullptr, nullptr, 0);
6526-
#elif defined __linux__
6529+
#elif defined SOCK_CLOEXEC
65276530
socket_t sock = accept4(svr_sock_, nullptr, nullptr, SOCK_CLOEXEC);
65286531
#else
65296532
socket_t sock = accept(svr_sock_, nullptr, nullptr);
@@ -9343,7 +9346,7 @@ inline Client::Client(const std::string &scheme_host_port,
93439346
cli_ = detail::make_unique<ClientImpl>(scheme_host_port, 80,
93449347
client_cert_path, client_key_path);
93459348
}
9346-
}
9349+
} // namespace detail
93479350

93489351
inline Client::Client(const std::string &host, int port)
93499352
: cli_(detail::make_unique<ClientImpl>(host, port)) {}

0 commit comments

Comments
 (0)