From d3d8af3ee60db939a6c5b3b70fe554585df10009 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 Mar 2017 23:15:56 +0100 Subject: [PATCH] mpdclient: add _is_dead() Prepare for asynchronous connect. --- src/main.c | 4 ++-- src/mpdclient.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) 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) -- 2.30.2