diff --git a/src/lib/istream-private.h b/src/lib/istream-private.h index c6b69d5754..ff6003a987 100644 --- a/src/lib/istream-private.h +++ b/src/lib/istream-private.h @@ -72,6 +72,7 @@ ssize_t i_stream_read_copy_from_parent(struct istream *istream); void i_stream_default_seek_nonseekable(struct istream_private *stream, uoff_t v_offset, bool mark); +struct istream *i_stream_get_root_io(struct istream *stream); void i_stream_set_io(struct istream *stream, struct io *io); void i_stream_unset_io(struct istream *stream, struct io *io); diff --git a/src/lib/istream.c b/src/lib/istream.c index ab957a3000..3937118e17 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -682,15 +682,21 @@ bool i_stream_add_data(struct istream *_stream, const unsigned char *data, return TRUE; } -void i_stream_set_input_pending(struct istream *stream, bool pending) +struct istream *i_stream_get_root_io(struct istream *stream) { - if (!pending) - return; - while (stream->real_stream->parent != NULL) { i_assert(stream->real_stream->io == NULL); stream = stream->real_stream->parent; } + return stream; +} + +void i_stream_set_input_pending(struct istream *stream, bool pending) +{ + if (!pending) + return; + + stream = i_stream_get_root_io(stream); if (stream->real_stream->io != NULL) io_set_pending(stream->real_stream->io); } @@ -706,10 +712,7 @@ void i_stream_switch_ioloop(struct istream *stream) void i_stream_set_io(struct istream *stream, struct io *io) { - while (stream->real_stream->parent != NULL) { - i_assert(stream->real_stream->io == NULL); - stream = stream->real_stream->parent; - } + stream = i_stream_get_root_io(stream); i_assert(stream->real_stream->io == NULL); stream->real_stream->io = io; @@ -717,10 +720,7 @@ void i_stream_set_io(struct istream *stream, struct io *io) void i_stream_unset_io(struct istream *stream, struct io *io) { - while (stream->real_stream->parent != NULL) { - i_assert(stream->real_stream->io == NULL); - stream = stream->real_stream->parent; - } + stream = i_stream_get_root_io(stream); i_assert(stream->real_stream->io == io); stream->real_stream->io = NULL;