[libgdata] core: Don't set the response error when cancelling gdata_upload_stream_write()



commit 61f4f916bfb249c8ed6ff2dcfb5c71a47a6ee902
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Dec 16 22:06:12 2010 +0000

    core: Don't set the response error when cancelling gdata_upload_stream_write()
    
    Helps: bgo#637036

 gdata/gdata-upload-stream.c |   50 +++++++++++++++++++++++-------------------
 1 files changed, 27 insertions(+), 23 deletions(-)
---
diff --git a/gdata/gdata-upload-stream.c b/gdata/gdata-upload-stream.c
index 3d1d3be..e62b833 100644
--- a/gdata/gdata-upload-stream.c
+++ b/gdata/gdata-upload-stream.c
@@ -371,24 +371,24 @@ gdata_upload_stream_set_property (GObject *object, guint property_id, const GVal
 	}
 }
 
+typedef struct {
+	GDataUploadStream *upload_stream;
+	gboolean *cancelled;
+} CancelledData;
+
 static void
-write_cancelled_cb (GCancellable *cancellable, GDataUploadStream *self)
+write_cancelled_cb (GCancellable *cancellable, CancelledData *data)
 {
-	GDataUploadStreamPrivate *priv = self->priv;
+	GDataUploadStreamPrivate *priv = data->upload_stream->priv;
 
 	/* Tell libsoup to cancel the upload */
 	soup_session_cancel_message (priv->session, priv->message, SOUP_STATUS_CANCELLED);
 
 	/* Set the error and signal that the write operation has finished */
 	g_static_mutex_lock (&(priv->write_mutex));
-
-	g_static_mutex_lock (&(priv->response_mutex));
-	g_cancellable_set_error_if_cancelled (cancellable, &(priv->response_error));
-	g_static_mutex_unlock (&(priv->response_mutex));
-
+	*(data->cancelled) = TRUE;
 	priv->write_finished = TRUE;
 	g_cond_signal (priv->write_cond);
-
 	g_static_mutex_unlock (&(priv->write_mutex));
 }
 
@@ -398,28 +398,34 @@ gdata_upload_stream_write (GOutputStream *stream, const void *buffer, gsize coun
 	GDataUploadStreamPrivate *priv = GDATA_UPLOAD_STREAM (stream)->priv;
 	gsize length_written = count;
 	gulong cancelled_signal = 0;
+	gboolean cancelled = FALSE;
 
 	/* Listen for cancellation events */
-	if (cancellable != NULL)
-		cancelled_signal = g_cancellable_connect (cancellable, (GCallback) write_cancelled_cb, GDATA_UPLOAD_STREAM (stream), NULL);
+	if (cancellable != NULL) {
+		CancelledData data;
+
+		data.upload_stream = GDATA_UPLOAD_STREAM (stream);
+		data.cancelled = &cancelled;
+
+		cancelled_signal = g_cancellable_connect (cancellable, (GCallback) write_cancelled_cb, &data, NULL);
+	}
 
 	/* Check for an error and return if necessary */
-	g_static_mutex_lock (&(priv->response_mutex));
-	if (priv->response_error != NULL) {
-		g_propagate_error (error, priv->response_error);
-		priv->response_error = NULL;
-		g_static_mutex_unlock (&(priv->response_mutex));
+	g_static_mutex_lock (&(priv->write_mutex));
+
+	if (cancelled == TRUE) {
+		g_assert (cancellable != NULL && g_cancellable_set_error_if_cancelled (cancellable, error) == TRUE);
+		g_static_mutex_unlock (&(priv->write_mutex));
 
 		if (cancelled_signal != 0)
 			g_cancellable_disconnect (cancellable, cancelled_signal);
 
 		return -1;
 	}
-	g_static_mutex_unlock (&(priv->response_mutex));
 
 	/* Set write_finished so we know if the write operation has finished before we reach write_cond */
-	g_static_mutex_lock (&(priv->write_mutex));
 	priv->write_finished = FALSE;
+
 	g_static_mutex_unlock (&(priv->write_mutex));
 
 	/* Handle the more common case of the network thread already having been created first */
@@ -461,7 +467,7 @@ gdata_upload_stream_write (GOutputStream *stream, const void *buffer, gsize coun
 write:
 	/* Wait for it to be written */
 	g_static_mutex_lock (&(priv->write_mutex));
-	if (priv->write_finished == FALSE)
+	if (priv->write_finished == FALSE && cancelled == FALSE)
 		g_cond_wait (priv->write_cond, g_static_mutex_get_mutex (&(priv->write_mutex)));
 	g_static_mutex_unlock (&(priv->write_mutex));
 
@@ -472,6 +478,9 @@ write:
 		g_propagate_error (error, priv->response_error);
 		priv->response_error = NULL;
 		length_written = -1;
+	} else if (cancelled == TRUE) {
+		g_assert (cancellable != NULL && g_cancellable_set_error_if_cancelled (cancellable, error) == TRUE);
+		length_written = -1;
 	}
 
 	g_static_mutex_unlock (&(priv->response_mutex));
@@ -484,11 +493,6 @@ write:
 	return length_written;
 }
 
-typedef struct {
-	GDataUploadStream *upload_stream;
-	gboolean *cancelled;
-} CancelledData;
-
 static void
 close_cancelled_cb (GCancellable *cancellable, CancelledData *data)
 {



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