]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Automatically flush ostream when it's closed
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 27 Oct 2017 23:55:22 +0000 (02:55 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Mon, 30 Oct 2017 11:04:53 +0000 (13:04 +0200)
Also verify that it unexpectedly didn't get fully flushed.

src/lib/ostream.c
src/lib/ostream.h

index 15e23d44f72f052edc90078a04d8a2163111d54e..04effd05ec2be470eb7803a8a5d8bf3994975c06 100644 (file)
@@ -45,6 +45,14 @@ const char *o_stream_get_error(struct ostream *stream)
 
 static void o_stream_close_full(struct ostream *stream, bool close_parents)
 {
+       /* Ideally o_stream_finish() would be called for all non-failed
+          ostreams, but strictly requiring it would cause unnecessary
+          complexity for many callers. Just require that at this point
+          after flushing there isn't anything in the output buffer or that
+          we're ignoring all errors. */
+       if (o_stream_flush(stream) == 0)
+               i_assert(stream->real_stream->error_handling_disabled);
+
        if (!stream->closed && !stream->real_stream->closing) {
                /* first mark the stream as being closed so the
                   o_stream_copy_error_from_parent() won't recurse us back
index 9b1595962890e6f1ffd11bd826465ce5bd72a70e..41968e0bf86ee8be5955765ea34b315a08fb99d8 100644 (file)
@@ -100,7 +100,13 @@ void o_stream_remove_destroy_callback(struct ostream *stream,
                                      void (*callback)());
 
 /* Mark the stream and all of its parent streams closed. Nothing will be
-   sent after this call. */
+   sent after this call. When using ostreams that require writing a trailer,
+   o_stream_finish() must be used before the stream is closed. When ostream
+   is destroyed, it's also closed but its parents aren't.
+
+   Closing the ostream (also via destroy) will first flush the ostream, and
+   afterwards requires one of: a) stream has failed, b) there is no more
+   buffered data, c) o_stream_set_no_error_handling() has been called. */
 void o_stream_close(struct ostream *stream);
 
 /* Set IO_WRITE callback. Default will just try to flush the output and