changeset 20860:668274a98b48

lib: Added ostream.blocking boolean Similar to istream.blocking.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 16 May 2016 19:33:40 +0300
parents d2d89eae7828
children ddae63d7bc9c
files src/lib/ostream-buffer.c src/lib/ostream-file.c src/lib/ostream-null.c src/lib/ostream.c src/lib/ostream.h
diffstat 5 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/ostream-buffer.c	Sat Apr 30 14:10:59 2016 +0200
+++ b/src/lib/ostream-buffer.c	Mon May 16 19:33:40 2016 +0300
@@ -59,6 +59,7 @@
 	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;
--- a/src/lib/ostream-file.c	Sat Apr 30 14:10:59 2016 +0200
+++ b/src/lib/ostream-file.c	Mon May 16 19:33:40 2016 +0300
@@ -1023,6 +1023,7 @@
 	fstream_init_file(fstream);
 	fstream->real_offset = offset;
 	fstream->buffer_offset = offset;
+	ostream->blocking = fstream->file;
 	ostream->offset = offset;
 	return ostream;
 }
--- a/src/lib/ostream-null.c	Sat Apr 30 14:10:59 2016 +0200
+++ b/src/lib/ostream-null.c	Mon May 16 19:33:40 2016 +0300
@@ -23,6 +23,7 @@
 	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);
--- a/src/lib/ostream.c	Sat Apr 30 14:10:59 2016 +0200
+++ b/src/lib/ostream.c	Mon May 16 19:33:40 2016 +0300
@@ -262,6 +262,7 @@
 			stream->last_failed_errno = stream->stream_errno;
 			errno = stream->stream_errno;
 		} else {
+			i_assert(!stream->blocking);
 			stream->overflow = TRUE;
 		}
 	}
@@ -570,6 +571,7 @@
 	_stream->fd = fd;
 	_stream->ostream.real_stream = _stream;
 	if (parent != NULL) {
+		_stream->ostream.blocking = parent->blocking;
 		_stream->parent = parent;
 		o_stream_ref(parent);
 
@@ -622,6 +624,7 @@
 	struct ostream *output;
 
 	stream = i_new(struct ostream_private, 1);
+	stream->ostream.blocking = TRUE;
 	stream->ostream.closed = TRUE;
 	stream->ostream.stream_errno = stream_errno;
 	stream->ostream.last_failed_errno = stream_errno;
--- a/src/lib/ostream.h	Sat Apr 30 14:10:59 2016 +0200
+++ b/src/lib/ostream.h	Mon May 16 19:33:40 2016 +0300
@@ -16,6 +16,8 @@
 	   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;