From 9ba5f98e902ba70bb4ee4ec5026876d4097250e1 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 A difference to the related unix implementation is that the prototype of setsockopt() on Windows defines socket option value type as 'const char'. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=61922 --- dbus/dbus-sysdeps-win.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 01394f30..46f4322d 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -1733,7 +1733,9 @@ _dbus_listen_tcp_socket (const char *host, tmp = ai; while (tmp) { + const char 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 (); @@ -1745,6 +1747,20 @@ _dbus_listen_tcp_socket (const char *host, } _DBUS_ASSERT_ERROR_IS_CLEAR(error); + if (setsockopt (fd.sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr))==-1) + { + _dbus_warn ("Failed to set socket option \"%s:%s\": %s", + host ? host : "*", port, _dbus_strerror (errno)); + } + + /* Nagle's algorithm imposes a huge delay on the initial messages + going over TCP. */ + if (setsockopt (fd.sock, 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.sock, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR) { saved_errno = _dbus_get_low_level_socket_errno (); -- 2.12.3