From: Timo Sirainen Date: Wed, 4 Feb 2009 22:50:05 +0000 (-0500) Subject: istream-tee: Minor cleanups, assert and a potential fix. X-Git-Tag: 1.2.beta1~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f8512649cd4db427a8dc5dc8f45c8e379ffd4d76;p=thirdparty%2Fdovecot%2Fcore.git istream-tee: Minor cleanups, assert and a potential fix. --HG-- branch : HEAD --- diff --git a/src/lib/istream-tee.c b/src/lib/istream-tee.c index a5ed2b4bf5..1a4090550b 100644 --- a/src/lib/istream-tee.c +++ b/src/lib/istream-tee.c @@ -112,12 +112,20 @@ static ssize_t i_stream_tee_read(struct istream_private *stream) uoff_t last_high_offset; ssize_t ret; + if (stream->buffer == NULL) { + /* initial read */ + tee_streams_update_buffer(tstream->tee); + } data = i_stream_get_data(input, &size); + /* last_high_offset contains how far we have read this child tee stream + so far. input->v_offset + size contains how much is available in + the parent stream without having to read more. */ last_high_offset = stream->istream.v_offset + - (tstream->istream.pos - tstream->istream.skip); + (stream->pos - stream->skip); i_assert(last_high_offset <= input->v_offset + size); if (last_high_offset == input->v_offset + size) { + /* we've read everything, need to read more */ tee_streams_skip(tstream->tee); ret = i_stream_read(input); if (ret <= 0) { @@ -133,9 +141,9 @@ static ssize_t i_stream_tee_read(struct istream_private *stream) } tee_streams_update_buffer(tstream->tee); data = i_stream_get_data(input, &size); - } else if (stream->buffer == NULL) { - tee_streams_update_buffer(tstream->tee); } else { + /* there's still some data available from parent */ + i_assert(stream->pos < size); stream->buffer = data; }