Code

main: reconnect at the end of timer_mpd_update()
authorMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 23:10:23 +0000 (01:10 +0200)
committerMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 23:10:23 +0000 (01:10 +0200)
During timer_mpd_update(), the MPD connection may get lost.  Move that
reconnect test to the end of timer_mpd_update(), so we can catch it as
soon as possible.  There is no advantage in having it at the
beginning.

src/main.c

index f874d6292dd573df994fcaed33485dda20f585b8..d10e42abedc37b73e9df83909171cc9ed13e589b 100644 (file)
@@ -242,9 +242,6 @@ timer_mpd_update(gpointer data)
 {
        if (mpdclient_is_connected(mpd))
                mpdclient_update(mpd);
-       else if (reconnect_source_id == 0)
-               reconnect_source_id = g_timeout_add(1000, timer_reconnect,
-                                                   NULL);
 
 #ifndef NCMPC_MINI
        if (options.enable_xterm_title)
@@ -254,6 +251,11 @@ timer_mpd_update(gpointer data)
        screen_update(mpd);
        mpd->events = 0;
 
+       if (!mpdclient_is_connected(mpd) && reconnect_source_id == 0)
+               /* reconnect when the connection is lost */
+               reconnect_source_id = g_timeout_add(1000, timer_reconnect,
+                                                   NULL);
+
        return GPOINTER_TO_INT(data);
 }