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.
This commit is contained in:
Max Kellermann 2011-09-16 20:34:42 +02:00
parent 59abdbd2dd
commit 65dfd90141

View File

@ -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)