]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Make test VNC and XDMCP client more robust
authorRobert Ancell <robert.ancell@canonical.com>
Sun, 16 Jun 2013 22:38:53 +0000 (10:38 +1200)
committerRobert Ancell <robert.ancell@canonical.com>
Sun, 16 Jun 2013 22:38:53 +0000 (10:38 +1200)
tests/src/vnc-client.c
tests/src/xdmcp-client.c

index 9d033ce1479827e5a644ee810751ba3d7d13f904..fedd2b5fbe354b907f0cfe4e69fd8e0d3c34b736 100644 (file)
@@ -18,7 +18,6 @@ main (int argc, char **argv)
     GError *error = NULL;
     GSocket *socket;
     GSocketConnectable *address;
-    GSocketAddress *socket_address;
     gboolean result;
     gchar buffer[1024];
     gssize n_read, n_sent;
@@ -68,9 +67,27 @@ main (int argc, char **argv)
     }
   
     address = g_network_address_new (hostname, port);
-    socket_address = g_socket_address_enumerator_next (g_socket_connectable_enumerate (address), NULL, NULL);
+    result = FALSE;
+    while (TRUE) 
+    {
+        GSocketAddress *socket_address;
+        GError *e = NULL;
+
+        socket_address = g_socket_address_enumerator_next (g_socket_connectable_enumerate (address), NULL, &e);
+        if (e)
+            g_warning ("Failed to get socket address: %s", e->message);
+        g_clear_error (&e);
+        if (!socket_address)
+            break;
 
-    result = g_socket_connect (socket, socket_address, NULL, &error);
+        result = g_socket_connect (socket, socket_address, NULL, error ? NULL : &error);
+        g_object_unref (socket_address);
+        if (result)
+        {
+            g_clear_error (&error);
+            break;
+        }
+    }
     if (error)
         g_warning ("Unable to connect VNC socket: %s", error->message);
     g_clear_error (&error);
index dd352c8bac74e6ef923ccfc6975a36770429423b..aa15d349015f20ffc9af2c38f5973ae17d9a5f8a 100644 (file)
@@ -262,21 +262,43 @@ gboolean
 xdmcp_client_start (XDMCPClient *client)
 {
     GSocketConnectable *address;
-    GSocketAddress *socket_address;
+    gboolean result;
     GError *error = NULL;
 
     client->priv->socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, &error);
+    if (error)
+        g_warning ("Error creating XDMCP socket: %s", error->message);
+    if (!client->priv->socket)
+        return FALSE;
 
     address = g_network_address_new (client->priv->host, client->priv->port);
-    socket_address = g_socket_address_enumerator_next (g_socket_connectable_enumerate (address), NULL, NULL);
-  
-    if (!client->priv->socket ||
-        !g_socket_connect (client->priv->socket, socket_address, NULL, &error) ||
-        !g_io_add_watch (g_io_channel_unix_new (g_socket_get_fd (client->priv->socket)), G_IO_IN, xdmcp_data_cb, client))
+    result = FALSE;
+    while (TRUE) 
     {
-        g_warning ("Error creating XDMCP socket: %s", error->message);
-        return FALSE;
+        GSocketAddress *socket_address;
+        GError *e = NULL;
+
+        socket_address = g_socket_address_enumerator_next (g_socket_connectable_enumerate (address), NULL, &e);
+        if (e)
+            g_warning ("Failed to get socket address: %s", e->message);
+        g_clear_error (&e);
+        if (!socket_address)
+            break;
+
+        result = g_socket_connect (client->priv->socket, socket_address, NULL, error ? NULL : &error);
+        g_object_unref (socket_address);
+        if (result)
+        {
+            g_clear_error (&error);
+            break;
+        }
     }
+    if (error)
+        g_warning ("Unable to connect XDMCP socket: %s", error->message);
+    if (!result)
+        return FALSE;
+  
+    g_io_add_watch (g_io_channel_unix_new (g_socket_get_fd (client->priv->socket)), G_IO_IN, xdmcp_data_cb, client);
 
     client->priv->query_timer = g_timeout_add (2000, xdmcp_query_cb, client);
     xdmcp_query_cb (client);