From: Max Kellermann Date: Sat, 3 Oct 2009 23:10:26 +0000 (+0200) Subject: main: check for connection lost in end_input_event() X-Git-Tag: release-0.16~174 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=182bfa40112e8b73ef3b2cf379f3a9e618db214b;p=ncmpc.git main: check for connection lost in end_input_event() Every GLib event callback which may affect the connection should detect a lost connection. --- diff --git a/src/main.c b/src/main.c index d10e42a..726f098 100644 --- a/src/main.c +++ b/src/main.c @@ -237,6 +237,15 @@ timer_reconnect(G_GNUC_UNUSED gpointer data) return FALSE; } +static void +check_reconnect(void) +{ + 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); +} + static gboolean timer_mpd_update(gpointer data) { @@ -251,10 +260,7 @@ 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); + check_reconnect(); return GPOINTER_TO_INT(data); } @@ -267,6 +273,8 @@ void end_input_event(void) { screen_update(mpd); mpd->events = 0; + + check_reconnect(); } int do_input_event(command_t cmd)