diff options
Diffstat (limited to 'src/server/net.c')
| -rw-r--r-- | src/server/net.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/server/net.c b/src/server/net.c index 41caa96..fcbe9fb 100644 --- a/src/server/net.c +++ b/src/server/net.c @@ -33,6 +33,7 @@ #include <dnbd3/shared/serialize.h> #include <assert.h> +#include <netinet/tcp.h> #ifdef __linux__ #include <sys/sendfile.h> @@ -174,6 +175,21 @@ void* net_handleNewConnection(void *clientPtr) // Await data from client. Since this is a fresh connection, we expect data right away sock_setTimeout( client->sock, _clientTimeout ); + // NODELAY makes sense since we're sending a lot of data + int e2 = 1; + socklen_t optlen = sizeof(e2); + setsockopt( client->sock, IPPROTO_TCP, TCP_NODELAY, (void *)&e2, optlen ); + // Also increase send buffer + if ( getsockopt( client->sock, SOL_SOCKET, SO_SNDBUF, (void *)&e2, &optlen ) == 0 ) { +#ifdef __linux__ + // Linux doubles the value to account for overhead, get "real" value + e2 /= 2; +#endif + if ( e2 < SERVER_TCP_BUFFER_MIN_SIZE_PAYLOAD ) { + e2 = SERVER_TCP_BUFFER_MIN_SIZE_PAYLOAD; + setsockopt( client->sock, SOL_SOCKET, SO_SNDBUF, &e2, sizeof(e2) ); + } + } do { #ifdef DNBD3_SERVER_AFL const int ret = (int)recv( 0, &request, sizeof(request), MSG_WAITALL ); |
