From a537ee8a0acf9fee2347400537dd5f9cd345bc14 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 29 Sep 2009 22:26:31 +0200 Subject: [PATCH] mpdclient: mpdclient_connect() returns bool .. and disable recovery with mpdclient_handle_error(). --- src/main.c | 12 ++++++------ src/mpdclient.c | 14 +++++--------- src/mpdclient.h | 5 +++-- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main.c b/src/main.c index 6010482..0cbe184 100644 --- a/src/main.c +++ b/src/main.c @@ -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; diff --git a/src/mpdclient.c b/src/mpdclient.c index 58094a9..179aecc 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -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 diff --git a/src/mpdclient.h b/src/mpdclient.h index d7fd555..fa2f1b6 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -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); -- 2.30.2