changeset 20244:fd39559c4533

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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 01 Jun 2016 18:09:48 +0300
parents 789d0e8c3b6c
children 57078d325d01
files src/lib/istream.c src/lib/istream.h
diffstat 2 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/istream.c	Wed Jun 01 18:03:58 2016 +0300
+++ b/src/lib/istream.c	Wed Jun 01 18:09:48 2016 +0300
@@ -119,7 +119,14 @@
 
 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)
--- a/src/lib/istream.h	Wed Jun 01 18:03:58 2016 +0300
+++ b/src/lib/istream.h	Wed Jun 01 18:09:48 2016 +0300
@@ -94,9 +94,13 @@
    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. */