From 1bd4ecc1256f38d7ab0da736434d46762507348b Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 8 Jun 2007 20:43:35 +0000 Subject: 2007-06-08 Havoc Pennington * backport fix to allow a server to use port=0 or omit port so the port can be auto-selected by the OS --- dbus/dbus-server-socket.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'dbus/dbus-server-socket.c') diff --git a/dbus/dbus-server-socket.c b/dbus/dbus-server-socket.c index 5c11e145..3a0da35f 100644 --- a/dbus/dbus-server-socket.c +++ b/dbus/dbus-server-socket.c @@ -323,6 +323,9 @@ _dbus_server_new_for_tcp_socket (const char *host, if (host == NULL) host = "localhost"; + + listen_fd = _dbus_listen_tcp_socket (host, &port, error); + _dbus_fd_set_close_on_exec (listen_fd); _dbus_string_init_const (&host_str, host); if (!_dbus_string_append (&address, "tcp:host=") || @@ -334,9 +337,7 @@ _dbus_server_new_for_tcp_socket (const char *host, dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return NULL; } - - listen_fd = _dbus_listen_tcp_socket (host, port, error); - _dbus_fd_set_close_on_exec (listen_fd); + if (listen_fd < 0) { @@ -401,7 +402,7 @@ _dbus_server_listen_socket (DBusAddressEntry *entry, sresult = _dbus_string_parse_int (&str, 0, &lport, NULL); _dbus_string_free (&str); - if (sresult == FALSE || lport <= 0 || lport > 65535) + if (sresult == FALSE || lport < 0 || lport > 65535) { _dbus_set_bad_address(error, NULL, NULL, "Port is not an integer between 0 and 65535"); -- cgit