From: Timo Sirainen Date: Sun, 29 Oct 2017 21:53:00 +0000 (+0200) Subject: lib: iostream-pump - Add iostream_pump_is_waiting_output() X-Git-Tag: 2.3.0.rc1~661 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fe4a5467c998dfd79a071416068ca59d5a6a388f;p=thirdparty%2Fdovecot%2Fcore.git lib: iostream-pump - Add iostream_pump_is_waiting_output() --- diff --git a/src/lib/iostream-pump.c b/src/lib/iostream-pump.c index 9a4eb80ba5..ba1a5615cc 100644 --- a/src/lib/iostream-pump.c +++ b/src/lib/iostream-pump.c @@ -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); diff --git a/src/lib/iostream-pump.h b/src/lib/iostream-pump.h index fd544bdaef..48d57c8ac0 100644 --- a/src/lib/iostream-pump.h +++ b/src/lib/iostream-pump.h @@ -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