From 27d1fdcb79811dc0fad3f2ebcbac51ff1ca01d75 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sat, 10 Mar 2018 13:24:26 +0100 Subject: [PATCH] Windows _dbus_listen_tcp_socket: Set socket options SO_REUSEADDR and TCP_NODELAY Bug: https://bugs.freedesktop.org/show_bug.cgi?id=61922 --- dbus/dbus-sysdeps-win.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 362922a9..dede8e29 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -1730,7 +1730,9 @@ _dbus_listen_tcp_socket (const char *host, tmp = ai; while (tmp) { + const int reuseaddr = 1, tcp_nodelay_on = 1; DBusSocket fd = DBUS_SOCKET_INIT, *newlisten_fd; + if ((fd.sock = socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) { saved_errno = _dbus_get_low_level_socket_errno (); @@ -1742,6 +1744,22 @@ _dbus_listen_tcp_socket (const char *host, } _DBUS_ASSERT_ERROR_IS_CLEAR(error); + if (setsockopt (fd.sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&reuseaddr, sizeof(reuseaddr)) == SOCKET_ERROR) + { + saved_errno = _dbus_get_low_level_socket_errno (); + _dbus_warn ("Failed to set socket option \"%s:%s\": %s", + host ? host : "*", port, _dbus_strerror (saved_errno)); + } + + /* Nagle's algorithm imposes a huge delay on the initial messages + going over TCP. */ + if (setsockopt (fd.sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&tcp_nodelay_on, sizeof (tcp_nodelay_on)) == SOCKET_ERROR) + { + saved_errno = _dbus_get_low_level_socket_errno (); + _dbus_warn ("Failed to set TCP_NODELAY socket option \"%s:%s\": %s", + host ? host : "*", port, _dbus_strerror (saved_errno)); + } + if (bind (fd.sock, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR) { saved_errno = _dbus_get_low_level_socket_errno (); -- 2.12.3