iostream-pump.c revision 3bc5b80ae9075e5d940616553f81e8acdd4bd88f
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher unsigned int ref;
65a9065538fd85e6ead925d344e6b421900eb8c2Jakub Hrozekvoid iostream_pump_copy(struct iostream_pump *pump)
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher size_t old_size = o_stream_get_max_buffer_size(pump->output);
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher o_stream_set_max_buffer_size(pump->output,
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher o_stream_get_max_buffer_size(pump->output)));
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher res = o_stream_send_istream(pump->output, pump->input);
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher o_stream_set_max_buffer_size(pump->output, old_size);
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher case OSTREAM_SEND_ISTREAM_RESULT_ERROR_INPUT:
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher case OSTREAM_SEND_ISTREAM_RESULT_ERROR_OUTPUT:
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher case OSTREAM_SEND_ISTREAM_RESULT_WAIT_OUTPUT:
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher case OSTREAM_SEND_ISTREAM_RESULT_FINISHED:
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher /* flush it */
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher case OSTREAM_SEND_ISTREAM_RESULT_WAIT_INPUT:
65a9065538fd85e6ead925d344e6b421900eb8c2Jakub Hrozekint iostream_pump_flush(struct iostream_pump *pump)
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher if ((ret = o_stream_flush(pump->output)) <= 0) {
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher pump->io = io_add_istream(pump->input, iostream_pump_copy, pump);
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagheriostream_pump_create(struct istream *input, struct ostream *output)
1008001f34abb42df75f840db17f14a83f0c21d4Stephen Gallagher /* ref streams */
1008001f34abb42df75f840db17f14a83f0c21d4Stephen Gallagher /* create pump */
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher struct iostream_pump *pump = i_new(struct iostream_pump, 1);
1008001f34abb42df75f840db17f14a83f0c21d4Stephen Gallaghervoid iostream_pump_start(struct iostream_pump *pump)
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher /* add flush handler */
1008001f34abb42df75f840db17f14a83f0c21d4Stephen Gallagher o_stream_set_flush_callback(pump->output, iostream_pump_flush, pump);
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher /* make IO objects */
1008001f34abb42df75f840db17f14a83f0c21d4Stephen Gallagher pump->io = io_add_istream(pump->input, iostream_pump_copy, pump);
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher /* make sure we do first read right away */
1008001f34abb42df75f840db17f14a83f0c21d4Stephen Gallagherstruct istream *iostream_pump_get_input(struct iostream_pump *pump)
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagherstruct ostream *iostream_pump_get_output(struct iostream_pump *pump)
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallaghervoid iostream_pump_set_completion_callback(struct iostream_pump *pump,
65a9065538fd85e6ead925d344e6b421900eb8c2Jakub Hrozek iostream_pump_callback_t *callback, void *context)
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallaghervoid iostream_pump_ref(struct iostream_pump *pump)
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallaghervoid iostream_pump_unref(struct iostream_pump **pump_r)
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher i_assert(pump_r != NULL && *pump_r != NULL);
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallaghervoid iostream_pump_stop(struct iostream_pump *pump)
6b0f9cd2ee601121cb7fe1d9ad8ebce782aa8f39Stephen Gallagher o_stream_unset_flush_callback(pump->output);