aboutsummaryrefslogtreecommitdiffstats
path: root/src/input/soup_input_plugin.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-09-16 20:12:35 +0200
committerMax Kellermann <max@duempel.org>2011-09-16 20:34:47 +0200
commit59abdbd2dd820069e1ca25e3c44c1b02f906087b (patch)
treecc121b1605d83d1903ad146fe15db50b94d7452b /src/input/soup_input_plugin.c
parenta6d6873856bb024608d50b7d9f6c1167827c76ec (diff)
downloadmpd-59abdbd2dd820069e1ca25e3c44c1b02f906087b.tar.gz
mpd-59abdbd2dd820069e1ca25e3c44c1b02f906087b.tar.xz
mpd-59abdbd2dd820069e1ca25e3c44c1b02f906087b.zip
input/soup: wait for _cancel_message() to complete
Add the "complete" attribute, and set it in _session_callback(). _close() waits for it to become true.
Diffstat (limited to 'src/input/soup_input_plugin.c')
-rw-r--r--src/input/soup_input_plugin.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/input/soup_input_plugin.c b/src/input/soup_input_plugin.c
index 710800294..7f92113b4 100644
--- a/src/input/soup_input_plugin.c
+++ b/src/input/soup_input_plugin.c
@@ -59,6 +59,12 @@ struct input_soup {
bool alive, pause, eof;
+ /**
+ * Set when the session callback has been invoked, when it is
+ * safe to free this object.
+ */
+ bool completed;
+
GError *postponed_error;
};
@@ -116,10 +122,14 @@ input_soup_session_callback(G_GNUC_UNUSED SoupSession *session,
struct input_soup *s = user_data;
assert(msg == s->msg);
+ assert(!s->completed);
g_mutex_lock(s->mutex);
+
s->base.ready = true;
s->alive = false;
+ s->completed = true;
+
g_cond_broadcast(s->cond);
g_mutex_unlock(s->mutex);
}
@@ -242,6 +252,7 @@ input_soup_open(const char *uri, G_GNUC_UNUSED GError **error_r)
s->alive = true;
s->pause = false;
s->eof = false;
+ s->completed = false;
s->postponed_error = NULL;
soup_session_queue_message(soup_session, s->msg,
@@ -257,16 +268,21 @@ input_soup_close(struct input_stream *is)
g_mutex_lock(s->mutex);
- if (s->alive) {
- assert(s->msg != NULL);
+ if (!s->completed) {
+ /* the messages's session callback hasn't been invoked
+ yet; cancel it and wait for completion */
- s->alive = false;
g_mutex_unlock(s->mutex);
soup_session_cancel_message(soup_session, s->msg,
SOUP_STATUS_CANCELLED);
- } else
- g_mutex_unlock(s->mutex);
+
+ g_mutex_lock(s->mutex);
+ while (!s->completed)
+ g_cond_wait(s->cond, s->mutex);
+ }
+
+ g_mutex_unlock(s->mutex);
g_mutex_free(s->mutex);
g_cond_free(s->cond);