]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Reformat iostream-pump.c.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 25 Feb 2018 18:04:14 +0000 (19:04 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 25 Jun 2019 09:18:25 +0000 (12:18 +0300)
src/lib/iostream-pump.c

index 51ad8d040ae6da00bd08f75f82451db239cd495f..6835b5854e9cd44b8480551fc3b2f9655d283511 100644 (file)
@@ -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"
 #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;