diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 51f40e18..fcf5df60 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;