From: Timo Sirainen Date: Thu, 8 Feb 2018 00:22:18 +0000 (+0200) Subject: lib: Add i_stream_get_root_io() and use it to deduplicate code X-Git-Tag: 2.3.9~2344 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5a9bbcb13b2dd2cf9a825c7ed09fe7ee143b1275;p=thirdparty%2Fdovecot%2Fcore.git lib: Add i_stream_get_root_io() and use it to deduplicate code --- diff --git a/src/lib/istream-private.h b/src/lib/istream-private.h index 641e7a0e2c..a88653133d 100644 --- a/src/lib/istream-private.h +++ b/src/lib/istream-private.h @@ -106,6 +106,7 @@ i_stream_default_snapshot(struct istream_private *stream, struct istream_snapshot *prev_snapshot); void i_stream_snapshot_free(struct istream_snapshot **snapshot); +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 5befd9ebdb..4310b15743 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -906,15 +906,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); } @@ -939,10 +945,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; @@ -950,10 +953,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;