iostream-pump.c revision fe4a5467c998dfd79a071416068ca59d5a6a388f
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file
56f45b3f3ae20e5c933701f4657dda5ef1916855Timo Sirainen unsigned int ref;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid iostream_pump_copy(struct iostream_pump *pump)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen size_t old_size = o_stream_get_max_buffer_size(pump->output);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen res = o_stream_send_istream(pump->output, pump->input);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen o_stream_set_max_buffer_size(pump->output, old_size);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen case OSTREAM_SEND_ISTREAM_RESULT_ERROR_OUTPUT:
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* flush it */
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenint iostream_pump_flush(struct iostream_pump *pump)
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen if ((ret = o_stream_flush(pump->output)) <= 0) {
a928e7efabb1672b1476e597106d4b4b81ac6f3cTimo Sirainen pump->io = io_add_istream(pump->input, iostream_pump_copy, pump);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Siraineniostream_pump_create(struct istream *input, struct ostream *output)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* ref streams */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* create pump */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct iostream_pump *pump = i_new(struct iostream_pump, 1);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid iostream_pump_start(struct iostream_pump *pump)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* add flush handler */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen o_stream_set_flush_callback(pump->output, iostream_pump_flush, pump);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* make IO objects */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen pump->io = io_add_istream(pump->input, iostream_pump_copy, pump);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* make sure we do first read right away */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct istream *iostream_pump_get_input(struct iostream_pump *pump)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct ostream *iostream_pump_get_output(struct iostream_pump *pump)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid iostream_pump_set_completion_callback(struct iostream_pump *pump,