From: Matt Hoosier Date: Wed, 26 Feb 2014 14:29:09 +0000 (-0600) Subject: Disable slow-start on TCP sockets X-Git-Tag: dbus-1.9.0~57 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dd4e09339f048849156174d7c8dff3a667f9a199;p=thirdparty%2Fdbus.git Disable slow-start on TCP sockets 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 --- diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 51f40e184..fcf5df605 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -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;