dovecot-2.2: istream-chain: Unreference also the last stream whe...

dovecot at dovecot.org dovecot at dovecot.org
Wed Aug 29 20:00:22 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/03e0b100243d
changeset: 14975:03e0b100243d
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Aug 29 19:59:42 2012 +0300
description:
istream-chain: Unreference also the last stream when it reaches EOF.

diffstat:

 src/lib/istream-chain.c |  41 ++++++++++++++++-------------------------
 1 files changed, 16 insertions(+), 25 deletions(-)

diffs (90 lines):

diff -r bfd4e6e08f72 -r 03e0b100243d src/lib/istream-chain.c
--- a/src/lib/istream-chain.c	Wed Aug 29 19:07:47 2012 +0300
+++ b/src/lib/istream-chain.c	Wed Aug 29 19:59:42 2012 +0300
@@ -10,8 +10,8 @@
 struct istream_chain_link {
 	struct istream_chain_link *prev, *next;
 
-	uoff_t start_offset;
 	struct istream *stream;
+	bool eof;
 };
 
 struct istream_chain {
@@ -39,11 +39,10 @@
 
 	link = i_new(struct istream_chain_link, 1);
 	link->stream = stream;
+	link->eof = stream == NULL;
 
-	if (stream != NULL) {
+	if (stream != NULL)
 		i_stream_ref(stream);	
-		link->start_offset = stream->v_offset;
-	}
 
 	if (chain->head == NULL && stream != NULL) {
 		if (chain->stream->istream.max_buffer_size == 0) {
@@ -113,9 +112,10 @@
 	DLLIST2_REMOVE(&cstream->chain.head, &cstream->chain.tail, link);
 	i_free(link);
 
+	/* a) we have more streams, b) we have EOF, c) we need to wait
+	   for more streams */
 	link = cstream->chain.head;
-	i_assert(link == NULL || link->stream != NULL);
-	if (link != NULL)
+	if (link != NULL && link->stream != NULL)
 		i_stream_seek(link->stream, 0);
 
 	/* we already verified that the data size is less than the
@@ -142,9 +142,8 @@
 	const unsigned char *data;
 	size_t size, pos, cur_pos, bytes_skipped;
 	ssize_t ret;
-	bool last_stream;
 
-	if (link != NULL && link->stream == NULL) {
+	if (link != NULL && link->eof) {
 		stream->istream.eof = TRUE;
 		return -1;
 	}
@@ -183,29 +182,21 @@
 		/* need to read more */
 		i_assert(cur_pos == pos);
 		ret = i_stream_read(link->stream);
-		if (ret == -2 || ret == 0) {
+		if (ret == -2 || ret == 0)
 			return ret;
-		}
 
-		if (ret == -1 && link->stream->stream_errno != 0) {
-			stream->istream.stream_errno =
-				link->stream->stream_errno;
-			return -1;
-		}
-
-		/* we either read something or we're at EOF */
-		last_stream = link->next != NULL && link->next->stream == NULL;
-		if (ret == -1 && !last_stream) {
-			if (stream->pos >= stream->max_buffer_size)
-				return -2;
-
+		if (ret == -1) {
+			if (link->stream->stream_errno != 0) {
+				stream->istream.stream_errno =
+					link->stream->stream_errno;
+				return -1;
+			}
+			/* EOF of this stream, go to next stream */
 			i_stream_chain_read_next(cstream);
 			cstream->prev_skip = stream->skip;
 			return i_stream_chain_read(stream);
 		}
-
-		stream->istream.eof = link->stream->eof && last_stream;
-		i_assert(ret != -1 || stream->istream.eof);
+		/* we read something */
 		data = i_stream_get_data(link->stream, &pos);
 	}
 


More information about the dovecot-cvs mailing list