[Telepathy-commits] [telepathy-salut/master] XmppConnectionListener: let the GibberListener choose the port

Alban Crequy alban.crequy at collabora.co.uk
Thu Nov 6 11:09:05 PST 2008


---
 lib/gibber/gibber-xmpp-connection-listener.c  |   10 +++++++---
 lib/gibber/gibber-xmpp-connection-listener.h  |    4 ++--
 src/salut-xmpp-connection-manager.c           |   24 +-----------------------
 tests/check-gibber-xmpp-connection-listener.c |   15 +++------------
 4 files changed, 13 insertions(+), 40 deletions(-)

diff --git a/lib/gibber/gibber-xmpp-connection-listener.c b/lib/gibber/gibber-xmpp-connection-listener.c
index db0ae22..e3ff9fb 100644
--- a/lib/gibber/gibber-xmpp-connection-listener.c
+++ b/lib/gibber/gibber-xmpp-connection-listener.c
@@ -158,13 +158,13 @@ new_connection_cb (GibberListener *listener,
   return TRUE;
 }
 
-gboolean
+int
 gibber_xmpp_connection_listener_listen (GibberXmppConnectionListener *self,
-                                        int port,
                                         GError **error)
 {
   GibberXmppConnectionListenerPrivate *priv =
     GIBBER_XMPP_CONNECTION_LISTENER_GET_PRIVATE (self);
+  int ret;
 
   if (priv->listener == NULL)
     {
@@ -173,5 +173,9 @@ gibber_xmpp_connection_listener_listen (GibberXmppConnectionListener *self,
         G_CALLBACK (new_connection_cb), self);
     }
 
-  return gibber_listener_listen_tcp (priv->listener, port, error);
+  ret = gibber_listener_listen_tcp (priv->listener, 0, error);
+  if (ret != TRUE)
+    return -1;
+
+  return gibber_listener_get_port (priv->listener);
 }
diff --git a/lib/gibber/gibber-xmpp-connection-listener.h b/lib/gibber/gibber-xmpp-connection-listener.h
index 077f8e5..a15b77e 100644
--- a/lib/gibber/gibber-xmpp-connection-listener.h
+++ b/lib/gibber/gibber-xmpp-connection-listener.h
@@ -60,9 +60,9 @@ GType gibber_xmpp_connection_listener_get_type (void);
 GibberXmppConnectionListener *
 gibber_xmpp_connection_listener_new (void);
 
-gboolean
+int
 gibber_xmpp_connection_listener_listen (
-    GibberXmppConnectionListener *listener, int port, GError **error);
+    GibberXmppConnectionListener *listener, GError **error);
 
 G_END_DECLS
 
diff --git a/src/salut-xmpp-connection-manager.c b/src/salut-xmpp-connection-manager.c
index 406c847..cc9d6a8 100644
--- a/src/salut-xmpp-connection-manager.c
+++ b/src/salut-xmpp-connection-manager.c
@@ -1133,30 +1133,8 @@ salut_xmpp_connection_manager_listen (SalutXmppConnectionManager *self,
 {
   SalutXmppConnectionManagerPrivate *priv =
     SALUT_XMPP_CONNECTION_MANAGER_GET_PRIVATE (self);
-  int port;
 
-  for (port = 5298; port < 5400; port++)
-    {
-      GError *e = NULL;
-      if (gibber_xmpp_connection_listener_listen (priv->listener, port,
-            &e))
-        break;
-
-      if (!g_error_matches (e, GIBBER_LISTENER_ERROR,
-            GIBBER_LISTENER_ERROR_ADDRESS_IN_USE))
-        {
-          g_propagate_error (error, e);
-          return -1;
-        }
-
-      g_error_free (e);
-      e = NULL;
-    }
-
-  if (port >= 5400)
-    return -1;
-
-  return port;
+  return gibber_xmpp_connection_listener_listen (priv->listener, error);
 }
 
 struct find_connection_for_contact_data
diff --git a/tests/check-gibber-xmpp-connection-listener.c b/tests/check-gibber-xmpp-connection-listener.c
index c3df499..214db00 100644
--- a/tests/check-gibber-xmpp-connection-listener.c
+++ b/tests/check-gibber-xmpp-connection-listener.c
@@ -73,6 +73,7 @@ START_TEST (test_listen)
   GibberXmppConnectionListener *listener;
   int port;
   gboolean result;
+  GError *error = NULL;
 
   got_connection = FALSE;
 
@@ -82,18 +83,8 @@ START_TEST (test_listen)
   g_signal_connect (listener, "new-connection", G_CALLBACK (new_connection_cb),
       NULL);
 
-  for (port = 5298; port < 5400; port++)
-    {
-      GError *error = NULL;
-      if (gibber_xmpp_connection_listener_listen (listener, port, &error))
-        break;
-
-      fail_if (!g_error_matches (error, GIBBER_LISTENER_ERROR,
-          GIBBER_LISTENER_ERROR_ADDRESS_IN_USE));
-      g_error_free (error);
-      error = NULL;
-    }
-  fail_if (port >= 5400);
+  port = gibber_xmpp_connection_listener_listen (listener, &error);
+  fail_if (port <= 0);
 
   result = connect_to_port (port);
   fail_if (result == FALSE);
-- 
1.5.6.5




More information about the Telepathy-commits mailing list