From 182bfa40112e8b73ef3b2cf379f3a9e618db214b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 4 Oct 2009 01:10:26 +0200 Subject: [PATCH] main: check for connection lost in end_input_event() Every GLib event callback which may affect the connection should detect a lost connection. --- src/main.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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) -- 2.30.2