From 65dfd90141e51d896e0988fe3c6afd3d3f9d7460 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 16 Sep 2011 20:34:42 +0200 Subject: input/soup: move libsoup calls to the I/O thread libsoup's asynchronous API is not thread safe. By moving the calls into the I/O thread, several crash bugs will be fixed. --- src/input/soup_input_plugin.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/input/soup_input_plugin.c b/src/input/soup_input_plugin.c index 7f92113b4..12ede3a29 100644 --- a/src/input/soup_input_plugin.c +++ b/src/input/soup_input_plugin.c @@ -220,6 +220,17 @@ input_soup_wait_data(struct input_soup *s) } } +static gpointer +input_soup_queue(gpointer data) +{ + struct input_soup *s = data; + + soup_session_queue_message(soup_session, s->msg, + input_soup_session_callback, s); + + return NULL; +} + static struct input_stream * input_soup_open(const char *uri, G_GNUC_UNUSED GError **error_r) { @@ -255,12 +266,23 @@ input_soup_open(const char *uri, G_GNUC_UNUSED GError **error_r) s->completed = false; s->postponed_error = NULL; - soup_session_queue_message(soup_session, s->msg, - input_soup_session_callback, s); + io_thread_call(input_soup_queue, s); return &s->base; } +static gpointer +input_soup_cancel(gpointer data) +{ + struct input_soup *s = data; + + if (!s->completed) + soup_session_cancel_message(soup_session, s->msg, + SOUP_STATUS_CANCELLED); + + return NULL; +} + static void input_soup_close(struct input_stream *is) { @@ -274,8 +296,7 @@ input_soup_close(struct input_stream *is) g_mutex_unlock(s->mutex); - soup_session_cancel_message(soup_session, s->msg, - SOUP_STATUS_CANCELLED); + io_thread_call(input_soup_cancel, s); g_mutex_lock(s->mutex); while (!s->completed) -- cgit v1.2.3