Code

main: assign reconnect_source_id when retrying to reconnect
authorMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 21:22:57 +0000 (23:22 +0200)
committerMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 21:22:57 +0000 (23:22 +0200)
Keep track of the current source id, and unregister it on exit.

src/main.c

index 8d9152b27cb8e64e3e90d252bc2465755dbde10d..a8643a393d7c01d3d9c0f9a6b362e30c970bc6a2 100644 (file)
@@ -190,6 +190,8 @@ timer_reconnect(G_GNUC_UNUSED gpointer data)
 
        assert(!mpdclient_is_connected(mpd));
 
+       reconnect_source_id = 0;
+
        screen_status_printf(_("Connecting to %s...  [Press %s to abort]"),
                             options.host, get_key_names(CMD_QUIT,0) );
        doupdate();
@@ -201,7 +203,8 @@ timer_reconnect(G_GNUC_UNUSED gpointer data)
                                    options.password);
        if (!success) {
                /* try again in 5 seconds */
-               g_timeout_add(5000, timer_reconnect, NULL);
+               reconnect_source_id = g_timeout_add(5000,
+                                                   timer_reconnect, NULL);
                return FALSE;
        }
 
@@ -217,7 +220,8 @@ timer_reconnect(G_GNUC_UNUSED gpointer data)
                doupdate();
 
                /* try again after 30 seconds */
-               g_timeout_add(30000, timer_reconnect, NULL);
+               reconnect_source_id = g_timeout_add(30000,
+                                                   timer_reconnect, NULL);
                return FALSE;
        }
 #endif
@@ -230,9 +234,7 @@ timer_reconnect(G_GNUC_UNUSED gpointer data)
        /* update immediately */
        g_timeout_add(1, timer_mpd_update, GINT_TO_POINTER(FALSE));
 
-       reconnect_source_id = 0;
        return FALSE;
-
 }
 
 static gboolean
@@ -490,6 +492,9 @@ main(int argc, const char *argv[])
 
        disable_update_timer();
 
+       if (reconnect_source_id != 0)
+               g_source_remove(reconnect_source_id);
+
 #ifndef NCMPC_MINI
        if (check_key_bindings_source_id != 0)
                g_source_remove(check_key_bindings_source_id);