[gnome-bluetooth/gnome-3-10] wizard: Don't try to connect in a busy loop



commit 13fc196033def4976d0cd99a9dc1b9a6733d65df
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Nov 13 16:59:01 2013 +0100

    wizard: Don't try to connect in a busy loop
    
    If the device wasn't quite ready, we would try to connect to it
    in a busy loop (as an error was returned immediately when trying to
    connect). Now we wait 500 msecs between connection.

 wizard/main.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/wizard/main.c b/wizard/main.c
index 749cb0e..2c8f30a 100644
--- a/wizard/main.c
+++ b/wizard/main.c
@@ -429,8 +429,24 @@ cancel_callback (GDBusMethodInvocation *invocation,
 typedef struct {
        const char *device;
        GTimer *timer;
+       guint timeout_id;
 } ConnectData;
 
+static void connect_callback (GObject      *source_object,
+                             GAsyncResult *res,
+                             gpointer      user_data);
+
+static gboolean
+connect_timeout_cb (gpointer user_data)
+{
+       ConnectData *data = (ConnectData *) user_data;
+
+       bluetooth_client_connect_service (client, data->device, TRUE, NULL, connect_callback, data);
+       data->timeout_id = 0;
+
+       return G_SOURCE_REMOVE;
+}
+
 static void
 connect_callback (GObject      *source_object,
                  GAsyncResult *res,
@@ -442,9 +458,12 @@ connect_callback (GObject      *source_object,
        success = bluetooth_client_connect_service_finish (client, res, NULL);
 
        if (success == FALSE && g_timer_elapsed (data->timer, NULL) < CONNECT_TIMEOUT) {
-               bluetooth_client_connect_service (client, data->device, TRUE, NULL, connect_callback, data);
+               g_assert (data->timeout_id == 0);
+               data->timeout_id = g_timeout_add (500, connect_timeout_cb, data);
                return;
        }
+       if (data->timeout_id > 0)
+               g_source_remove (data->timeout_id);
 
        if (success == FALSE)
                g_debug ("Failed to connect to device %s", data->device);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]