bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomiiostream-pump
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomi=============
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki TuomiThis construct pumps data from istream to ostream asynchronously.
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki TuomiThe pump requires you to provide completion callback. The
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomicompletion callback is called with success parameter to
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomiindicate whether it ended with error.
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki TuomiThe istream and ostream are reffed on creation and unreffed
39435f00a35a276d329283179b3e7e0351482939Timo Sirainen /* pump succeeded - EOF received from istream and all output was
39435f00a35a276d329283179b3e7e0351482939Timo Sirainen written successfully to ostream. */
39435f00a35a276d329283179b3e7e0351482939Timo Sirainen /* pump failed - istream returned an error */
39435f00a35a276d329283179b3e7e0351482939Timo Sirainen /* pump failed - ostream returned an error */
39435f00a35a276d329283179b3e7e0351482939Timo Sirainen/* The callback is called once when the pump succeeds or fails due to
39435f00a35a276d329283179b3e7e0351482939Timo Sirainen iostreams. (It's not called if pump is destroyed.) */
39435f00a35a276d329283179b3e7e0351482939Timo Sirainentypedef void iostream_pump_callback_t(enum iostream_pump_status status,
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomiiostream_pump_create(struct istream *input, struct ostream *output);
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomistruct istream *iostream_pump_get_input(struct iostream_pump *pump);
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomistruct ostream *iostream_pump_get_output(struct iostream_pump *pump);
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomivoid iostream_pump_start(struct iostream_pump *pump);
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomivoid iostream_pump_stop(struct iostream_pump *pump);
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomivoid iostream_pump_ref(struct iostream_pump *pump);
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomivoid iostream_pump_unref(struct iostream_pump **pump_r);
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomivoid iostream_pump_set_completion_callback(struct iostream_pump *pump,
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomi iostream_pump_callback_t *callback, void *context);
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomi#define iostream_pump_set_completion_callback(pump, callback, context) \
08c0bffa1c9ccb1ac67689093f3c99cd38cfd3a4Aki Tuomi iostream_pump_set_completion_callback(pump, (iostream_pump_callback_t *)callback, context + \
39435f00a35a276d329283179b3e7e0351482939Timo Sirainen CALLBACK_TYPECHECK(callback, void (*)(enum iostream_pump_status, typeof(context))))
fe4a5467c998dfd79a071416068ca59d5a6a388fTimo Sirainen/* Returns TRUE if the pump is currently only writing to the ostream. The input
fe4a5467c998dfd79a071416068ca59d5a6a388fTimo Sirainen listener has been removed either because the ostream buffer is full or
fe4a5467c998dfd79a071416068ca59d5a6a388fTimo Sirainen because the istream already returned EOF. This function can also be called
fe4a5467c998dfd79a071416068ca59d5a6a388fTimo Sirainen from the completion callback in error conditions. */
fe4a5467c998dfd79a071416068ca59d5a6a388fTimo Sirainenbool iostream_pump_is_waiting_output(struct iostream_pump *pump);