<listen> element of the configuration file

Ralf Habacker ralf.habacker at freenet.de
Tue Mar 6 10:11:20 PST 2007


Havoc Pennington schrieb:
> Luigi Paioro wrote:
>> Which means that I can run only one "TCP session". I can guess the
>> reason: the port to use.
>>
>> Well, this is only a curiosity... have you ever thought to implement
>> a port increment system? I mean: while port N is occupied then try
>> N+1 for maximum K times...
>>
>> There are other troubles or implications I don't see?
>>
>
> It just hasn't been done afaik. I think last time it came up someone
> posted the normal way to ask the OS to assign a port, we just have to
> call bind properly or something. Patches welcome ;-)
On windows the autoport selecting behavior is implemented by using
port=0  in the listen statement

    <listen>tcp:host=localhost,port=0</listen>

using the following patch.


Index: dbus/dbus-server-socket.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server-socket.c,v
retrieving revision 1.3
diff -u -b -B -r1.3 dbus-server-socket.c
--- dbus/dbus-server-socket.c    1 Oct 2006 15:36:18 -0000    1.3
+++ dbus/dbus-server-socket.c    4 Mar 2007 22:11:28 -0000
@@ -393,15 +393,19 @@
          
       if (port == NULL)
         {
+#if defined(DBUS_WIN) || defined(DBUS_WINCE)
+          port = "0";
+#else
           _dbus_set_bad_address(error, "tcp", "port", NULL);
           return DBUS_SERVER_LISTEN_BAD_ADDRESS;
+#endif
         }
 
       _dbus_string_init_const (&str, port);
       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");

Index: dbus/dbus-transport-socket.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport-socket.c,v
retrieving revision 1.4
diff -u -b -B -r1.4 dbus-transport-socket.c
--- dbus/dbus-transport-socket.c    20 Oct 2006 03:05:00 -0000    1.4
+++ dbus/dbus-transport-socket.c    4 Mar 2007 22:11:29 -0000
@@ -1286,15 +1286,19 @@
          
       if (port == NULL)
         {
+#if defined(DBUS_WIN) || defined(DBUS_WINCE)
+          port = "0";
+#else
           _dbus_set_bad_address (error, "tcp", "port", NULL);
           return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+#endif
         }
 
       _dbus_string_init_const (&str, port);
       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");

Ralf



More information about the dbus mailing list