[libsoup] port to GTask



commit e9ce1914f50a46db28ed6a9878f8cf12ea8938bd
Author: Dan Winship <danw gnome org>
Date:   Mon Jun 18 09:54:41 2012 -0400

    port to GTask

 configure.ac                          |    4 +-
 libsoup/soup-address.c                |   34 +++++--------
 libsoup/soup-client-input-stream.c    |   75 +++++++++++++---------------
 libsoup/soup-message-queue.c          |    4 +-
 libsoup/soup-message-queue.h          |    2 +-
 libsoup/soup-multipart-input-stream.c |   52 +++++++-------------
 libsoup/soup-request-file.c           |   38 ++++++---------
 libsoup/soup-request-http.c           |   87 +++++++++++++--------------------
 libsoup/soup-request.c                |   23 +++++----
 libsoup/soup-session-async.c          |   46 +++++++-----------
 10 files changed, 151 insertions(+), 214 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 438df9c..7576359 100644
--- a/configure.ac
+++ b/configure.ac
@@ -83,12 +83,12 @@ dnl ***********************
 dnl *** Checks for glib ***
 dnl ***********************
 
-GLIB_REQUIRED=2.33.1
+GLIB_REQUIRED=2.35.0
 AM_PATH_GLIB_2_0($GLIB_REQUIRED,,,gobject gio)
 if test "$GLIB_LIBS" = ""; then
    AC_MSG_ERROR(GLIB $GLIB_REQUIRED or later is required to build libsoup)
 fi
-GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_34"
+GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36"
 
 GLIB_MAKEFILE='$(top_srcdir)/Makefile.glib'
 AC_SUBST(GLIB_MAKEFILE)
diff --git a/libsoup/soup-address.c b/libsoup/soup-address.c
index c298d3e..521ff76 100644
--- a/libsoup/soup-address.c
+++ b/libsoup/soup-address.c
@@ -1111,15 +1111,19 @@ soup_address_address_enumerator_next (GSocketAddressEnumerator  *enumerator,
 static void
 got_addresses (SoupAddress *addr, guint status, gpointer user_data)
 {
-	GSimpleAsyncResult *simple = user_data;
+	GTask *task = user_data;
 	GError *error;
 
 	error = g_object_get_data (G_OBJECT (addr), "async-resolved-error");
 	if (error)
-		g_simple_async_result_set_from_error (simple, error);
+		g_task_return_error (task, error);
+	else {
+		GSocketAddress *addr;
 
-	g_simple_async_result_complete (simple);
-	g_object_unref (simple);
+		addr = next_address (g_task_get_source_object (task));
+		g_task_return_pointer (task, addr, g_object_unref);
+	}
+	g_object_unref (task);
 }
 
 static void
@@ -1131,18 +1135,15 @@ soup_address_address_enumerator_next_async (GSocketAddressEnumerator  *enumerato
 	SoupAddressAddressEnumerator *addr_enum =
 		SOUP_ADDRESS_ADDRESS_ENUMERATOR (enumerator);
 	SoupAddressPrivate *priv = SOUP_ADDRESS_GET_PRIVATE (addr_enum->addr);
-	GSimpleAsyncResult *simple;
-
-	simple = g_simple_async_result_new (G_OBJECT (enumerator),
-					    callback, user_data,
-					    soup_address_address_enumerator_next_async);
+	GTask *task;
 
+	task = g_task_new (enumerator, cancellable, callback, user_data);
 	if (!priv->sockaddr) {
 		soup_address_resolve_async (addr_enum->addr, NULL, cancellable,
-					    got_addresses, simple);
+					    got_addresses, task);
 	} else {
-		g_simple_async_result_complete_in_idle (simple);
-		g_object_unref (simple);
+		g_task_return_pointer (task, next_address (addr_enum), g_object_unref);
+		g_object_unref (task);
 	}
 }
 
@@ -1151,14 +1152,7 @@ soup_address_address_enumerator_next_finish (GSocketAddressEnumerator  *enumerat
 					     GAsyncResult              *result,
 					     GError                   **error)
 {
-	SoupAddressAddressEnumerator *addr_enum =
-		SOUP_ADDRESS_ADDRESS_ENUMERATOR (enumerator);
-	GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
-
-	if (g_simple_async_result_propagate_error (simple, error))
-		return NULL;
-	else 
-		return next_address (addr_enum);
+	return g_task_propagate_pointer (G_TASK (result), error);
 }
 
 static void
diff --git a/libsoup/soup-client-input-stream.c b/libsoup/soup-client-input-stream.c
index 966b940..ddcabaa 100644
--- a/libsoup/soup-client-input-stream.c
+++ b/libsoup/soup-client-input-stream.c
@@ -157,40 +157,43 @@ soup_client_input_stream_close_fn (GInputStream  *stream,
 						 cancellable, error);
 }
 
-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,
+					       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);
+	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;
 }
 
@@ -201,22 +204,17 @@ 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 ());
+	task = g_task_new (stream, cancellable, callback, user_data);
+	g_task_set_priority (task, priority);
+
+	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);
 }
 
@@ -225,12 +223,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
diff --git a/libsoup/soup-message-queue.c b/libsoup/soup-message-queue.c
index 2a60446..9afa31e 100644
--- a/libsoup/soup-message-queue.c
+++ b/libsoup/soup-message-queue.c
@@ -185,8 +185,8 @@ soup_message_queue_item_unref (SoupMessageQueueItem *item)
 		g_object_unref (item->proxy_addr);
 	if (item->proxy_uri)
 		soup_uri_free (item->proxy_uri);
-	if (item->result)
-		g_object_unref (item->result);
+	if (item->task)
+		g_object_unref (item->task);
 	if (item->io_source) {
 		g_source_destroy (item->io_source);
 		g_source_unref (item->io_source);
diff --git a/libsoup/soup-message-queue.h b/libsoup/soup-message-queue.h
index 0f948cc..627fd2d 100644
--- a/libsoup/soup-message-queue.h
+++ b/libsoup/soup-message-queue.h
@@ -40,7 +40,7 @@ struct _SoupMessageQueueItem {
 	SoupAddress *proxy_addr;
 	SoupURI *proxy_uri;
 	SoupConnection *conn;
-	GSimpleAsyncResult *result;
+	GTask *task;
 	GSource *io_source;
 
 	guint paused            : 1;
diff --git a/libsoup/soup-multipart-input-stream.c b/libsoup/soup-multipart-input-stream.c
index 0867f84..9cd1b3a 100644
--- a/libsoup/soup-multipart-input-stream.c
+++ b/libsoup/soup-multipart-input-stream.c
@@ -483,9 +483,10 @@ soup_multipart_input_stream_next_part (SoupMultipartInputStream  *multipart,
 }
 
 static void
-soup_multipart_input_stream_next_part_thread (GSimpleAsyncResult *simple,
-					      GObject            *object,
-					      GCancellable       *cancellable)
+soup_multipart_input_stream_next_part_thread (GTask        *task,
+					      gpointer      object,
+					      gpointer      task_data,
+					      GCancellable *cancellable)
 {
 	SoupMultipartInputStream *multipart = SOUP_MULTIPART_INPUT_STREAM (object);
 	GError *error = NULL;
@@ -495,11 +496,10 @@ soup_multipart_input_stream_next_part_thread (GSimpleAsyncResult *simple,
 
 	g_input_stream_clear_pending (G_INPUT_STREAM (multipart));
 
-	if (g_simple_async_result_propagate_error (simple, &error))
-		return;
-
-	if (new_stream)
-		g_simple_async_result_set_op_res_gpointer (simple, new_stream, g_object_unref);
+	if (error)
+		g_task_return_error (task, error);
+	else
+		g_task_return_pointer (task, new_stream, g_object_unref);
 }
 
 /**
@@ -520,31 +520,28 @@ soup_multipart_input_stream_next_part_thread (GSimpleAsyncResult *simple,
  */
 void
 soup_multipart_input_stream_next_part_async (SoupMultipartInputStream *multipart,
-					     int                      io_priority,
+					     int                       io_priority,
 					     GCancellable	      *cancellable,
 					     GAsyncReadyCallback       callback,
 					     gpointer		       data)
 {
 	GInputStream *stream = G_INPUT_STREAM (multipart);
-	GSimpleAsyncResult *simple;
+	GTask *task;
 	GError *error = NULL;
 
 	g_return_if_fail (SOUP_IS_MULTIPART_INPUT_STREAM (multipart));
 
-	simple = g_simple_async_result_new (G_OBJECT (multipart),
-					    callback, data,
-					    soup_multipart_input_stream_next_part_async);
+	task = g_task_new (multipart, cancellable, callback, data);
+	g_task_set_priority (task, io_priority);
 
 	if (!g_input_stream_set_pending (stream, &error)) {
-		g_simple_async_result_take_error (simple, error);
-		g_simple_async_result_complete_in_idle (simple);
-		g_object_unref (simple);
+		g_task_return_error (task, error);
+		g_object_unref (task);
 		return;
 	}
 
-	g_simple_async_result_run_in_thread (simple, soup_multipart_input_stream_next_part_thread,
-					     io_priority, cancellable);
-	g_object_unref (simple);
+	g_task_run_in_thread (task, soup_multipart_input_stream_next_part_thread);
+	g_object_unref (task);
 }
 
 /**
@@ -565,22 +562,9 @@ soup_multipart_input_stream_next_part_finish (SoupMultipartInputStream	*multipar
 					      GAsyncResult		*result,
 					      GError		       **error)
 {
-	GSimpleAsyncResult *simple;
-	GInputStream *new_stream;
-
-	g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (multipart),
-							      soup_multipart_input_stream_next_part_async), FALSE);
-
-	simple = G_SIMPLE_ASYNC_RESULT (result);
-
-	if (g_simple_async_result_propagate_error (simple, error))
-		return NULL;
-
-	new_stream = g_simple_async_result_get_op_res_gpointer (simple);
-	if (new_stream)
-		return g_object_ref (new_stream);
+	g_return_val_if_fail (g_task_is_valid (result, multipart), FALSE);
 
-	return NULL;
+	return g_task_propagate_pointer (G_TASK (result), error);
 }
 
 /**
diff --git a/libsoup/soup-request-file.c b/libsoup/soup-request-file.c
index 73d0cd8..22642f4 100644
--- a/libsoup/soup-request-file.c
+++ b/libsoup/soup-request-file.c
@@ -192,36 +192,33 @@ soup_request_file_send (SoupRequest          *request,
 }
 
 static void
-soup_request_file_send_async_thread (GSimpleAsyncResult *res,
-				     GObject            *object,
-				     GCancellable       *cancellable)
+soup_request_file_send_async_thread (GTask        *task,
+				     gpointer      source_object,
+				     gpointer      task_data,
+				     GCancellable *cancellable)
 {
+	SoupRequest *request = source_object;
 	GInputStream *stream;
-	SoupRequest *request;
 	GError *error = NULL;
 
-	request = SOUP_REQUEST (object);
-
 	stream = soup_request_file_send (request, cancellable, &error);
-
 	if (stream == NULL)
-		g_simple_async_result_take_error (res, error);
+		g_task_return_error (task, error);
 	else
-		g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
+		g_task_return_pointer (task, stream, g_object_unref);
 }
 
 static void
 soup_request_file_send_async (SoupRequest          *request,
 			      GCancellable         *cancellable,
-			      GAsyncReadyCallback callback,
-			      gpointer user_data)
+			      GAsyncReadyCallback   callback,
+			      gpointer              user_data)
 {
-	GSimpleAsyncResult *res;
-
-	res = g_simple_async_result_new (G_OBJECT (request), callback, user_data, soup_request_file_send_async);
+	GTask *task;
 
-	g_simple_async_result_run_in_thread (res, soup_request_file_send_async_thread, G_PRIORITY_DEFAULT, cancellable);
-	g_object_unref (res);
+	task = g_task_new (request, cancellable, callback, user_data);
+	g_task_run_in_thread (task, soup_request_file_send_async_thread);
+	g_object_unref (task);
 }
 
 static GInputStream *
@@ -229,14 +226,9 @@ soup_request_file_send_finish (SoupRequest          *request,
 			       GAsyncResult         *result,
 			       GError              **error)
 {
-	GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
-
-	g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == soup_request_file_send_async);
-
-	if (g_simple_async_result_propagate_error (simple, error))
-		return NULL;
+	g_return_val_if_fail (g_task_is_valid (result, request), NULL);
 
-	return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
+	return g_task_propagate_pointer (G_TASK (result), error);
 }
 
 static goffset
diff --git a/libsoup/soup-request-http.c b/libsoup/soup-request-http.c
index 4fc8220..d817cd0 100644
--- a/libsoup/soup-request-http.c
+++ b/libsoup/soup-request-http.c
@@ -99,10 +99,6 @@ soup_request_http_send (SoupRequest          *request,
 
 
 typedef struct {
-	SoupRequestHTTP *http;
-	GCancellable *cancellable;
-	GSimpleAsyncResult *simple;
-
 	SoupMessage *original;
 	GInputStream *stream;
 } SendAsyncData;
@@ -110,10 +106,6 @@ typedef struct {
 static void
 free_send_async_data (SendAsyncData *sadata)
 {
-       g_object_unref (sadata->http);
-       g_object_unref (sadata->simple);
-
-       g_clear_object (&sadata->cancellable);
        g_clear_object (&sadata->stream);
        g_clear_object (&sadata->original);
 
@@ -123,25 +115,24 @@ free_send_async_data (SendAsyncData *sadata)
 static void
 http_input_stream_ready_cb (GObject *source, GAsyncResult *result, gpointer user_data)
 {
-	SendAsyncData *sadata = user_data;
+	GTask *task = user_data;
 	GError *error = NULL;
 	GInputStream *stream;
 
 	stream = soup_session_send_request_finish (SOUP_SESSION (source), result, &error);
-	if (stream) {
-		g_simple_async_result_set_op_res_gpointer (sadata->simple, stream, g_object_unref);
-	} else {
-		g_simple_async_result_take_error (sadata->simple, error);
-	}
-	g_simple_async_result_complete (sadata->simple);
-	free_send_async_data (sadata);
+	if (stream)
+		g_task_return_pointer (task, stream, g_object_unref);
+	else
+		g_task_return_error (task, error);
+	g_object_unref (task);
 }
 
-
 static void
 conditional_get_ready_cb (SoupSession *session, SoupMessage *msg, gpointer user_data)
 {
-	SendAsyncData *sadata = user_data;
+	GTask *task = user_data;
+	SoupRequestHTTP *http = g_task_get_source_object (task);
+	SendAsyncData *sadata = g_task_get_task_data (task);
 	GInputStream *stream;
 
 	if (msg->status_code == SOUP_STATUS_NOT_MODIFIED) {
@@ -149,16 +140,13 @@ conditional_get_ready_cb (SoupSession *session, SoupMessage *msg, gpointer user_
 
 		stream = soup_cache_send_response (cache, sadata->original);
 		if (stream) {
-			g_simple_async_result_set_op_res_gpointer (sadata->simple, stream, g_object_unref);
-
 			soup_message_got_headers (sadata->original);
+			soup_message_finished (sadata->original);
 
-			sadata->http->priv->content_type = g_strdup (soup_message_headers_get_content_type (msg->response_headers, NULL));
-
-			g_simple_async_result_complete (sadata->simple);
+			http->priv->content_type = g_strdup (soup_message_headers_get_content_type (msg->response_headers, NULL));
 
-			soup_message_finished (sadata->original);
-			free_send_async_data (sadata);
+			g_task_return_pointer (task, stream, g_object_unref);
+			g_object_unref (task);
 			return;
 		}
 	}
@@ -168,28 +156,27 @@ conditional_get_ready_cb (SoupSession *session, SoupMessage *msg, gpointer user_
 	 * we're donwloading the resource twice, but we will change it
 	 * once the cache is integrated in the streams stack.
 	 */
-	soup_session_send_request_async (session, sadata->original, sadata->cancellable,
-					 http_input_stream_ready_cb, sadata);
+	soup_session_send_request_async (session, sadata->original,
+					 g_task_get_cancellable (task),
+					 http_input_stream_ready_cb, task);
 }
 
 static gboolean
 idle_return_from_cache_cb (gpointer data)
 {
-	SendAsyncData *sadata = data;
-
-	g_simple_async_result_set_op_res_gpointer (sadata->simple,
-						   g_object_ref (sadata->stream), g_object_unref);
+	GTask *task = data;
+	SoupRequestHTTP *http = g_task_get_source_object (task);
+	SendAsyncData *sadata = g_task_get_task_data (task);
 
 	/* Issue signals  */
-	soup_message_got_headers (sadata->http->priv->msg);
+	soup_message_got_headers (http->priv->msg);
+	soup_message_finished (http->priv->msg);
 
-	sadata->http->priv->content_type = g_strdup (soup_message_headers_get_content_type (sadata->http->priv->msg->response_headers, NULL));
+	http->priv->content_type = g_strdup (soup_message_headers_get_content_type (http->priv->msg->response_headers, NULL));
 
-	g_simple_async_result_complete (sadata->simple);
+	g_task_return_pointer (task, g_object_ref (sadata->stream), g_object_unref);
+	g_object_unref (task);
 
-	soup_message_finished (sadata->http->priv->msg);
-
-	free_send_async_data (sadata);
 	return FALSE;
 }
 
@@ -200,16 +187,15 @@ soup_request_http_send_async (SoupRequest          *request,
 			      gpointer              user_data)
 {
 	SoupRequestHTTP *http = SOUP_REQUEST_HTTP (request);
+	GTask *task;
 	SendAsyncData *sadata;
 	GInputStream *stream;
 	SoupSession *session;
 	SoupCache *cache;
 
+	task = g_task_new (request, cancellable, callback, user_data);
 	sadata = g_slice_new0 (SendAsyncData);
-	sadata->http = g_object_ref (http);
-	sadata->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
-	sadata->simple = g_simple_async_result_new (G_OBJECT (request), callback, user_data,
-						    soup_request_http_send_async);
+	g_task_set_task_data (task, sadata, (GDestroyNotify)free_send_async_data);
 
 	session = soup_request_get_session (request);
 	cache = (SoupCache *)soup_session_get_feature (session, SOUP_TYPE_CACHE);
@@ -224,14 +210,14 @@ soup_request_http_send_async (SoupRequest          *request,
 			/* Cached resource file could have been deleted outside */
 			if (stream) {
 				/* Do return the stream asynchronously as in
-				 * the other cases. It's not enough to use
-				 * g_simple_async_result_complete_in_idle as
+				 * the other cases. It's not enough to let
+				 * GTask do the asynchrony for us, because
 				 * the signals must be also emitted
 				 * asynchronously
 				 */
 				sadata->stream = stream;
 				soup_add_completion (soup_session_get_async_context (session),
-						     idle_return_from_cache_cb, sadata);
+						     idle_return_from_cache_cb, task);
 				return;
 			}
 		} else if (response == SOUP_CACHE_RESPONSE_NEEDS_VALIDATION) {
@@ -243,14 +229,14 @@ soup_request_http_send_async (SoupRequest          *request,
 				sadata->original = g_object_ref (http->priv->msg);
 				soup_session_queue_message (session, conditional_msg,
 							    conditional_get_ready_cb,
-							    sadata);
+							    task);
 				return;
 			}
 		}
 	}
 
 	soup_session_send_request_async (session, http->priv->msg, cancellable,
-					 http_input_stream_ready_cb, sadata);
+					 http_input_stream_ready_cb, task);
 }
 
 static GInputStream *
@@ -258,14 +244,9 @@ soup_request_http_send_finish (SoupRequest   *request,
 			       GAsyncResult  *result,
 			       GError       **error)
 {
-	GSimpleAsyncResult *simple;
-
-	g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (request), soup_request_http_send_async), NULL);
+	g_return_val_if_fail (g_task_is_valid (result, request), NULL);
 
-	simple = G_SIMPLE_ASYNC_RESULT (result);
-	if (g_simple_async_result_propagate_error (simple, error))
-		return NULL;
-	return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
+	return g_task_propagate_pointer (G_TASK (result), error);
 }
 
 static goffset
diff --git a/libsoup/soup-request.c b/libsoup/soup-request.c
index e7471c1..dbc8361 100644
--- a/libsoup/soup-request.c
+++ b/libsoup/soup-request.c
@@ -173,13 +173,18 @@ soup_request_default_send_async (SoupRequest          *request,
 				 GAsyncReadyCallback   callback,
 				 gpointer              user_data)
 {
-	GSimpleAsyncResult *simple;
-
-	simple = g_simple_async_result_new (G_OBJECT (request),
-					    callback, user_data,
-					    soup_request_default_send_async);
-	g_simple_async_result_complete_in_idle (simple);
-	g_object_unref (simple);
+	GTask *task;
+	GInputStream *stream;
+	GError *error = NULL;
+
+	task = g_task_new (request, cancellable, callback, user_data);
+
+	stream = soup_request_send (request, cancellable, &error);
+	if (stream)
+		g_task_return_pointer (task, stream, g_object_unref);
+	else
+		g_task_return_error (task, error);
+	g_object_unref (task);
 }
 
 static GInputStream *
@@ -187,9 +192,7 @@ soup_request_default_send_finish (SoupRequest          *request,
 				  GAsyncResult         *result,
 				  GError              **error)
 {
-	g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (request), soup_request_default_send_async), NULL);
-
-	return soup_request_send (request, NULL, error);
+	return g_task_propagate_pointer (G_TASK (result), error);
 }
 
 /**
diff --git a/libsoup/soup-session-async.c b/libsoup/soup-session-async.c
index 398cc0f..57d8617 100644
--- a/libsoup/soup-session-async.c
+++ b/libsoup/soup-session-async.c
@@ -473,10 +473,10 @@ static void
 send_request_return_result (SoupMessageQueueItem *item,
 			    gpointer stream, GError *error)
 {
-	GSimpleAsyncResult *simple;
+	GTask *task;
 
-	simple = item->result;
-	item->result = NULL;
+	task = item->task;
+	item->task = NULL;
 
 	if (item->io_source) {
 		g_source_destroy (item->io_source);
@@ -484,20 +484,17 @@ send_request_return_result (SoupMessageQueueItem *item,
 	}
 
 	if (error)
-		g_simple_async_result_take_error (simple, error);
+		g_task_return_error (task, error);
 	else if (SOUP_STATUS_IS_TRANSPORT_ERROR (item->msg->status_code)) {
 		if (stream)
 			g_object_unref (stream);
-		g_simple_async_result_set_error (simple,
-						 SOUP_HTTP_ERROR,
-						 item->msg->status_code,
-						 "%s",
-						 item->msg->reason_phrase);
+		g_task_return_new_error (task, SOUP_HTTP_ERROR,
+					 item->msg->status_code,
+					 "%s",
+					 item->msg->reason_phrase);
 	} else
-		g_simple_async_result_set_op_res_gpointer (simple, stream, g_object_unref);
-
-	g_simple_async_result_complete (simple);
-	g_object_unref (simple);
+		g_task_return_pointer (task, stream, g_object_unref);
+	g_object_unref (task);
 }
 
 static void
@@ -515,12 +512,12 @@ send_request_finished (SoupSession *session, SoupMessageQueueItem *item)
 	GInputStream *istream = NULL;
 	GError *error = NULL;
 
-	if (!item->result) {
+	if (!item->task) {
 		/* Something else already took care of it. */
 		return;
 	}
 
-	mostream = g_object_get_data (G_OBJECT (item->result), "SoupSessionAsync:ostream");
+	mostream = g_object_get_data (G_OBJECT (item->task), "SoupSessionAsync:ostream");
 	if (mostream) {
 		gpointer data;
 		gssize size;
@@ -563,7 +560,7 @@ send_async_spliced (GObject *source, GAsyncResult *result, gpointer user_data)
 
 	/* If the message was cancelled, it will be completed via other means */
 	if (g_cancellable_is_cancelled (item->cancellable) ||
-	    !item->result) {
+	    !item->task) {
 		soup_message_queue_item_unref (item);
 		return;
 	}
@@ -591,7 +588,7 @@ send_async_maybe_complete (SoupMessageQueueItem *item,
 
 		/* Message may be requeued, so gather the current message body... */
 		ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
-		g_object_set_data_full (G_OBJECT (item->result), "SoupSessionAsync:ostream",
+		g_object_set_data_full (G_OBJECT (item->task), "SoupSessionAsync:ostream",
 					ostream, g_object_unref);
 
 		g_object_set_data (G_OBJECT (ostream), "istream", stream);
@@ -693,10 +690,8 @@ soup_session_send_request_async (SoupSession         *session,
 	g_return_if_fail (item != NULL);
 
 	item->new_api = TRUE;
-	item->result = g_simple_async_result_new (G_OBJECT (session),
-						  callback, user_data,
-						  soup_session_send_request_async);
-	g_simple_async_result_set_op_res_gpointer (item->result, item, (GDestroyNotify) soup_message_queue_item_unref);
+	item->task = g_task_new (session, cancellable, callback, user_data);
+	g_task_set_task_data (item->task, item, (GDestroyNotify) soup_message_queue_item_unref);
 
 	if (cancellable) {
 		g_object_unref (item->cancellable);
@@ -709,15 +704,10 @@ soup_session_send_request_finish (SoupSession   *session,
 				  GAsyncResult  *result,
 				  GError       **error)
 {
-	GSimpleAsyncResult *simple;
-
 	g_return_val_if_fail (SOUP_IS_SESSION_ASYNC (session), NULL);
-	g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (session), soup_session_send_request_async), NULL);
+	g_return_val_if_fail (g_task_is_valid (result, session), NULL);
 
-	simple = G_SIMPLE_ASYNC_RESULT (result);
-	if (g_simple_async_result_propagate_error (simple, error))
-		return NULL;
-	return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
+	return g_task_propagate_pointer (G_TASK (result), error);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]