From: Timo Sirainen Date: Wed, 4 Oct 2017 17:13:49 +0000 (+0300) Subject: lib: Add i_stream_set_blocking() X-Git-Tag: 2.3.0.rc1~916 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b6924ad1943fe5c6917fc49f675d8f316b0d939;p=thirdparty%2Fdovecot%2Fcore.git lib: Add i_stream_set_blocking() --- diff --git a/src/lib/istream.c b/src/lib/istream.c index eb82c89934..442dd4eea6 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -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) diff --git a/src/lib/istream.h b/src/lib/istream.h index 762ac70faa..d39ba04bde 100644 --- a/src/lib/istream.h +++ b/src/lib/istream.h @@ -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. */