-/* 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"
#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;
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);
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;
/* 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;
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;
}
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;
struct iostream_pump *
iostream_pump_create(struct istream *input, struct ostream *output)
{
+ struct iostream_pump *pump;
+
i_assert(input != NULL &&
output != NULL);
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;
}
}
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;