Code

mpdclient: add _is_dead()
authorMax Kellermann <max.kellermann@gmail.com>
Fri, 17 Mar 2017 22:15:56 +0000 (23:15 +0100)
committerMax Kellermann <max.kellermann@gmail.com>
Fri, 17 Mar 2017 22:30:43 +0000 (23:30 +0100)
Prepare for asynchronous connect.

src/main.c
src/mpdclient.h

index 177f1b529be07e0506fe8d245bf82b5d78c94ceb..ec051f4a8c83de04a54b1e9983910a3847614662 100644 (file)
@@ -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);
index 7756710173a368116e2165f161bf346919bde78f..84878466d22e7a08bc40f42330502745f4f048e9 100644 (file)
@@ -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)