]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add o_stream_flush_parent()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 31 Oct 2017 13:00:51 +0000 (15:00 +0200)
committerTimo Sirainen <tss@dovecot.fi>
Wed, 1 Nov 2017 00:22:19 +0000 (02:22 +0200)
src/lib/ostream-private.h
src/lib/ostream.c

index d9d4fa5f7cd01f6cf7d22a2e401480eb33e39636..609ba80b4d5984ebaa2efcd43ffea4c35f45748c 100644 (file)
@@ -58,4 +58,10 @@ void o_stream_copy_error_from_parent(struct ostream_private *_stream);
    Returns 1 if more data can be safely added, 0 if not, -1 if error. */
 int o_stream_flush_parent_if_needed(struct ostream_private *_stream);
 
+/* Call this in flush() handler to flush the parent stream. It will call
+   either o_stream_flush() or o_stream_finish() depending on whether this
+   stream is already finished. If the parent fails, its error will be also
+   copied to this stream. */
+int o_stream_flush_parent(struct ostream_private *_stream);
+
 #endif
index 04effd05ec2be470eb7803a8a5d8bf3994975c06..2f6379a5cdb67f8d35f27af647d2134ea7a39508 100644 (file)
@@ -544,6 +544,21 @@ int o_stream_flush_parent_if_needed(struct ostream_private *_stream)
        return 1;
 }
 
+int o_stream_flush_parent(struct ostream_private *_stream)
+{
+       int ret;
+
+       i_assert(_stream->parent != NULL);
+
+       if (!_stream->finished)
+               ret = o_stream_flush(_stream->parent);
+       else
+               ret = o_stream_finish(_stream->parent);
+       if (ret < 0)
+               o_stream_copy_error_from_parent(_stream);
+       return ret;
+}
+
 static int o_stream_default_flush(struct ostream_private *_stream)
 {
        int ret;