From: Timo Sirainen Date: Wed, 1 Jun 2016 15:09:48 +0000 (+0300) Subject: lib: i_stream_get_max_buffer_size() checks also parents' max sizes X-Git-Tag: 2.3.0.rc1~3592 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=71aed7ba87b5fd5e96e97a22d89ac025b883d60a;p=thirdparty%2Fdovecot%2Fcore.git lib: i_stream_get_max_buffer_size() checks also parents' max sizes This fixes i_stream_get_max_buffer_size() to work correctly with istream-chain. --- diff --git a/src/lib/istream.c b/src/lib/istream.c index 9b66f79af8..83a4892d62 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -123,7 +123,14 @@ void i_stream_set_max_buffer_size(struct istream *stream, size_t max_size) size_t i_stream_get_max_buffer_size(struct istream *stream) { - return stream->real_stream->max_buffer_size; + size_t max_size = 0; + + do { + if (max_size < stream->real_stream->max_buffer_size) + max_size = stream->real_stream->max_buffer_size; + stream = stream->real_stream->parent; + } while (stream != NULL); + return max_size; } void i_stream_set_return_partial_line(struct istream *stream, bool set) diff --git a/src/lib/istream.h b/src/lib/istream.h index 4db812005d..34f95715d1 100644 --- a/src/lib/istream.h +++ b/src/lib/istream.h @@ -94,9 +94,13 @@ void i_stream_sync(struct istream *stream); unless it's called before reading anything. */ void i_stream_set_init_buffer_size(struct istream *stream, size_t size); /* Change the maximum size for stream's input buffer to grow. Useful only - for buffered streams (currently only file). */ + for buffered streams (currently only file). This changes also all the + parent streams' max buffer size. */ void i_stream_set_max_buffer_size(struct istream *stream, size_t max_size); -/* Returns the current max. buffer size. */ +/* Returns the current max. buffer size for the stream. This function also + goesthrough all of the parent streams and returns the highest seen max + buffer size. This is needed because some streams (e.g. istream-chain) change + their max buffer size dynamically. */ size_t i_stream_get_max_buffer_size(struct istream *stream); /* Enable/disable i_stream[_read]_next_line() returning the last line if it doesn't end with LF. */