diff options
author | Ralf Habacker <ralf.habacker@freenet.de> | 2015-01-30 20:19:01 +0100 |
---|---|---|
committer | Ralf Habacker <ralf.habacker@freenet.de> | 2015-01-30 22:07:10 +0100 |
commit | 795ea3007ed211e50249e2f886023a8701dd76a9 (patch) | |
tree | 2c1f48303b0bc30e7f222d8ba2ba03a8cb802a81 | |
parent | 91dbd2eff5106f67db19aea0614772f5b61e4b70 (diff) | |
download | dbus-795ea3007ed211e50249e2f886023a8701dd76a9.tar.gz |
Fix 'dbus-daemon on Windows: Failed to bind socket "localhost:xxxx": Address already in use'.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=87999
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r-- | dbus/dbus-sysdeps-win.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 26cab697..68fa72b0 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -1715,10 +1715,19 @@ _dbus_listen_tcp_socket (const char *host, if (bind (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR) { DBUS_SOCKET_SET_ERRNO (); + closesocket (fd); + if (errno == WSAEADDRINUSE) + { + /* Calling this function with port=0 tries to + * bind the same port twice, so we should + * ignore the second bind. + */ + tmp = tmp->ai_next; + continue; + } dbus_set_error (error, _dbus_error_from_errno (errno), "Failed to bind socket \"%s:%s\": %s", host ? host : "*", port, _dbus_strerror_from_errno ()); - closesocket (fd); goto failed; } @@ -1764,7 +1773,10 @@ _dbus_listen_tcp_socket (const char *host, host ? host : "*", port, _dbus_strerror_from_errno()); goto failed; } - snprintf( portbuf, sizeof( portbuf ) - 1, "%d", addr.AddressIn.sin_port ); + if (addr.AddressIn.sin_family = AF_INET) + snprintf( portbuf, sizeof( portbuf ) - 1, "%d", ntohs(addr.AddressIn.sin_port) ); + else + snprintf( portbuf, sizeof( portbuf ) - 1, "%d", ntohs(addr.AddressIn6.sin6_port) ); if (!_dbus_string_append(retport, portbuf)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); |