/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file
*/
#ifndef IOSTREAM_PROXY_H
/**
iostream-proxy
=============
This construct will proxy data between two pairs of
istream and ostream. Data is proxied from left to right
and right to left using iostream-pump.
The proxy requires you to provide completion callback. The
completion callback is called with success parameter to
indicate whether it ended with error.
The istreams and ostreams are reffed on creation and unreffed
on unref.
**/
struct istream;
struct ostream;
struct iostream_proxy;
enum iostream_proxy_side {
/* Input is coming from left side's istream and is proxied to
right side's ostream. */
/* Input is coming from right side's istream and is proxied to
left side's ostream. */
};
enum iostream_proxy_status {
/* proxy succeeded - EOF received from istream and all output was
written successfully to ostream. */
/* proxy failed - istream returned an error */
/* proxy failed - other side's ostream returned an error */
};
/* The callback maybe be called once or twice. Usually the first call should
destroy the proxy, but it's possible for it to just wait for the other
direction of the proxy to finish as well and call the callback.
Note that the sides mean which side is the reader side. If the failure is in
ostream, it's the other side's ostream that failed. So for example if
side=left, the write failed to the right side's ostream.
The callback is called when the proxy succeeds or fails due to
iostreams. (It's not called if proxy is destroyed.) */
enum iostream_proxy_status status,
void *context);
struct iostream_proxy *
/* See iostream_pump_is_waiting_output() */
enum iostream_proxy_side side);
CALLBACK_TYPECHECK(callback, void (*)(enum iostream_proxy_side side, enum iostream_proxy_status, typeof(context))))
#endif