]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add i_stream_get_root_io() and use it to deduplicate code
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 8 Feb 2018 00:22:18 +0000 (02:22 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 8 Feb 2018 10:55:49 +0000 (12:55 +0200)
src/lib/istream-private.h
src/lib/istream.c

index 641e7a0e2c640fcccd60b727a459e16a2ab71ee4..a88653133d94af00d5ab3d2745ad6c784ccbcaf8 100644 (file)
@@ -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);
 
index 5befd9ebdb52e9fcca8f1b9cf1c5427fb6dbf884..4310b15743feb0c8f60c4bec9ecb42b69b01f2a7 100644 (file)
@@ -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;