Mercurial > dovecot > core-2.2
changeset 22839:e94be670bd18
lib: Add i_stream_get_root_io() and use it to deduplicate code
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 08 Feb 2018 02:22:18 +0200 |
parents | bed6a1eb53f7 |
children | e88a611656a8 |
files | src/lib/istream-private.h src/lib/istream.c |
diffstat | 2 files changed, 13 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/istream-private.h Thu Feb 08 10:52:57 2018 +0200 +++ b/src/lib/istream-private.h Thu Feb 08 02:22:18 2018 +0200 @@ -72,6 +72,7 @@ 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);
--- a/src/lib/istream.c Thu Feb 08 10:52:57 2018 +0200 +++ b/src/lib/istream.c Thu Feb 08 02:22:18 2018 +0200 @@ -682,15 +682,21 @@ return TRUE; } +struct istream *i_stream_get_root_io(struct istream *stream) +{ + 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; - 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); if (stream->real_stream->io != NULL) io_set_pending(stream->real_stream->io); } @@ -706,10 +712,7 @@ 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_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;