From e2ce7103aa9ff239d0ffcc71b4bd9c33dbf65284 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Mon, 7 Dec 2015 14:05:49 +0100 Subject: [PATCH] disable the nagle algorithm to speed up write operations to the tcp connections (and dramatically improving write performance) fixes issue 50 --- src/includes.h | 1 + src/tcpresolver.h | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/includes.h b/src/includes.h index 005239b..6768f00 100644 --- a/src/includes.h +++ b/src/includes.h @@ -25,6 +25,7 @@ #include #include #include +#include #include // forward declarations diff --git a/src/tcpresolver.h b/src/tcpresolver.h index 19c1938..e16d626 100644 --- a/src/tcpresolver.h +++ b/src/tcpresolver.h @@ -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) {