]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Disable slow-start on TCP sockets
authorMatt Hoosier <matt.hoosier@garmin.com>
Wed, 26 Feb 2014 14:29:09 +0000 (08:29 -0600)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 3 Mar 2014 15:36:47 +0000 (15:36 +0000)
Leaving Nagle's algorithm enabled on the TCP transport leads to some
really long latencies (at least, during the first several messages).

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75544
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
dbus/dbus-sysdeps-unix.c

index 51f40e1848fe88a7f67b6a0f8f1f77c176984136..fcf5df605de4f063c52c2b7b6ae836d9a45fd232 100644 (file)
@@ -53,6 +53,7 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <netinet/in.h>
+#include <netinet/tcp.h>
 #include <netdb.h>
 #include <grp.h>
 #include <arpa/inet.h>
@@ -1395,7 +1396,7 @@ _dbus_listen_tcp_socket (const char     *host,
   tmp = ai;
   while (tmp)
     {
-      int fd = -1, *newlisten_fd;
+      int fd = -1, *newlisten_fd, tcp_nodelay_on;
       if (!_dbus_open_socket (&fd, tmp->ai_family, SOCK_STREAM, 0, error))
         {
           _DBUS_ASSERT_ERROR_IS_SET(error);
@@ -1410,6 +1411,15 @@ _dbus_listen_tcp_socket (const char     *host,
                       host ? host : "*", port, _dbus_strerror (errno));
         }
 
+      /* Nagle's algorithm imposes a huge delay on the initial messages
+         going over TCP. */
+      tcp_nodelay_on = 1;
+      if (setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &tcp_nodelay_on, sizeof (tcp_nodelay_on)) == -1)
+        {
+          _dbus_warn ("Failed to set TCP_NODELAY socket option \"%s:%s\": %s",
+                      host ? host : "*", port, _dbus_strerror (errno));
+        }
+
       if (bind (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) < 0)
         {
           saved_errno = errno;