@@ -187,6 +187,7 @@ using ssize_t = long;
187
187
#include < io.h>
188
188
#include < winsock2.h>
189
189
#include < ws2tcpip.h>
190
+ #include < afunix.h>
190
191
191
192
#ifndef WSA_FLAG_NO_HANDLE_INHERIT
192
193
#define WSA_FLAG_NO_HANDLE_INHERIT 0x80
@@ -3538,7 +3539,6 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
3538
3539
hints.ai_flags = socket_flags;
3539
3540
}
3540
3541
3541
- #ifndef _WIN32
3542
3542
if (hints.ai_family == AF_UNIX) {
3543
3543
const auto addrlen = host.length ();
3544
3544
if (addrlen > sizeof (sockaddr_un::sun_path)) { return INVALID_SOCKET; }
@@ -3562,11 +3562,19 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
3562
3562
sizeof (addr) - sizeof (addr.sun_path ) + addrlen);
3563
3563
3564
3564
#ifndef SOCK_CLOEXEC
3565
+ #ifndef _WIN32
3565
3566
fcntl (sock, F_SETFD, FD_CLOEXEC);
3567
+ #endif
3566
3568
#endif
3567
3569
3568
3570
if (socket_options) { socket_options (sock); }
3569
3571
3572
+ #ifdef _WIN32
3573
+ // Setting SO_REUSEADDR seems not to work well with AF_UNIX on windows, so avoid
3574
+ // setting default_socket_options.
3575
+ detail::set_socket_opt (sock, SOL_SOCKET, SO_REUSEADDR, 0 );
3576
+ #endif
3577
+
3570
3578
bool dummy;
3571
3579
if (!bind_or_connect (sock, hints, dummy)) {
3572
3580
close_socket (sock);
@@ -3575,7 +3583,6 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
3575
3583
}
3576
3584
return sock;
3577
3585
}
3578
- #endif
3579
3586
3580
3587
auto service = std::to_string (port);
3581
3588
0 commit comments