]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: ostream-wrapper - Return flush status from o_stream_wrapper_continue().
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 29 Apr 2020 07:51:55 +0000 (09:51 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 5 May 2020 06:17:30 +0000 (06:17 +0000)
src/lib/ostream-wrapper.c
src/lib/ostream-wrapper.h

index 5ba6e2ea93dce950e37244b6cb46f8aca28781ce..e2e5fd1a30c821a7639b410f346e7758f266ff6a 100644 (file)
@@ -1071,13 +1071,13 @@ wrapper_ostream_create(struct wrapper_ostream *wostream,
        return o_stream_create(&wostream->ostream, NULL, -1);
 }
 
-void wrapper_ostream_continue(struct wrapper_ostream *wostream)
+int wrapper_ostream_continue(struct wrapper_ostream *wostream)
 {
        struct ostream_private *stream = &wostream->ostream;
        struct ostream *ostream = &stream->ostream;
        struct ioloop *ioloop = NULL;
        bool use_cork = !stream->corked;
-       int ret;
+       int ret = 1;
 
        if (wostream->flush_waiting) {
                /* Inside wrapper_ostream_flush_wait() */
@@ -1088,14 +1088,15 @@ void wrapper_ostream_continue(struct wrapper_ostream *wostream)
             wostream->output != NULL &&
             o_stream_get_buffer_used_size(wostream->output) == 0)) {
                /* Already finished */
-               if (wrapper_ostream_finish(wostream) == 0)
-                       return;
+               ret = wrapper_ostream_finish(wostream);
+               if (ret == 0)
+                       return 0;
        }
        if (wostream->flush_waiting) {
                i_assert(ioloop != NULL);
                io_loop_stop(ioloop);
                wostream->flush_waiting = FALSE;
-               return;
+               return ret;
        }
 
        /* Set flush_pending = FALSE first before calling the flush callback,
@@ -1132,7 +1133,20 @@ void wrapper_ostream_continue(struct wrapper_ostream *wostream)
        if (!stream->ostream.blocking)
                wrapper_ostream_output_manage(wostream, FALSE);
 
+       if (ret < 0 || ostream->stream_errno != 0 ||
+           wostream->pending_errno != 0)
+               ret = -1;
+       else if (wostream->output_closed)
+               ret = 1;
+       else if (!wrapper_ostream_is_empty(wostream) &&
+                (!stream->corked || wrapper_ostream_is_filled(wostream)))
+               ret = 0;
+       else if (wostream->flush_pending)
+               ret = 0;
+
        o_stream_unref(&ostream);
+
+       return ret;
 }
 
 void wrapper_ostream_trigger_flush(struct wrapper_ostream *wostream)
index 22842c0041617b9a5289c54111df5570baa23928..3fb6cccaf4ad9043485fa8b9cc0c682289423e10 100644 (file)
@@ -125,8 +125,9 @@ wrapper_ostream_create(struct wrapper_ostream *wostream,
                       size_t max_buffer_size, bool blocking,
                       struct event *event) ATTR_NULL(4);
 
-/* Continue sending output. */
-void wrapper_ostream_continue(struct wrapper_ostream *wostream);
+/* Continue sending output. Returns 1 if all buffered data is sent so far,
+   0 if not, and -1 if an error occurred. */
+int wrapper_ostream_continue(struct wrapper_ostream *wostream);
 /* Trigger an (asynchronous) flush on the output stream. */
 void wrapper_ostream_trigger_flush(struct wrapper_ostream *wostream);