From: Steinar H. Gunderson Date: Sat, 7 Apr 2018 00:58:10 +0000 (+0200) Subject: When doing persistent connections, explicitly flush the socket so that we do not... X-Git-Tag: 1.4.0~23 X-Git-Url: https://git.sesse.net/?p=cubemap;a=commitdiff_plain;h=014604812e65d325316778ac98ac7c422226fce8 When doing persistent connections, explicitly flush the socket so that we do not get 200 ms extra delay for the last bytes due to TCP_CORK. --- diff --git a/server.cpp b/server.cpp index e9bc654..a7f579c 100644 --- a/server.cpp +++ b/server.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -1247,6 +1248,14 @@ bool Server::more_requests(Client *client) // Log to access_log. access_log->write(client->get_stats()); + // Flush pending data; does not cancel out TCP_CORK (since that still takes priority), + // but does a one-off flush. + int one = 1; + if (setsockopt(client->sock, SOL_TCP, TCP_NODELAY, &one, sizeof(one)) == -1) { + log_perror("setsockopt(TCP_NODELAY)"); + // Can still continue. + } + // Switch states and reset the parsers. We don't reset statistics. client->state = Client::READING_REQUEST; client->url.clear();