]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: i_stream_get_max_buffer_size() checks also parents' max sizes
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 1 Jun 2016 15:09:48 +0000 (18:09 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 1 Jun 2016 15:09:48 +0000 (18:09 +0300)
This fixes i_stream_get_max_buffer_size() to work correctly with
istream-chain.

src/lib/istream.c
src/lib/istream.h

index 9b66f79af82fe37edd15919a72073a3838754500..83a4892d6285da7a1c25c46059613f19d8767eb2 100644 (file)
@@ -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)
index 4db812005d9676065c248a24de009b0d1a5320b1..34f95715d1dc6f57fdd22f25a5170b9d59180523 100644 (file)
@@ -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. */