From: Max Kellermann Date: Fri, 16 Oct 2009 13:08:51 +0000 (+0200) Subject: gidle: mpd_glib_enter() returns success X-Git-Tag: release-0.16~100 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ea237ee661ffcd1c16a7bb72364e83c7642f2427;p=ncmpc.git gidle: mpd_glib_enter() returns success mpd_glib_enter() is unreliable, because it does nothing when called during the callback, which in turn was invoked by mpd_glib_leave(). Sometimes, mpdclient.idle is wrong because of that. This patch sets mpdclient.idle to the return value of mpd_glib_enter(). --- diff --git a/src/gidle.c b/src/gidle.c index d4fd807..2165294 100644 --- a/src/gidle.c +++ b/src/gidle.c @@ -337,7 +337,7 @@ mpd_glib_add_watch(struct mpd_glib_source *source) source->io_events = events; } -void +bool mpd_glib_enter(struct mpd_glib_source *source) { bool success; @@ -347,17 +347,18 @@ mpd_glib_enter(struct mpd_glib_source *source) assert(!source->destroyed); if (source->leaving) - return; + return false; source->idle_events = 0; success = mpd_async_send_command(source->async, "idle", NULL); if (!success) { mpd_glib_invoke_async_error(source); - return; + return false; } mpd_glib_add_watch(source); + return true; } bool diff --git a/src/gidle.h b/src/gidle.h index 6d17f76..2404116 100644 --- a/src/gidle.h +++ b/src/gidle.h @@ -45,7 +45,13 @@ mpd_glib_new(struct mpd_connection *connection, void mpd_glib_free(struct mpd_glib_source *source); -void +/** + * Enters idle mode. + * + * @return true if idle mode has been entered, false if not + * (e.g. blocked during the callback, or I/O error) + */ +bool mpd_glib_enter(struct mpd_glib_source *source); /** diff --git a/src/mpdclient.c b/src/mpdclient.c index e380ac0..748baed 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -252,8 +252,7 @@ mpdclient_put_connection(struct mpdclient *c) assert(c->source == NULL || c->connection != NULL); if (c->source != NULL && !c->idle) { - c->idle = true; - mpd_glib_enter(c->source); + c->idle = mpd_glib_enter(c->source); } }