[vte] [ring/stream] Handle stream failure (out of space)
- From: Behdad Esfahbod <behdad src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vte] [ring/stream] Handle stream failure (out of space)
- Date: Wed, 16 Sep 2009 02:23:42 +0000 (UTC)
commit 5254710eb86008ab218f2ad0a61e631f3f6d6b39
Author: Behdad Esfahbod <behdad behdad org>
Date: Tue Sep 15 21:17:51 2009 -0400
[ring/stream] Handle stream failure (out of space)
src/ring.c | 19 ++++++++++++++-----
src/vtestream-base.h | 6 +++---
src/vtestream-file.h | 15 ++++++---------
src/vtestream.h | 3 +--
4 files changed, 24 insertions(+), 19 deletions(-)
---
diff --git a/src/ring.c b/src/ring.c
index 6f73572..c4a2376 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -179,12 +179,17 @@ _vte_ring_thaw_row (VteRing *ring, guint position, VteRowData *row, gboolean tru
attr_change.text_offset = 0;
- _vte_stream_read (ring->row_stream, position * sizeof (record), (char *) records, sizeof (records));
- if (records[1].text_offset < records[0].text_offset)
+ if (!_vte_stream_read (ring->row_stream, position * sizeof (records[0]), (char *) &records[0], sizeof (records[0])))
+ return;
+ if ((position + 1) * sizeof (VteRowRecord) < _vte_stream_head (ring->row_stream)) {
+ if (!_vte_stream_read (ring->row_stream, (position + 1) * sizeof (records[1]), (char *) &records[1], sizeof (records[1])))
+ return;
+ } else
records[1].text_offset = _vte_stream_head (ring->text_stream);
g_string_set_size (buffer, records[1].text_offset - records[0].text_offset);
- _vte_stream_read (ring->text_stream, records[0].text_offset, buffer->str, buffer->len);
+ if (!_vte_stream_read (ring->text_stream, records[0].text_offset, buffer->str, buffer->len))
+ return;
record = records[0];
@@ -201,7 +206,8 @@ _vte_ring_thaw_row (VteRing *ring, guint position, VteRowData *row, gboolean tru
attr = ring->last_attr.attr;
} else {
if (record.text_offset >= attr_change.text_offset) {
- _vte_stream_read (ring->attr_stream, record.attr_offset, (char *) &attr_change, sizeof (attr_change));
+ if (!_vte_stream_read (ring->attr_stream, record.attr_offset, (char *) &attr_change, sizeof (attr_change)))
+ return;
record.attr_offset += sizeof (attr_change);
}
attr = attr_change.attr;
@@ -233,7 +239,10 @@ _vte_ring_thaw_row (VteRing *ring, guint position, VteRowData *row, gboolean tru
if (truncate) {
if (records[0].text_offset < ring->last_attr.text_offset)
- _vte_stream_read (ring->attr_stream, records[0].attr_offset, (char *) &ring->last_attr, sizeof (ring->last_attr));
+ if (!_vte_stream_read (ring->attr_stream, records[0].attr_offset, (char *) &ring->last_attr, sizeof (ring->last_attr))) {
+ ring->last_attr.text_offset = 0;
+ ring->last_attr.attr.i = 0;
+ }
_vte_stream_truncate (ring->row_stream, position * sizeof (record));
_vte_stream_truncate (ring->attr_stream, records[0].attr_offset);
_vte_stream_truncate (ring->text_stream, records[0].text_offset);
diff --git a/src/vtestream-base.h b/src/vtestream-base.h
index b79179a..80c6c3e 100644
--- a/src/vtestream-base.h
+++ b/src/vtestream-base.h
@@ -33,7 +33,7 @@ typedef struct _VteStreamClass {
void (*reset) (VteStream *stream, gsize offset);
gsize (*append) (VteStream *stream, const char *data, gsize len);
- void (*read) (VteStream *stream, gsize offset, char *data, gsize len);
+ gboolean (*read) (VteStream *stream, gsize offset, char *data, gsize len);
void (*truncate) (VteStream *stream, gsize offset);
void (*new_page) (VteStream *stream);
gsize (*head) (VteStream *stream);
@@ -67,10 +67,10 @@ _vte_stream_append (VteStream *stream, const char *data, gsize len)
return VTE_STREAM_GET_CLASS (stream)->append (stream, data, len);
}
-void
+gboolean
_vte_stream_read (VteStream *stream, gsize offset, char *data, gsize len)
{
- VTE_STREAM_GET_CLASS (stream)->read (stream, offset, data, len);
+ return VTE_STREAM_GET_CLASS (stream)->read (stream, offset, data, len);
}
void
diff --git a/src/vtestream-file.h b/src/vtestream-file.h
index 36a9fc1..7693154 100644
--- a/src/vtestream-file.h
+++ b/src/vtestream-file.h
@@ -166,29 +166,26 @@ _vte_file_stream_append (VteStream *astream, const char *data, gsize len)
return stream->offset[0] + ret;
}
-static void
+static gboolean
_vte_file_stream_read (VteStream *astream, gsize offset, char *data, gsize len)
{
VteFileStream *stream = (VteFileStream *) astream;
gsize l;
- if (G_UNLIKELY (offset < stream->offset[1])) {
- l = MIN (len, stream->offset[1] - offset);
- memset (data, 0, l);
- offset += l; data += l; len -= l; if (!len) return;
- }
+ if (G_UNLIKELY (offset < stream->offset[1]))
+ return FALSE;
if (offset < stream->offset[0]) {
lseek (stream->fd[1], offset - stream->offset[1], SEEK_SET);
l = _xread (stream->fd[1], data, len);
- offset += l; data += l; len -= l; if (!len) return;
+ offset += l; data += l; len -= l; if (!len) return TRUE;
}
lseek (stream->fd[0], offset - stream->offset[0], SEEK_SET);
l = _xread (stream->fd[0], data, len);
- offset += l; data += l; len -= l; if (!len) return;
+ offset += l; data += l; len -= l; if (!len) return TRUE;
- memset (data, 0, len);
+ return FALSE;
}
static void
diff --git a/src/vtestream.h b/src/vtestream.h
index ec45fcc..56df5a0 100644
--- a/src/vtestream.h
+++ b/src/vtestream.h
@@ -29,7 +29,7 @@ typedef struct _VteStream VteStream;
void _vte_stream_reset (VteStream *stream, gsize offset);
gsize _vte_stream_append (VteStream *stream, const char *data, gsize len);
-void _vte_stream_read (VteStream *stream, gsize offset, char *data, gsize len);
+gboolean _vte_stream_read (VteStream *stream, gsize offset, char *data, gsize len);
void _vte_stream_truncate (VteStream *stream, gsize offset);
void _vte_stream_new_page (VteStream *stream);
gsize _vte_stream_head (VteStream *stream);
@@ -43,4 +43,3 @@ _vte_file_stream_new (void);
G_END_DECLS
#endif
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]