Code

mpdclient: mpdclient_connect() returns bool
authorMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 20:26:31 +0000 (22:26 +0200)
committerMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 20:26:31 +0000 (22:26 +0200)
.. and disable recovery with mpdclient_handle_error().

src/main.c
src/mpdclient.c
src/mpdclient.h

index 6010482a45a45dc58ac28a703ceac5036ef4a5a5..0cbe184bca87554ce95c9a114df8820bacf40698 100644 (file)
@@ -176,7 +176,7 @@ timer_mpd_update(gpointer data);
 static gboolean
 timer_reconnect(G_GNUC_UNUSED gpointer data)
 {
-       int ret;
+       bool success;
 
        assert(!mpdclient_is_connected(mpd));
 
@@ -185,11 +185,11 @@ timer_reconnect(G_GNUC_UNUSED gpointer data)
        doupdate();
 
        mpdclient_disconnect(mpd);
-       ret = mpdclient_connect(mpd,
-                               options.host, options.port,
-                               1.5,
-                               options.password);
-       if (ret != 0) {
+       success = mpdclient_connect(mpd,
+                                   options.host, options.port,
+                                   1.5,
+                                   options.password);
+       if (!success) {
                /* try again in 5 seconds */
                g_timeout_add(5000, timer_reconnect, NULL);
                return FALSE;
index 58094a94741852fcfa1f3e7f0ee63b8da9f96004..179aecc2c5c8bd6b24b2c6f1819c01db9912993a 100644 (file)
@@ -179,7 +179,7 @@ mpdclient_disconnect(struct mpdclient *c)
                c->song = NULL;
 }
 
-gint
+bool
 mpdclient_connect(struct mpdclient *c,
                  const gchar *host,
                  gint port,
@@ -198,13 +198,9 @@ mpdclient_connect(struct mpdclient *c,
                g_error("Out of memory");
 
        if (mpd_connection_get_error(c->connection) != MPD_ERROR_SUCCESS) {
-               retval = mpdclient_handle_error(c);
-               if (retval != 0) {
-                       mpd_connection_free(c->connection);
-                       c->connection = NULL;
-               }
-
-               return retval;
+               mpdclient_handle_error(c);
+               mpdclient_disconnect(c);
+               return false;
        }
 
        /* send password */
@@ -213,7 +209,7 @@ mpdclient_connect(struct mpdclient *c,
                retval = mpdclient_finish_command(c);
        }
 
-       return retval;
+       return true;
 }
 
 gint
index d7fd555e808f78237f00cc969fb335b2242a6096..fa2f1b61dae81096377a5442dcb84cf2d378716d 100644 (file)
@@ -40,8 +40,9 @@ mpdclient_is_connected(const struct mpdclient *c)
        return c->connection != NULL;
 }
 
-gint mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
-                      gfloat timeout_, const gchar *password);
+bool
+mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
+                 gfloat timeout_, const gchar *password);
 
 void
 mpdclient_disconnect(struct mpdclient *c);