From: Stephan Bosch Date: Sun, 25 Feb 2018 18:04:14 +0000 (+0100) Subject: lib: Reformat iostream-pump.c. X-Git-Tag: 2.3.9~2117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b056116e1b7791e8d678a83455617695c8b1d72c;p=thirdparty%2Fdovecot%2Fcore.git lib: Reformat iostream-pump.c. --- diff --git a/src/lib/iostream-pump.c b/src/lib/iostream-pump.c index 9cc5b8896c..d28ca253eb 100644 --- a/src/lib/iostream-pump.c +++ b/src/lib/iostream-pump.c @@ -1,5 +1,5 @@ -/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file - */ +/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */ + #include "lib.h" #include "buffer.h" #include "str.h" @@ -11,13 +11,13 @@ #undef iostream_pump_set_completion_callback struct iostream_pump { + unsigned int ref; + struct istream *input; struct ostream *output; struct io *io; - unsigned int ref; - iostream_pump_callback_t *callback; void *context; @@ -25,16 +25,16 @@ struct iostream_pump { bool completed; }; -static -void iostream_pump_copy(struct iostream_pump *pump) +static void iostream_pump_copy(struct iostream_pump *pump) { enum ostream_send_istream_result res; + size_t old_size; o_stream_cork(pump->output); - size_t old_size = o_stream_get_max_buffer_size(pump->output); + old_size = o_stream_get_max_buffer_size(pump->output); o_stream_set_max_buffer_size(pump->output, - I_MIN(IO_BLOCK_SIZE, - o_stream_get_max_buffer_size(pump->output))); + I_MIN(IO_BLOCK_SIZE, + o_stream_get_max_buffer_size(pump->output))); res = o_stream_send_istream(pump->output, pump->input); o_stream_set_max_buffer_size(pump->output, old_size); o_stream_uncork(pump->output); @@ -42,11 +42,13 @@ void iostream_pump_copy(struct iostream_pump *pump) switch(res) { case OSTREAM_SEND_ISTREAM_RESULT_ERROR_INPUT: io_remove(&pump->io); - pump->callback(IOSTREAM_PUMP_STATUS_INPUT_ERROR, pump->context); + pump->callback(IOSTREAM_PUMP_STATUS_INPUT_ERROR, + pump->context); return; case OSTREAM_SEND_ISTREAM_RESULT_ERROR_OUTPUT: io_remove(&pump->io); - pump->callback(IOSTREAM_PUMP_STATUS_OUTPUT_ERROR, pump->context); + pump->callback(IOSTREAM_PUMP_STATUS_OUTPUT_ERROR, + pump->context); return; case OSTREAM_SEND_ISTREAM_RESULT_WAIT_OUTPUT: pump->waiting_output = TRUE; @@ -58,14 +60,16 @@ void iostream_pump_copy(struct iostream_pump *pump) /* flush it */ switch (o_stream_flush(pump->output)) { case -1: - pump->callback(IOSTREAM_PUMP_STATUS_OUTPUT_ERROR, pump->context); + pump->callback(IOSTREAM_PUMP_STATUS_OUTPUT_ERROR, + pump->context); break; case 0: pump->waiting_output = TRUE; pump->completed = TRUE; break; default: - pump->callback(IOSTREAM_PUMP_STATUS_INPUT_EOF, pump->context); + pump->callback(IOSTREAM_PUMP_STATUS_INPUT_EOF, + pump->context); break; } return; @@ -76,13 +80,15 @@ void iostream_pump_copy(struct iostream_pump *pump) i_unreached(); } -static -int iostream_pump_flush(struct iostream_pump *pump) +static int iostream_pump_flush(struct iostream_pump *pump) { int ret; + if ((ret = o_stream_flush(pump->output)) <= 0) { - if (ret < 0) - pump->callback(IOSTREAM_PUMP_STATUS_OUTPUT_ERROR, pump->context); + if (ret < 0) { + pump->callback(IOSTREAM_PUMP_STATUS_OUTPUT_ERROR, + pump->context); + } return ret; } pump->waiting_output = FALSE; @@ -92,7 +98,8 @@ int iostream_pump_flush(struct iostream_pump *pump) } if (pump->io == NULL) { - pump->io = io_add_istream(pump->input, iostream_pump_copy, pump); + pump->io = io_add_istream(pump->input, + iostream_pump_copy, pump); io_set_pending(pump->io); } return ret; @@ -101,6 +108,8 @@ int iostream_pump_flush(struct iostream_pump *pump) struct iostream_pump * iostream_pump_create(struct istream *input, struct ostream *output) { + struct iostream_pump *pump; + i_assert(input != NULL && output != NULL); @@ -109,12 +118,11 @@ iostream_pump_create(struct istream *input, struct ostream *output) o_stream_ref(output); /* create pump */ - struct iostream_pump *pump = i_new(struct iostream_pump, 1); + pump = i_new(struct iostream_pump, 1); + pump->ref = 1; pump->input = input; pump->output = output; - pump->ref = 1; - return pump; } @@ -146,7 +154,8 @@ struct ostream *iostream_pump_get_output(struct iostream_pump *pump) } void iostream_pump_set_completion_callback(struct iostream_pump *pump, - iostream_pump_callback_t *callback, void *context) + iostream_pump_callback_t *callback, + void *context) { i_assert(pump != NULL); pump->callback = callback;