iostream-proxy.h revision 6ce52edd3de46bdf565ee71f6112a9e7a6090031
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file
baf346e71ebd7b44fcba4b48f4d39845453b778bTimo Siraineniostream-proxy
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo SirainenThis construct will proxy data between two pairs of
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenistream and ostream. Data is proxied from left to right
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenand right to left using iostream-pump.
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo SirainenThe proxy requires you to provide completion callback. The
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainencompletion callback is called with success parameter to
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenindicate whether it ended with error.
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo SirainenThe istreams and ostreams are reffed on creation and unreffed
25ec868bd8b5375e1c1c4c3331d761667ddfe26cTimo Sirainentypedef void iostream_proxy_callback_t(enum iostream_proxy_side side,
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Siraineniostream_proxy_create(struct istream *left_input, struct ostream *left_output,
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen struct istream *right_input, struct ostream *right_output);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenstruct istream *iostream_proxy_get_istream(struct iostream_proxy *proxy, enum iostream_proxy_side);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenstruct ostream *iostream_proxy_get_ostream(struct iostream_proxy *proxy, enum iostream_proxy_side);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenvoid iostream_proxy_start(struct iostream_proxy *proxy);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenvoid iostream_proxy_stop(struct iostream_proxy *proxy);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen/* See iostream_pump_is_waiting_output() */
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenbool iostream_proxy_is_waiting_output(struct iostream_proxy *proxy,
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenvoid iostream_proxy_set_completion_callback(struct iostream_proxy *proxy,
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen iostream_proxy_callback_t *callback, void *context);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen#define iostream_proxy_set_completion_callback(proxy, callback, context) \
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen iostream_proxy_set_completion_callback(proxy, (iostream_proxy_callback_t *)callback, context + \
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainen CALLBACK_TYPECHECK(callback, void (*)(enum iostream_proxy_side side, bool, typeof(context))))
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenvoid iostream_proxy_ref(struct iostream_proxy *proxy);
cf636afb3826f0d8e15c248aa1fc04ce72820e08Timo Sirainenvoid iostream_proxy_unref(struct iostream_proxy **proxy_r);