From 298b1717aa34928cec25156146d6f4bc612e1d78 Mon Sep 17 00:00:00 2001
From: Recolic K <bensl@microsoft.com>
Date: Wed, 15 Jun 2022 12:18:04 +0800
Subject: [PATCH] Fix win build bug

---
 sys/sio.hpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/sys/sio.hpp b/sys/sio.hpp
index ff06807..9b98c56 100644
--- a/sys/sio.hpp
+++ b/sys/sio.hpp
@@ -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 */
-- 
GitLab