From 6b83d27d53e24bfe7c37e9f7578cfec9540aae1f Mon Sep 17 00:00:00 2001 From: MadCamel Date: Sun, 7 Apr 2013 17:07:03 -0400 Subject: Enable tcp_thin socket optimizations on Linux See kernel/Documentation/networking/tcp-thin.txt These TCP optimizations were designed for the specific purpose of low latency TCP gameservers and can help reduce latency in adverse network conditions. --- src/common/socket.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/common/socket.cpp b/src/common/socket.cpp index cc6e4b3..e79f27a 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -117,10 +117,19 @@ static void connect_client (int listen_fd) setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes); /// Send packets as soon as possible /// even if the kernel thinks there is too little for it to be worth it! - // I'm not convinced this is a good idea; although in minimizes the - // latency for an individual write, it increases traffic in general. + /// Testing shows this is indeed a good idea. setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes); + // Linux-ism: Set socket options to optimize for thin streams + // See http://lwn.net/Articles/308919/ and + // Documentation/networking/tcp-thin.txt .. Kernel 3.2+ +#ifdef TCP_THIN_LINEAR_TIMEOUTS + setsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS, &yes, sizeof yes); +#endif +#ifdef TCP_THIN_DUPACK + setsockopt(fd, IPPROTO_TCP, TCP_THIN_DUPACK, &yes, sizeof yes); +#endif + FD_SET (fd, &readfds); fcntl (fd, F_SETFL, O_NONBLOCK); -- cgit v1.2.3-60-g2f50