diff options
Diffstat (limited to 'libsoup/soup-client-input-stream.c')
-rw-r--r-- | libsoup/soup-client-input-stream.c | 125 |
1 files changed, 56 insertions, 69 deletions
diff --git a/libsoup/soup-client-input-stream.c b/libsoup/soup-client-input-stream.c index 5c18eaa0..0264cb79 100644 --- a/libsoup/soup-client-input-stream.c +++ b/libsoup/soup-client-input-stream.c @@ -11,7 +11,6 @@ #include "soup-client-input-stream.h" #include "soup.h" -#include "soup-marshal.h" #include "soup-message-private.h" struct _SoupClientInputStreamPrivate { @@ -47,6 +46,16 @@ soup_client_input_stream_init (SoupClientInputStream *stream) } static void +soup_client_input_stream_finalize (GObject *object) +{ + SoupClientInputStream *cistream = SOUP_CLIENT_INPUT_STREAM (object); + + g_clear_object (&cistream->priv->msg); + + G_OBJECT_CLASS (soup_client_input_stream_parent_class)->finalize (object); +} + +static void soup_client_input_stream_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { @@ -78,17 +87,6 @@ soup_client_input_stream_get_property (GObject *object, guint prop_id, } } -/* Temporary HACK to keep SoupCache working. See soup_client_input_stream_read_fn() - * and soup_client_input_stream_read_nonblocking(). - */ -static void -soup_client_input_stream_emit_got_chunk (SoupClientInputStream *stream, void *data, gssize nread) -{ - SoupBuffer *buffer = soup_buffer_new (SOUP_MEMORY_TEMPORARY, data, nread); - soup_message_got_chunk (stream->priv->msg, buffer); - soup_buffer_free (buffer); -} - static gssize soup_client_input_stream_read_fn (GInputStream *stream, void *buffer, @@ -104,12 +102,6 @@ soup_client_input_stream_read_fn (GInputStream *stream, if (nread == 0) g_signal_emit (stream, signals[EOF], 0); - /* Temporary HACK to keep SoupCache working */ - if (nread > 0) { - soup_client_input_stream_emit_got_chunk (SOUP_CLIENT_INPUT_STREAM (stream), - buffer, nread); - } - return nread; } @@ -127,12 +119,6 @@ soup_client_input_stream_read_nonblocking (GPollableInputStream *stream, if (nread == 0) g_signal_emit (stream, signals[EOF], 0); - /* Temporary HACK to keep SoupCache working */ - if (nread > 0) { - soup_client_input_stream_emit_got_chunk (SOUP_CLIENT_INPUT_STREAM (stream), - buffer, nread); - } - return nread; } @@ -142,45 +128,53 @@ soup_client_input_stream_close_fn (GInputStream *stream, GError **error) { SoupClientInputStream *cistream = SOUP_CLIENT_INPUT_STREAM (stream); + gboolean success; - return soup_message_io_run_until_finish (cistream->priv->msg, - cancellable, error); + success = soup_message_io_run_until_finish (cistream->priv->msg, TRUE, + NULL, error); + soup_message_io_finished (cistream->priv->msg); + return success; } -typedef struct { - SoupClientInputStream *cistream; - gint priority; - GCancellable *cancellable; - GSimpleAsyncResult *result; -} CloseAsyncData; - -static void -close_async_data_free (CloseAsyncData *cad) +static gboolean +idle_finish_close (gpointer user_data) { - g_clear_object (&cad->cancellable); - g_object_unref (cad->result); - g_slice_free (CloseAsyncData, cad); + GTask *task = user_data; + + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return FALSE; } static gboolean close_async_ready (SoupMessage *msg, gpointer user_data) { - CloseAsyncData *cad = user_data; + GTask *task = user_data; + SoupClientInputStream *cistream = g_task_get_source_object (task); GError *error = NULL; - if (!soup_message_io_run_until_finish (cad->cistream->priv->msg, - cad->cancellable, &error) && + if (!soup_message_io_run_until_finish (cistream->priv->msg, FALSE, + g_task_get_cancellable (task), + &error) && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { g_error_free (error); return TRUE; } - if (error) - g_simple_async_result_take_error (cad->result, error); - else - g_simple_async_result_set_op_res_gboolean (cad->result, TRUE); - g_simple_async_result_complete_in_idle (cad->result); - close_async_data_free (cad); + soup_message_io_finished (cistream->priv->msg); + + if (error) { + g_task_return_error (task, error); + g_object_unref (task); + return FALSE; + } + + /* Due to a historical accident, SoupSessionAsync relies on us + * waiting one extra cycle after run_until_finish() returns. + * Ugh. FIXME later when it's easier to do. + */ + soup_add_idle (g_main_context_get_thread_default (), + idle_finish_close, task); return FALSE; } @@ -191,23 +185,20 @@ soup_client_input_stream_close_async (GInputStream *stream, GAsyncReadyCallback callback, gpointer user_data) { - CloseAsyncData *cad; + SoupClientInputStream *cistream = SOUP_CLIENT_INPUT_STREAM (stream); + GTask *task; GSource *source; - cad = g_slice_new (CloseAsyncData); - cad->cistream = SOUP_CLIENT_INPUT_STREAM (stream); - cad->result = g_simple_async_result_new (G_OBJECT (stream), - callback, user_data, - soup_client_input_stream_close_async); - cad->priority = priority; - cad->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - - source = soup_message_io_get_source (cad->cistream->priv->msg, - cancellable, - close_async_ready, cad); - g_source_set_priority (source, priority); - g_source_attach (source, g_main_context_get_thread_default ()); - g_source_unref (source); + task = g_task_new (stream, cancellable, callback, user_data); + g_task_set_priority (task, priority); + + if (close_async_ready (cistream->priv->msg, task) == G_SOURCE_CONTINUE) { + source = soup_message_io_get_source (cistream->priv->msg, + cancellable, NULL, NULL); + + g_task_attach_source (task, source, (GSourceFunc) close_async_ready); + g_source_unref (source); + } } static gboolean @@ -215,12 +206,7 @@ soup_client_input_stream_close_finish (GInputStream *stream, GAsyncResult *result, GError **error) { - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - else - return g_simple_async_result_get_op_res_gboolean (simple); + return g_task_propagate_boolean (G_TASK (result), error); } static void @@ -231,6 +217,7 @@ soup_client_input_stream_class_init (SoupClientInputStreamClass *stream_class) g_type_class_add_private (stream_class, sizeof (SoupClientInputStreamPrivate)); + object_class->finalize = soup_client_input_stream_finalize; object_class->set_property = soup_client_input_stream_set_property; object_class->get_property = soup_client_input_stream_get_property; @@ -245,7 +232,7 @@ soup_client_input_stream_class_init (SoupClientInputStreamClass *stream_class) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - _soup_marshal_NONE__NONE, + NULL, G_TYPE_NONE, 0); g_object_class_install_property ( |