[libgdata] core: Catch SOUP_STATUS_IO_ERROR and treat it as cancellation



commit 0345885c14f2d5c1f80b6460be302adeb3e14103
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sat Aug 20 17:39:06 2011 +0100

    core: Catch SOUP_STATUS_IO_ERROR and treat it as cancellation
    
    When we cancel a request, it's (somehow) possible for libsoup to return
    SOUP_STATUS_IO_ERROR instead of the (desired) SOUP_STATUS_CANCELLED. We now
    catch SOUP_STATUS_IO_ERROR and, if the user requested cancellation, treat it
    like a normal cancellation status.

 gdata/gdata-service.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/gdata/gdata-service.c b/gdata/gdata-service.c
index a082668..d0e1f3e 100644
--- a/gdata/gdata-service.c
+++ b/gdata/gdata-service.c
@@ -630,16 +630,22 @@ _gdata_service_actually_send_message (SoupSession *session, SoupMessage *message
 	}
 
 	/* Set the cancellation error if applicable. We can't assume that our GCancellable has been cancelled just because the message has;
-	 * libsoup may internally cancel messages if, for example, the proxy URI of the SoupSession is changed. */
+	 * libsoup may internally cancel messages if, for example, the proxy URI of the SoupSession is changed.
+	 * libsoup also sometimes seems to return a SOUP_STATUS_IO_ERROR when we cancel a message, even though we've specified SOUP_STATUS_CANCELLED
+	 * at cancellation time. Ho Hum. */
 	g_assert (message->status_code != SOUP_STATUS_NONE);
 
-	if (message->status_code == SOUP_STATUS_CANCELLED) {
+	if (message->status_code == SOUP_STATUS_CANCELLED ||
+	    (message->status_code == SOUP_STATUS_IO_ERROR && cancellable != NULL && g_cancellable_is_cancelled (cancellable) == TRUE)) {
 		/* We hackily create and cancel a new GCancellable so that we can set the error using it and therefore save ourselves a translatable
 		 * string and the associated maintenance. */
 		GCancellable *error_cancellable = g_cancellable_new ();
 		g_cancellable_cancel (error_cancellable);
 		g_assert (g_cancellable_set_error_if_cancelled (error_cancellable, error) == TRUE);
 		g_object_unref (error_cancellable);
+
+		/* As per the above comment, force the status to be SOUP_STATUS_CANCELLED. */
+		soup_message_set_status (message, SOUP_STATUS_CANCELLED);
 	}
 
 	/* Free things */



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