]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: iostream-pump - Add iostream_pump_is_waiting_output()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 29 Oct 2017 21:53:00 +0000 (23:53 +0200)
committerTimo Sirainen <tss@dovecot.fi>
Wed, 1 Nov 2017 00:23:31 +0000 (02:23 +0200)
src/lib/iostream-pump.c
src/lib/iostream-pump.h

index 9a4eb80ba56f793178cee06c3a71d8cdd1d26994..ba1a5615cce9ed418ae1c9f1c0ae23d2850ab09e 100644 (file)
@@ -20,6 +20,8 @@ struct iostream_pump {
 
        iostream_pump_callback_t *callback;
        void *context;
+
+       bool waiting_output;
        bool completed;
 };
 
@@ -44,9 +46,11 @@ void iostream_pump_copy(struct iostream_pump *pump)
                pump->callback(FALSE, pump->context);
                return;
        case OSTREAM_SEND_ISTREAM_RESULT_WAIT_OUTPUT:
+               pump->waiting_output = TRUE;
                io_remove(&pump->io);
                return;
        case OSTREAM_SEND_ISTREAM_RESULT_FINISHED:
+               pump->waiting_output = FALSE;
                io_remove(&pump->io);
                /* flush it */
                switch (o_stream_flush(pump->output)) {
@@ -54,6 +58,7 @@ void iostream_pump_copy(struct iostream_pump *pump)
                        pump->callback(FALSE, pump->context);
                        break;
                case 0:
+                       pump->waiting_output = TRUE;
                        pump->completed = TRUE;
                        break;
                default:
@@ -62,6 +67,7 @@ void iostream_pump_copy(struct iostream_pump *pump)
                }
                return;
        case OSTREAM_SEND_ISTREAM_RESULT_WAIT_INPUT:
+               pump->waiting_output = FALSE;
                return;
        }
        i_unreached();
@@ -76,6 +82,7 @@ int iostream_pump_flush(struct iostream_pump *pump)
                        pump->callback(FALSE, pump->context);
                return ret;
        }
+       pump->waiting_output = FALSE;
        if (pump->completed) {
                pump->callback(TRUE, pump->context);
                return 1;
@@ -173,6 +180,11 @@ void iostream_pump_stop(struct iostream_pump *pump)
        io_remove(&pump->io);
 }
 
+bool iostream_pump_is_waiting_output(struct iostream_pump *pump)
+{
+       return pump->waiting_output;
+}
+
 void iostream_pump_switch_ioloop(struct iostream_pump *pump)
 {
        i_assert(pump != NULL);
index fd544bdaef4962fc7eda0fa95443331fbf3208b0..48d57c8ac04559b72d6ce4aac1f8a32fb542dccc 100644 (file)
@@ -43,6 +43,12 @@ void iostream_pump_set_completion_callback(struct iostream_pump *pump,
        iostream_pump_set_completion_callback(pump, (iostream_pump_callback_t *)callback, context + \
                CALLBACK_TYPECHECK(callback, void (*)(bool, typeof(context))))
 
+/* Returns TRUE if the pump is currently only writing to the ostream. The input
+   listener has been removed either because the ostream buffer is full or
+   because the istream already returned EOF. This function can also be called
+   from the completion callback in error conditions. */
+bool iostream_pump_is_waiting_output(struct iostream_pump *pump);
+
 void iostream_pump_switch_ioloop(struct iostream_pump *pump);
 
 #endif