diff options
| author | Pieter Wuille <[email protected]> | 2017-05-17 17:26:54 -0700 |
|---|---|---|
| committer | Pieter Wuille <[email protected]> | 2017-05-17 17:36:27 -0700 |
| commit | ae786098bc58b1ca92f596a698b23aeade9cd2cd (patch) | |
| tree | e01c0f83a3c4be084fc6d3775461775b188b914d | |
| parent | Merge #10395: Replace boost::function with std::function (C++11) (diff) | |
| parent | [net] Added SetSocketNoDelay() utility function (diff) | |
| download | discoin-ae786098bc58b1ca92f596a698b23aeade9cd2cd.tar.xz discoin-ae786098bc58b1ca92f596a698b23aeade9cd2cd.zip | |
Merge #10061: [net] Added SetSocketNoDelay() utility function
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)
Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
| -rw-r--r-- | src/net.cpp | 7 | ||||
| -rw-r--r-- | src/netbase.cpp | 15 | ||||
| -rw-r--r-- | src/netbase.h | 2 |
3 files changed, 12 insertions, 12 deletions
diff --git a/src/net.cpp b/src/net.cpp index dd375e580..ded6f1099 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1071,12 +1071,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { // According to the internet TCP_NODELAY is not carried into accepted sockets // on all platforms. Set it again here just to be sure. - int set = 1; -#ifdef WIN32 - setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int)); -#else - setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (void*)&set, sizeof(int)); -#endif + SetSocketNoDelay(hSocket); if (IsBanned(addr) && !whitelisted) { diff --git a/src/netbase.cpp b/src/netbase.cpp index bdc725359..2584f571e 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -428,18 +428,14 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe if (hSocket == INVALID_SOCKET) return false; - int set = 1; #ifdef SO_NOSIGPIPE + int set = 1; // Different way of disabling SIGPIPE on BSD setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int)); #endif //Disable Nagle's algorithm -#ifdef WIN32 - setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int)); -#else - setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (void*)&set, sizeof(int)); -#endif + SetSocketNoDelay(hSocket); // Set to non-blocking if (!SetSocketNonBlocking(hSocket, true)) @@ -728,6 +724,13 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking) return true; } +bool SetSocketNoDelay(SOCKET& hSocket) +{ + int set = 1; + int rc = setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int)); + return rc == 0; +} + void InterruptSocks5(bool interrupt) { interruptSocks5Recv = interrupt; diff --git a/src/netbase.h b/src/netbase.h index dd33b6e47..c9d108aad 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -59,6 +59,8 @@ std::string NetworkErrorString(int err); bool CloseSocket(SOCKET& hSocket); /** Disable or enable blocking-mode for a socket */ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking); +/** Set the TCP_NODELAY flag on a socket */ +bool SetSocketNoDelay(SOCKET& hSocket); /** * Convert milliseconds to a struct timeval for e.g. select. */ |