summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMadCamel <madcamel@gmail.com>2013-04-07 17:07:03 -0400
committerBen Longbons <b.r.longbons@gmail.com>2013-04-13 21:55:21 -0700
commit6b83d27d53e24bfe7c37e9f7578cfec9540aae1f (patch)
tree204ef700e6380a587b77b6e673fdbc13fd0653d8
parent655730e5a02a053a83fdecb053034c91377f51f7 (diff)
downloadtmwa-6b83d27d53e24bfe7c37e9f7578cfec9540aae1f.tar.gz
tmwa-6b83d27d53e24bfe7c37e9f7578cfec9540aae1f.tar.bz2
tmwa-6b83d27d53e24bfe7c37e9f7578cfec9540aae1f.tar.xz
tmwa-6b83d27d53e24bfe7c37e9f7578cfec9540aae1f.zip
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.
-rw-r--r--src/common/socket.cpp13
1 files 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);