[gtksourceview/wip/loader-saver] FileLoader: loop around g_output_stream_write()



commit 4c7f6cbebf3e9ae87b3acf644e597c7313ae8bb0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Apr 3 21:24:28 2014 +0200

    FileLoader: loop around g_output_stream_write()

 gtksourceview/gtksourcefileloader.c |   45 ++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 19 deletions(-)
---
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index 7e9062a..771cb4c 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -377,30 +377,37 @@ write_complete (GtkSourceFileLoader *loader)
 static void
 write_file_chunk (GtkSourceFileLoader *loader)
 {
-       gssize bytes_written;
-       GError *error = NULL;
-
-       /* We use sync methods on the buffer stream since it is in memory. Using
-        * async would be racy and we can end up with invalidated iters.
-        */
-       bytes_written = g_output_stream_write (loader->priv->output_stream,
-                                              loader->priv->chunk_buffer,
-                                              loader->priv->chunk_bytes_read,
-                                              g_task_get_cancellable (loader->priv->task),
-                                              &error);
-
-       DEBUG ({
-              g_print ("Written: %" G_GSSIZE_FORMAT "\n", bytes_written);
-       });
+       gssize chunk_bytes_written = 0;
 
-       if (error != NULL)
+       while (chunk_bytes_written < loader->priv->chunk_bytes_read)
        {
+               gssize bytes_written;
+               GError *error = NULL;
+
+               /* We use sync methods on the buffer stream since it is in memory. Using
+                * async would be racy and we can end up with invalidated iters.
+                */
+               bytes_written = g_output_stream_write (loader->priv->output_stream,
+                                                      loader->priv->chunk_buffer + chunk_bytes_written,
+                                                      loader->priv->chunk_bytes_read - chunk_bytes_written,
+                                                      g_task_get_cancellable (loader->priv->task),
+                                                      &error);
+
                DEBUG ({
-                      g_print ("Write error: %s\n", error->message);
+                      g_print ("Written: %" G_GSSIZE_FORMAT "\n", bytes_written);
                });
 
-               g_task_return_error (loader->priv->task, error);
-               return;
+               if (error != NULL)
+               {
+                       DEBUG ({
+                              g_print ("Write error: %s\n", error->message);
+                       });
+
+                       g_task_return_error (loader->priv->task, error);
+                       return;
+               }
+
+               chunk_bytes_written += bytes_written;
        }
 
        /* FIXME: note that calling the progress callback blocks the read...


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