Check setsockopt for error
authorsvost <ya.nowa@yandex.ru>
Tue, 3 May 2016 16:33:33 +0000 (19:33 +0300)
committersvost <ya.nowa@yandex.ru>
Tue, 3 May 2016 16:33:33 +0000 (19:33 +0300)
src/net.cpp

index c235fd2..a1d9e33 100644 (file)
@@ -1767,11 +1767,19 @@ bool BindListenPort(const CService &addrBind, string& strError)
 #ifndef WIN32
 #ifdef SO_NOSIGPIPE
     // Different way of disabling SIGPIPE on BSD
-    setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int));
+    if (setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int)) == SOCKET_ERROR)
+    {
+        printf("WARNING: setsockopt failed\n");
+        //TODO: work around problem - may be add CloseSocket and return false?
+    }
 #endif
     // Allow binding if the port is still in TIME_WAIT state after
     // the program was closed and restarted. Not an issue on windows!
-    setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int));
+    if (setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int)) == SOCKET_ERROR)
+    {
+        printf("WARNING: setsockopt failed\n");
+        //TODO: work around problem - may be add CloseSocket and return false?
+    }
 #endif
 
 #ifdef WIN32
@@ -1792,14 +1800,26 @@ bool BindListenPort(const CService &addrBind, string& strError)
     if (addrBind.IsIPv6()) {
 #ifdef IPV6_V6ONLY
 #ifdef WIN32
-        setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&nOne, sizeof(int));
+    if (setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&nOne, sizeof(int)) == SOCKET_ERROR)
+    {
+        printf("WARNING: setsockopt failed\n");
+        //TODO: work around problem - may be add CloseSocket and return false?
+    }
 #else
-        setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&nOne, sizeof(int));
+    if (setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&nOne, sizeof(int)) == SOCKET_ERROR)
+    {
+        printf("WARNING: setsockopt failed\n");
+        //TODO: work around problem - may be add CloseSocket and return false?
+    }
 #endif
 #endif
 #ifdef WIN32
-        int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED;
-        setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (const char*)&nProtLevel, sizeof(int));
+    int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED;
+    if (setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (const char*)&nProtLevel, sizeof(int)) == SOCKET_ERROR)
+    {
+        printf("WARNING: setsockopt failed\n");
+        //TODO: work around problem - may be add CloseSocket and return false?
+    }
 #endif
     }
 #endif