mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Fix #164
This commit is contained in:
parent
b5c79bf146
commit
6d74fa86be
1 changed files with 8 additions and 0 deletions
|
@ -639,9 +639,17 @@ socket_t create_socket(const char *host, int port, Fn fn,
|
|||
|
||||
for (auto rp = result; rp; rp = rp->ai_next) {
|
||||
// Create a socket
|
||||
#ifdef _WIN32
|
||||
auto sock = WSASocket(rp->ai_family, rp->ai_socktype, rp->ai_protocol, nullptr, 0, WSA_FLAG_NO_HANDLE_INHERIT);
|
||||
#else
|
||||
auto sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
||||
#endif
|
||||
if (sock == INVALID_SOCKET) { continue; }
|
||||
|
||||
#ifndef _WIN32
|
||||
if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) { continue; }
|
||||
#endif
|
||||
|
||||
// Make 'reuse address' option available
|
||||
int yes = 1;
|
||||
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes));
|
||||
|
|
Loading…
Reference in a new issue