disable the nagle algorithm to speed up write operations to the tcp connections (and dramatically improving write performance) fixes issue 50

This commit is contained in:
Emiel Bruijntjes 2015-12-07 14:05:49 +01:00
parent 93a0b60b6e
commit e2ce7103aa
2 changed files with 12 additions and 1 deletions

View File

@ -25,6 +25,7 @@
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <netinet/tcp.h>
#include <functional>
// forward declarations

View File

@ -110,7 +110,17 @@ private:
}
// connection succeeded, mark socket as non-blocking
if (_socket >= 0) fcntl(_socket, F_SETFL, O_NONBLOCK);
if (_socket >= 0)
{
// turn socket into a non-blocking socket
fcntl(_socket, F_SETFL, O_NONBLOCK);
// we want to enable "nodelay" on sockets (otherwise all send operations are s-l-o-w
int optval = 1;
// set the option
setsockopt(_socket, IPPROTO_TCP, TCP_NODELAY, &optval, sizeof(int));
}
}
catch (const std::runtime_error &error)
{