[evolution-data-server] Improve error handling in CamelStreamBuffer::read().
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Improve error handling in CamelStreamBuffer::read().
- Date: Mon, 12 Jul 2010 11:22:28 +0000 (UTC)
commit e2ea5f1b668dcd88e581419b01d2d4d265460ddd
Author: Matthew Barnes <mbarnes redhat com>
Date: Mon Jul 12 07:05:48 2010 -0400
Improve error handling in CamelStreamBuffer::read().
If we managed to successfully read some data before camel_stream_read()
failed, discard the GError and return the number of bytes successfully
read. If camel_stream_read() failed immediately, propagate the GError
and return -1.
camel/camel-stream-buffer.c | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/camel/camel-stream-buffer.c b/camel/camel-stream-buffer.c
index e63513e..c33ab03 100644
--- a/camel/camel-stream-buffer.c
+++ b/camel/camel-stream-buffer.c
@@ -148,6 +148,7 @@ stream_buffer_read (CamelStream *stream,
gssize bytes_read = 1;
gssize bytes_left;
gchar *bptr = buffer;
+ GError *local_error = NULL;
priv = CAMEL_STREAM_BUFFER_GET_PRIVATE (stream);
@@ -167,7 +168,7 @@ stream_buffer_read (CamelStream *stream,
/* if we are reading a lot, then read directly to the destination buffer */
if (n >= priv->size/3) {
bytes_read = camel_stream_read (
- priv->stream, bptr, n, error);
+ priv->stream, bptr, n, &local_error);
if (bytes_read>0) {
n -= bytes_read;
bptr += bytes_read;
@@ -175,7 +176,7 @@ stream_buffer_read (CamelStream *stream,
} else {
bytes_read = camel_stream_read (
priv->stream, (gchar *)
- priv->buf, priv->size, error);
+ priv->buf, priv->size, &local_error);
if (bytes_read>0) {
gsize bytes_used = bytes_read > n ? n : bytes_read;
priv->ptr = priv->buf;
@@ -194,6 +195,18 @@ stream_buffer_read (CamelStream *stream,
}
}
+ /* If camel_stream_read() failed but we managed to read some data
+ * before the failure, discard the error and return the number of
+ * bytes read. If we didn't read any data, propagate the error. */
+ if (local_error != NULL) {
+ if (bptr > buffer)
+ g_clear_error (&local_error);
+ else {
+ g_propagate_error (error, local_error);
+ return -1;
+ }
+ }
+
return (gssize)(bptr - buffer);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]