Set TCP_NODELAY on P2P sockets.
Nagle appears to be a significant contributor to latency now that the static sleeps are gone. Most of our messages are relatively large compared to IP + TCP so I do not expect this to create enormous overhead. This may also reduce traffic burstyness somewhat. Conflicts: src/net.cpp Rebased-From: a4e28b3d1e5c95eb0c87f144851cd65048c3e0bc Github-Pull: #6867
This commit is contained in:
committed by
Wladimir J. van der Laan
parent
072032448b
commit
95a50390e1
@@ -38,6 +38,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|||||||
12
src/net.cpp
12
src/net.cpp
@@ -869,6 +869,15 @@ void ThreadSocketHandler()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// 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
|
||||||
|
|
||||||
CNode* pnode = new CNode(hSocket, addr, "", true);
|
CNode* pnode = new CNode(hSocket, addr, "", true);
|
||||||
pnode->AddRef();
|
pnode->AddRef();
|
||||||
pnode->fWhitelisted = whitelisted;
|
pnode->fWhitelisted = whitelisted;
|
||||||
@@ -1508,8 +1517,11 @@ bool BindListenPort(const CService &addrBind, string& strError, bool fWhiteliste
|
|||||||
// Allow binding if the port is still in TIME_WAIT state after
|
// Allow binding if the port is still in TIME_WAIT state after
|
||||||
// the program was closed and restarted.
|
// the program was closed and restarted.
|
||||||
setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int));
|
setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int));
|
||||||
|
// Disable Nagle's algorithm
|
||||||
|
setsockopt(hListenSocket, IPPROTO_TCP, TCP_NODELAY, (void*)&nOne, sizeof(int));
|
||||||
#else
|
#else
|
||||||
setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&nOne, sizeof(int));
|
setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&nOne, sizeof(int));
|
||||||
|
setsockopt(hListenSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&nOne, sizeof(int));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set to non-blocking, incoming connections will also inherit this
|
// Set to non-blocking, incoming connections will also inherit this
|
||||||
|
|||||||
@@ -444,12 +444,19 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
|
|||||||
if (hSocket == INVALID_SOCKET)
|
if (hSocket == INVALID_SOCKET)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#ifdef SO_NOSIGPIPE
|
|
||||||
int set = 1;
|
int set = 1;
|
||||||
|
#ifdef SO_NOSIGPIPE
|
||||||
// Different way of disabling SIGPIPE on BSD
|
// Different way of disabling SIGPIPE on BSD
|
||||||
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
|
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
|
||||||
#endif
|
#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
|
||||||
|
|
||||||
// Set to non-blocking
|
// Set to non-blocking
|
||||||
if (!SetSocketNonBlocking(hSocket, true))
|
if (!SetSocketNonBlocking(hSocket, true))
|
||||||
return error("ConnectSocketDirectly: Setting socket to non-blocking failed, error %s\n", NetworkErrorString(WSAGetLastError()));
|
return error("ConnectSocketDirectly: Setting socket to non-blocking failed, error %s\n", NetworkErrorString(WSAGetLastError()));
|
||||||
|
|||||||
Reference in New Issue
Block a user