From 33497bd260d242c32fdebe06a20803b2c6a68338 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 13 Apr 2021 18:00:08 +0200 Subject: [SERVER] Set TCP_NODELAY on outgoing connections This will send all (block) requests immediately at sometimes more overhead, but slighly less delays. Since the outgoing connection on a client is only used very lightly, this tradeoff should always make sense. --- src/shared/sockhelper.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shared/sockhelper.c b/src/shared/sockhelper.c index 585afe7..1970447 100644 --- a/src/shared/sockhelper.c +++ b/src/shared/sockhelper.c @@ -2,6 +2,7 @@ #include #include #include // inet_ntop +#include #include #include #include @@ -53,7 +54,9 @@ int sock_connect(const dnbd3_host_t * const addr, const int connect_ms, const in } else { sock_setTimeout( client_sock, connect_ms ); } - int e2; + // NODELAY makes sense for the client side, which should be all users in this code base + int e2 = 1; + setsockopt( client_sock, IPPROTO_TCP, TCP_NODELAY, (void *)&e2, sizeof(e2) ); for ( int i = 0; i < 5; ++i ) { int ret = connect( client_sock, (struct sockaddr *)&ss, addrlen ); e2 = errno; -- cgit v1.2.3-55-g7522