diff options
| author | Philip Kaufmann <[email protected]> | 2014-06-24 09:03:18 +0200 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2015-06-27 13:44:15 +0000 |
| commit | a8fe7c245b25ac619a18cfd14d14c42ff3a98f67 (patch) | |
| tree | 1496938e6d5ec7ffb3a367b9b2e7e27fe8bee942 /src | |
| parent | add missing vhListenSocket.clear(); to CNetCleanup() (diff) | |
| download | discoin-a8fe7c245b25ac619a18cfd14d14c42ff3a98f67.tar.xz discoin-a8fe7c245b25ac619a18cfd14d14c42ff3a98f67.zip | |
small cleanup of #ifdefs in BindListenPort()
- SO_NOSIGPIPE isn't available on WIN32 so merge the 2 non-WIN32 blocks
- use predefined names from header for IPV6_PROTECTION_LEVEL and
PROTECTION_LEVEL_UNRESTRICTED
Diffstat (limited to 'src')
| -rw-r--r-- | src/net.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/net.cpp b/src/net.cpp index 76fb5f3e2..df27819b7 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -36,6 +36,17 @@ #define MSG_NOSIGNAL 0 #endif +// Fix for ancient MinGW versions, that don't have defined these in ws2tcpip.h. +// Todo: Can be removed when our pull-tester is upgraded to a modern MinGW version. +#ifdef WIN32 +#ifndef PROTECTION_LEVEL_UNRESTRICTED +#define PROTECTION_LEVEL_UNRESTRICTED 10 +#endif +#ifndef IPV6_PROTECTION_LEVEL +#define IPV6_PROTECTION_LEVEL 23 +#endif +#endif + using namespace std; using namespace boost; @@ -1579,18 +1590,16 @@ bool BindListenPort(const CService &addrBind, string& strError) return false; } +#ifndef WIN32 #ifdef SO_NOSIGPIPE // Different way of disabling SIGPIPE on BSD setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int)); #endif - -#ifndef WIN32 // Allow binding if the port is still in TIME_WAIT state after - // the program was closed and restarted. Not an issue on windows. + // the program was closed and restarted. Not an issue on windows! setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int)); #endif - #ifdef WIN32 // Set to non-blocking, incoming connections will also inherit this if (ioctlsocket(hListenSocket, FIONBIO, (u_long*)&nOne) == SOCKET_ERROR) @@ -1614,10 +1623,8 @@ bool BindListenPort(const CService &addrBind, string& strError) #endif #endif #ifdef WIN32 - int nProtLevel = 10 /* PROTECTION_LEVEL_UNRESTRICTED */; - int nParameterId = 23 /* IPV6_PROTECTION_LEVEl */; - // this call is allowed to fail - setsockopt(hListenSocket, IPPROTO_IPV6, nParameterId, (const char*)&nProtLevel, sizeof(int)); + int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED; + setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (const char*)&nProtLevel, sizeof(int)); #endif } |