From 8b2cf1c1bd8ddcea0525b62fd35ba76e136828a1 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 16 May 2016 19:33:40 +0300 Subject: [PATCH] lib: Added ostream.blocking boolean Similar to istream.blocking. --- src/lib/ostream-buffer.c | 1 + src/lib/ostream-file.c | 1 + src/lib/ostream-null.c | 1 + src/lib/ostream.c | 3 +++ src/lib/ostream.h | 2 ++ 5 files changed, 8 insertions(+) diff --git a/src/lib/ostream-buffer.c b/src/lib/ostream-buffer.c index 3507ec4408..75baa09cd4 100644 --- a/src/lib/ostream-buffer.c +++ b/src/lib/ostream-buffer.c @@ -59,6 +59,7 @@ struct ostream *o_stream_create_buffer(buffer_t *buf) struct ostream *output; bstream = i_new(struct buffer_ostream, 1); + bstream->ostream.ostream.blocking = TRUE; bstream->ostream.max_buffer_size = (size_t)-1; bstream->ostream.seek = o_stream_buffer_seek; bstream->ostream.sendv = o_stream_buffer_sendv; diff --git a/src/lib/ostream-file.c b/src/lib/ostream-file.c index f3593e4037..b7449e7b5f 100644 --- a/src/lib/ostream-file.c +++ b/src/lib/ostream-file.c @@ -1023,6 +1023,7 @@ o_stream_create_fd_file(int fd, uoff_t offset, bool autoclose_fd) fstream_init_file(fstream); fstream->real_offset = offset; fstream->buffer_offset = offset; + ostream->blocking = fstream->file; ostream->offset = offset; return ostream; } diff --git a/src/lib/ostream-null.c b/src/lib/ostream-null.c index 7c00284718..9f9d0fe03e 100644 --- a/src/lib/ostream-null.c +++ b/src/lib/ostream-null.c @@ -23,6 +23,7 @@ struct ostream *o_stream_create_null(void) struct ostream *output; stream = i_new(struct ostream_private, 1); + stream->ostream.blocking = TRUE; stream->sendv = o_stream_null_sendv; output = o_stream_create(stream, NULL, -1); diff --git a/src/lib/ostream.c b/src/lib/ostream.c index 3733d8a45d..b23025b906 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -252,6 +252,7 @@ o_stream_sendv_int(struct ostream *stream, const struct const_iovec *iov, i_assert(stream->stream_errno != 0); errno = stream->stream_errno; } else { + i_assert(!stream->blocking); stream->overflow = TRUE; *overflow_r = TRUE; } @@ -578,6 +579,7 @@ o_stream_create(struct ostream_private *_stream, struct ostream *parent, int fd) _stream->fd = fd; _stream->ostream.real_stream = _stream; if (parent != NULL) { + _stream->ostream.blocking = parent->blocking; _stream->parent = parent; o_stream_ref(parent); @@ -630,6 +632,7 @@ struct ostream *o_stream_create_error(int stream_errno) struct ostream *output; stream = i_new(struct ostream_private, 1); + stream->ostream.blocking = TRUE; stream->ostream.closed = TRUE; stream->ostream.stream_errno = stream_errno; diff --git a/src/lib/ostream.h b/src/lib/ostream.h index bb10c82c6c..37aae551c5 100644 --- a/src/lib/ostream.h +++ b/src/lib/ostream.h @@ -14,6 +14,8 @@ struct ostream { functions was neither sent nor buffered. It's never unset inside ostream code. */ unsigned int overflow:1; + /* o_stream_send() writes all the data or returns failure */ + unsigned int blocking:1; unsigned int closed:1; struct ostream_private *real_stream;