]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add i_stream_set_blocking()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 4 Oct 2017 17:13:49 +0000 (20:13 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Thu, 5 Oct 2017 08:20:49 +0000 (11:20 +0300)
src/lib/istream.c
src/lib/istream.h

index eb82c89934f82d9cb44f9aa4565ba0a70091ffff..442dd4eea6f10d17af40a4660e13c17f312dca5a 100644 (file)
@@ -4,6 +4,7 @@
 #include "ioloop.h"
 #include "array.h"
 #include "str.h"
+#include "fd-set-nonblock.h"
 #include "istream-private.h"
 
 static bool i_stream_is_buffer_invalid(const struct istream_private *stream);
@@ -153,6 +154,21 @@ void i_stream_set_persistent_buffers(struct istream *stream, bool set)
        } while (stream != NULL);
 }
 
+void i_stream_set_blocking(struct istream *stream, bool blocking)
+{
+       int prev_fd = -1;
+
+       do {
+               stream->blocking = blocking;
+               if (stream->real_stream->fd != -1 &&
+                   stream->real_stream->fd != prev_fd) {
+                       fd_set_nonblock(stream->real_stream->fd, !blocking);
+                       prev_fd = stream->real_stream->fd;
+               }
+               stream = stream->real_stream->parent;
+       } while (stream != NULL);
+}
+
 static void i_stream_update(struct istream_private *stream)
 {
        if (stream->parent == NULL)
index 762ac70faa304230f0d31d1f017342b7f6a8022e..d39ba04bdeb7c921073095be319aba94995b8f71 100644 (file)
@@ -130,6 +130,9 @@ void i_stream_set_return_partial_line(struct istream *stream, bool set);
    the memory usage is minimized by freeing the stream's buffers whenever they
    become empty. */
 void i_stream_set_persistent_buffers(struct istream *stream, bool set);
+/* Set the istream blocking or nonblocking, including its parent streams.
+   If any of the istreams have an fd, its O_NONBLOCK flag is changed. */
+void i_stream_set_blocking(struct istream *stream, bool blocking);
 
 /* Returns number of bytes read if read was ok, -1 if EOF or error, -2 if the
    input buffer is full. */