aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-06-04 00:49:56 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-06-04 04:27:10 +0200
commitec128558a4d067f51cd36d8026e6df849ea7de26 (patch)
tree412d5145ae258c268b3c9530a48280e0353e25db
parent7f7606008dc06a63a374c3fe87c3381314dc6373 (diff)
downloadliberty-ec128558a4d067f51cd36d8026e6df849ea7de26.tar.gz
liberty-ec128558a4d067f51cd36d8026e6df849ea7de26.tar.xz
liberty-ec128558a4d067f51cd36d8026e6df849ea7de26.zip
MPD client: abort pending tasks
-rw-r--r--liberty-proto.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/liberty-proto.c b/liberty-proto.c
index 0b873e3..94549fd 100644
--- a/liberty-proto.c
+++ b/liberty-proto.c
@@ -1356,7 +1356,7 @@ struct mpd_response
char *message_text; ///< Error message
};
-/// Task completion callback
+/// Task completion callback; on connection abortion most fields are 0
typedef void (*mpd_client_task_cb) (const struct mpd_response *response,
const struct strv *data, void *user_data);
@@ -1449,10 +1449,31 @@ mpd_client_free (struct mpd_client *self)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+static void
+mpd_client_dispatch (struct mpd_client *self, struct mpd_response *response)
+{
+ struct mpd_client_task *task;
+ if (!(task = self->tasks))
+ return;
+
+ if (task->callback)
+ task->callback (response, &self->data, task->user_data);
+ strv_reset (&self->data);
+
+ LIST_UNLINK_WITH_TAIL (self->tasks, self->tasks_tail, task);
+ free (task);
+}
+
/// Reinitialize the interface so that you can reconnect anew
static void
mpd_client_reset (struct mpd_client *self)
{
+ // Get rid of all pending tasks to release resources etc.
+ strv_reset (&self->data);
+ struct mpd_response aborted = { .message_text = "Disconnected" };
+ while (self->tasks)
+ mpd_client_dispatch (self, &aborted);
+
if (self->state == MPD_CONNECTING)
mpd_client_destroy_connector (self);
@@ -1468,17 +1489,11 @@ mpd_client_reset (struct mpd_client *self)
str_reset (&self->read_buffer);
str_reset (&self->write_buffer);
- strv_reset (&self->data);
-
self->got_hello = false;
self->idling = false;
self->idling_subsystems = 0;
self->in_list = false;
- LIST_FOR_EACH (struct mpd_client_task, iter, self->tasks)
- free (iter);
- self->tasks = self->tasks_tail = NULL;
-
self->state = MPD_DISCONNECTED;
}
@@ -1529,21 +1544,6 @@ mpd_client_parse_response (const char *p, struct mpd_response *response)
return true;
}
-static void
-mpd_client_dispatch (struct mpd_client *self, struct mpd_response *response)
-{
- struct mpd_client_task *task;
- if (!(task = self->tasks))
- return;
-
- if (task->callback)
- task->callback (response, &self->data, task->user_data);
- strv_reset (&self->data);
-
- LIST_UNLINK_WITH_TAIL (self->tasks, self->tasks_tail, task);
- free (task);
-}
-
static bool
mpd_client_parse_hello (struct mpd_client *self, const char *line)
{