iostream-pump.h revision fe4a5467c998dfd79a071416068ca59d5a6a388f
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file
e248fe370c4047cee921a91b48edc37944ab0526Timo SirainenThis construct pumps data from istream to ostream asynchronously.
e248fe370c4047cee921a91b48edc37944ab0526Timo SirainenThe pump requires you to provide completion callback. The
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainencompletion callback is called with success parameter to
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenindicate whether it ended with error.
4ead43ecc06d10047998966c4dc0b142ecce4b66Timo SirainenThe istream and ostream are reffed on creation and unreffed
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainentypedef void iostream_pump_callback_t(bool success, void *context);
ad004e44be109684521494b5af2ad1da39b8bb27Timo Siraineniostream_pump_create(struct istream *input, struct ostream *output);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstruct istream *iostream_pump_get_input(struct iostream_pump *pump);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstruct ostream *iostream_pump_get_output(struct iostream_pump *pump);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid iostream_pump_start(struct iostream_pump *pump);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid iostream_pump_stop(struct iostream_pump *pump);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid iostream_pump_ref(struct iostream_pump *pump);
ad004e44be109684521494b5af2ad1da39b8bb27Timo Sirainenvoid iostream_pump_unref(struct iostream_pump **pump_r);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid iostream_pump_set_completion_callback(struct iostream_pump *pump,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen iostream_pump_callback_t *callback, void *context);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen#define iostream_pump_set_completion_callback(pump, callback, context) \
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen iostream_pump_set_completion_callback(pump, (iostream_pump_callback_t *)callback, context + \
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen CALLBACK_TYPECHECK(callback, void (*)(bool, typeof(context))))
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Returns TRUE if the pump is currently only writing to the ostream. The input
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen listener has been removed either because the ostream buffer is full or
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen because the istream already returned EOF. This function can also be called
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen from the completion callback in error conditions. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenbool iostream_pump_is_waiting_output(struct iostream_pump *pump);