]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
istream-tee: Minor cleanups, assert and a potential fix.
authorTimo Sirainen <tss@iki.fi>
Wed, 4 Feb 2009 22:50:05 +0000 (17:50 -0500)
committerTimo Sirainen <tss@iki.fi>
Wed, 4 Feb 2009 22:50:05 +0000 (17:50 -0500)
--HG--
branch : HEAD

src/lib/istream-tee.c

index a5ed2b4bf509281b9bb3d7ae38a55f2f22f8e48e..1a4090550b47f0d8933cbbf2026cc8c71e54d69a 100644 (file)
@@ -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;
        }