Skip to content
Snippets Groups Projects
Commit 298b1717 authored by Recolic K's avatar Recolic K
Browse files

Fix win build bug

parent b28d482a
No related branches found
No related tags found
No related merge requests found
Pipeline #900 failed with stage
......@@ -33,7 +33,7 @@ namespace rlib {
namespace rlib {
// Both POSIX and Win32
// Both POSIX and Win32. Note what MinGW32 does not have POSIX support, so network operations will not compile on them.
using rlib::literals::operator "" _format;
static inline sockfd_t quick_accept(sockfd_t sock) {
auto res = accept(sock, NULL, NULL);
......@@ -219,10 +219,14 @@ namespace rlib {
if (listenfd == -1)
continue;
int reuse = 1;
#ifdef SO_REUSEADDR
if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (const char *) &reuse, sizeof(int)) < 0)
throw std::runtime_error("setsockopt(SO_REUSEADDR) failed");
#endif
#ifdef SO_REUSEPORT
if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEPORT, (const char *) &reuse, sizeof(int)) < 0)
throw std::runtime_error("setsockopt(SO_REUSEPORT) failed");
#endif
if (bind(listenfd, rp->ai_addr, rp->ai_addrlen) == 0) {
success = true;
break;
......@@ -267,10 +271,14 @@ namespace rlib {
if (sockfd == -1)
continue;
int reuse = 1;
#ifdef SO_REUSEADDR
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *) &reuse, sizeof(int)) < 0)
throw std::runtime_error("setsockopt(SO_REUSEADDR) failed");
#endif
#ifdef SO_REUSEPORT
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, (const char *) &reuse, sizeof(int)) < 0)
throw std::runtime_error("setsockopt(SO_REUSEPORT) failed");
#endif
if (connect(sockfd, rp->ai_addr, rp->ai_addrlen) == 0) {
success = true;
break; /* Success */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment