[vte/vte-0-34] [stream] Remove write_contents



commit 73e10d9bcf414696258dbf10245a111985311b9a
Author: Behdad Esfahbod <behdad behdad org>
Date:   Sun Sep 29 19:54:39 2013 -0400

    [stream] Remove write_contents
    
    The ring will now read the stream contents and write it out itself.
    Makes stream implementation(s) easier.

 src/ring.c           |   34 +++++++++++++++++++++++++++-------
 src/vtestream-base.h |   13 -------------
 src/vtestream-file.h |   38 --------------------------------------
 src/vtestream.h      |    4 ----
 4 files changed, 27 insertions(+), 62 deletions(-)
---
diff --git a/src/ring.c b/src/ring.c
index 9345164..aa4e364 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -658,15 +658,35 @@ _vte_ring_write_contents (VteRing *ring,
 
        _vte_debug_print(VTE_DEBUG_RING, "Writing contents to GOutputStream.\n");
 
-       if (ring->start < ring->writable) {
+       if (ring->start < ring->writable)
+       {
                VteRowRecord record;
-               /* XXX what to do in case of error? */
-               if (_vte_ring_read_row_record (ring, &record, ring->start)) {
-                       if (!_vte_stream_write_contents (ring->text_stream, stream,
-                                                        record.text_start_offset,
-                                                        cancellable, error))
-                               return FALSE;
+
+               if (_vte_ring_read_row_record (ring, &record, ring->start))
+               {
+                       gsize start_offset = record.text_start_offset;
+                       gsize end_offset = _vte_stream_head (ring->text_stream, 0);
+                       char buf[4096];
+                       while (start_offset < end_offset)
+                       {
+                               gsize bytes_written, len;
+
+                               len = MIN (G_N_ELEMENTS (buf), end_offset - start_offset);
+
+                               if (!_vte_stream_read (ring->text_stream, start_offset,
+                                                      buf, len))
+                                       return FALSE;
+
+                               if (!g_output_stream_write_all (stream, buf, len,
+                                                               &bytes_written, cancellable,
+                                                               error))
+                                       return FALSE;
+
+                               start_offset += len;
+                       }
                }
+               else
+                       return FALSE;
        }
 
        for (i = ring->writable; i < ring->end; i++) {
diff --git a/src/vtestream-base.h b/src/vtestream-base.h
index dee5ff6..5b77e4d 100644
--- a/src/vtestream-base.h
+++ b/src/vtestream-base.h
@@ -38,9 +38,6 @@ typedef struct _VteStreamClass {
        void (*truncate) (VteStream *stream, gsize offset);
        void (*new_page) (VteStream *stream);
        gsize (*head) (VteStream *stream, guint index);
-       gboolean (*write_contents) (VteStream *stream, GOutputStream *output,
-                                   gsize start_offset,
-                                   GCancellable *cancellable, GError **error);
 } VteStreamClass;
 
 static GType _vte_stream_get_type (void);
@@ -96,13 +93,3 @@ _vte_stream_head (VteStream *stream, guint index)
 
        return VTE_STREAM_GET_CLASS (stream)->head (stream, index);
 }
-
-gboolean
-_vte_stream_write_contents (VteStream *stream, GOutputStream *output,
-                           gsize start_offset,
-                           GCancellable *cancellable, GError **error)
-{
-       return VTE_STREAM_GET_CLASS (stream)->write_contents (stream, output,
-                                                             start_offset,
-                                                             cancellable, error);
-}
diff --git a/src/vtestream-file.h b/src/vtestream-file.h
index c47b0b6..0badb31 100644
--- a/src/vtestream-file.h
+++ b/src/vtestream-file.h
@@ -123,22 +123,6 @@ _xpwrite (int fd, const char *data, gsize len, gsize offset)
        }
 }
 
-static gboolean
-_xwrite_contents (gint fd, GOutputStream *output, GCancellable *cancellable, GError **error)
-{
-       gboolean ret;
-       GInputStream *input;
-
-       if (G_UNLIKELY (!fd))
-               return TRUE;
-
-       input = g_unix_input_stream_new (fd, FALSE);
-       ret = -1 != g_output_stream_splice (output, input, G_OUTPUT_STREAM_SPLICE_NONE, cancellable, error);
-       g_object_unref (input);
-
-       return ret;
-}
-
 
 /*
  * VteFileStream: A POSIX file-based stream
@@ -288,27 +272,6 @@ _vte_file_stream_head (VteStream *astream, guint index)
        return index == 0 ? stream->head : stream->offset[index - 1];
 }
 
-static gboolean
-_vte_file_stream_write_contents (VteStream *astream, GOutputStream *output,
-                                gsize offset,
-                                GCancellable *cancellable, GError **error)
-{
-       VteFileStream *stream = (VteFileStream *) astream;
-
-       if (G_UNLIKELY (offset < stream->offset[1]))
-               return FALSE;
-
-       if (offset < stream->offset[0]) {
-               lseek (stream->fd[1], offset - stream->offset[1], SEEK_SET);
-               if (!_xwrite_contents (stream->fd[1], output, cancellable, error))
-                       return FALSE;
-               offset = stream->offset[0];
-       }
-
-       lseek (stream->fd[0], offset - stream->offset[0], SEEK_SET);
-       return _xwrite_contents (stream->fd[0], output, cancellable, error);
-}
-
 static void
 _vte_file_stream_class_init (VteFileStreamClass *klass)
 {
@@ -322,5 +285,4 @@ _vte_file_stream_class_init (VteFileStreamClass *klass)
        klass->truncate = _vte_file_stream_truncate;
        klass->new_page = _vte_file_stream_new_page;
        klass->head = _vte_file_stream_head;
-       klass->write_contents = _vte_file_stream_write_contents;
 }
diff --git a/src/vtestream.h b/src/vtestream.h
index 7b36e1f..e968d42 100644
--- a/src/vtestream.h
+++ b/src/vtestream.h
@@ -39,10 +39,6 @@ void _vte_stream_new_page (VteStream *stream);
  * - index == 2 -> start of previous page (ie. last offset available in stream)
  */
 gsize _vte_stream_head (VteStream *stream, guint index);
-gboolean _vte_stream_write_contents (VteStream *stream, GOutputStream *output,
-                                    gsize start_offset,
-                                    GCancellable *cancellable, GError **error);
-
 
 /* Various streams */
 


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