Added TCP_NODELAY to server sockets.

Reviewers: mislav.bradac

Reviewed By: mislav.bradac

Subscribers: pullbot, buda

Differential Revision: https://phabricator.memgraph.io/D362
This commit is contained in:
Matej Ferencevic 2017-05-10 14:52:51 +02:00
parent a236d704a3
commit aeacdfc631
3 changed files with 22 additions and 0 deletions

View File

@ -137,6 +137,16 @@ bool Socket::SetKeepAlive() {
return true; return true;
} }
bool Socket::SetNoDelay() {
int optval = 1;
socklen_t optlen = sizeof(optval);
if (setsockopt(socket_, SOL_TCP, TCP_NODELAY, (void*)&optval, optlen) < 0)
return false;
return true;
}
bool Socket::SetTimeout(long sec, long usec) { bool Socket::SetTimeout(long sec, long usec) {
struct timeval tv; struct timeval tv;
tv.tv_sec = sec; tv.tv_sec = sec;

View File

@ -97,6 +97,17 @@ class Socket {
*/ */
bool SetKeepAlive(); bool SetKeepAlive();
/**
* Enables TCP no_delay on the socket.
* When enabled, the socket doesn't wait for an ACK of every data packet
* before sending the next packet.
*
* @return enable no_delay success status:
* true if no_delay was successfully enabled on the socket
* false if no_delay was not enabled
*/
bool SetNoDelay();
/** /**
* Sets the socket timeout. * Sets the socket timeout.
* *

View File

@ -30,6 +30,7 @@ class StreamReader : public StreamListener<Derived, Stream> {
s.endpoint().port()); s.endpoint().port());
if (!s.SetKeepAlive()) return false; if (!s.SetKeepAlive()) return false;
if (!s.SetNoDelay()) return false;
auto& stream = this->derived().OnConnect(std::move(s)); auto& stream = this->derived().OnConnect(std::move(s));