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:
parent
a236d704a3
commit
aeacdfc631
@ -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;
|
||||||
|
@ -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.
|
||||||
*
|
*
|
||||||
|
@ -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));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user