[gvfs] afp: don't send commands which have been cancelled



commit 8f45840d0ef3299538b626280bbfbc6aa09026d3
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Mon Jul 18 00:00:41 2011 +0200

    afp: don't send commands which have been cancelled

 daemon/gvfsafpconnection.c |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/daemon/gvfsafpconnection.c b/daemon/gvfsafpconnection.c
index 4189e4e..65d6691 100644
--- a/daemon/gvfsafpconnection.c
+++ b/daemon/gvfsafpconnection.c
@@ -794,8 +794,11 @@ write_command_cb (GObject *object, GAsyncResult *res, gpointer user_data)
   bytes_written = g_output_stream_write_finish (output, res, &err);
   if (bytes_written == -1)
   {
-    g_simple_async_result_set_from_error (req_data->simple, err);
-    g_simple_async_result_complete (req_data->simple);
+    if (req_data->simple)
+    {
+      g_simple_async_result_set_from_error (req_data->simple, err);
+      g_simple_async_result_complete (req_data->simple);
+    }
 
     free_request_data (req_data);
     g_error_free (err);
@@ -813,7 +816,6 @@ write_command_cb (GObject *object, GAsyncResult *res, gpointer user_data)
     
     data = g_vfs_afp_command_get_data (req_data->command);
     
-    
     g_output_stream_write_async (output, data + priv->bytes_written,
                                  size - priv->bytes_written, 0, NULL,
                                  write_command_cb, afp_conn);
@@ -847,8 +849,11 @@ write_dsi_header_cb (GObject *object, GAsyncResult *res, gpointer user_data)
   bytes_written = g_output_stream_write_finish (output, res, &err);
   if (bytes_written == -1)
   {
-    g_simple_async_result_set_from_error (req_data->simple, err);
-    g_simple_async_result_complete (req_data->simple);
+    if (req_data->simple)
+    {
+      g_simple_async_result_set_from_error (req_data->simple, err);
+      g_simple_async_result_complete (req_data->simple);
+    }
 
     remove_first (priv->request_queue);
     g_error_free (err);
@@ -889,7 +894,23 @@ send_request (GVfsAfpConnection *afp_connection)
   guint32 writeOffset;
   guint8 dsi_command;
 
-  req_data = g_queue_peek_head (priv->request_queue);
+  while ((req_data = g_queue_peek_head (priv->request_queue)))
+  {
+    if (req_data->cancellable && g_cancellable_is_cancelled (req_data->cancellable))
+    {
+      if (req_data->simple)
+      {
+        GError *err = NULL;
+
+        g_cancellable_set_error_if_cancelled (req_data->cancellable, &err);
+        g_simple_async_result_take_error (req_data->simple, err);
+        g_simple_async_result_complete (req_data->simple);
+      }
+      remove_first (priv->request_queue);
+    }
+    else
+      break;
+  }
 
   if (!req_data) {
     priv->send_loop_running = FALSE;



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