From: Max Kellermann Date: Fri, 17 Mar 2017 22:15:56 +0000 (+0100) Subject: mpdclient: add _is_dead() X-Git-Tag: v0.26~47 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d3d8af3ee60db939a6c5b3b70fe554585df10009;p=ncmpc.git mpdclient: add _is_dead() Prepare for asynchronous connect. --- diff --git a/src/main.c b/src/main.c index 177f1b5..ec051f4 100644 --- a/src/main.c +++ b/src/main.c @@ -252,7 +252,7 @@ default_settings_name(void) static gboolean timer_reconnect(gcc_unused gpointer data) { - assert(!mpdclient_is_connected(mpd)); + assert(mpdclient_is_dead(mpd)); reconnect_source_id = 0; @@ -307,7 +307,7 @@ timer_reconnect(gcc_unused gpointer data) static void check_reconnect(void) { - if (!mpdclient_is_connected(mpd) && reconnect_source_id == 0) + if (mpdclient_is_dead(mpd) && reconnect_source_id == 0) /* reconnect when the connection is lost */ reconnect_source_id = g_timeout_add(1000, timer_reconnect, NULL); diff --git a/src/mpdclient.h b/src/mpdclient.h index 7756710..8487846 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -90,6 +90,17 @@ mpdclient_is_connected(const struct mpdclient *c) return c->connection != NULL; } +/** + * Is this object "dead"? i.e. not connected and not currently doing + * anything to connect. + */ +gcc_pure +static inline bool +mpdclient_is_dead(const struct mpdclient *c) +{ + return c->connection == NULL; +} + gcc_pure static inline bool mpdclient_is_playing(const struct mpdclient *c)