]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: ostream: Allow switching to a specific ioloop.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Wed, 17 Jan 2018 01:49:44 +0000 (02:49 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 12 Mar 2018 07:22:59 +0000 (09:22 +0200)
src/lib-ssl-iostream/ostream-openssl.c
src/lib/ostream-file.c
src/lib/ostream-private.h
src/lib/ostream.c
src/lib/ostream.h

index f591e3430c8562a9e9a7947e285f68832cd64a74..87b16784142a742be62955623a33500fb7da0c3c 100644 (file)
@@ -159,11 +159,12 @@ o_stream_ssl_sendv(struct ostream_private *stream,
        return bytes_sent;
 }
 
-static void o_stream_ssl_switch_ioloop(struct ostream_private *stream)
+static void o_stream_ssl_switch_ioloop_to(struct ostream_private *stream,
+                                         struct ioloop *ioloop)
 {
        struct ssl_ostream *sstream = (struct ssl_ostream *)stream;
 
-       o_stream_switch_ioloop(sstream->ssl_io->plain_output);
+       o_stream_switch_ioloop_to(sstream->ssl_io->plain_output, ioloop);
 }
 
 static int plain_flush_callback(struct ssl_ostream *sstream)
@@ -227,7 +228,7 @@ struct ostream *openssl_o_stream_create_ssl(struct ssl_iostream *ssl_io)
        sstream->ostream.iostream.destroy = o_stream_ssl_destroy;
        sstream->ostream.sendv = o_stream_ssl_sendv;
        sstream->ostream.flush = o_stream_ssl_flush;
-       sstream->ostream.switch_ioloop = o_stream_ssl_switch_ioloop;
+       sstream->ostream.switch_ioloop_to = o_stream_ssl_switch_ioloop_to;
 
        sstream->ostream.get_used_size = o_stream_ssl_get_used_size;
        sstream->ostream.flush_pending = o_stream_ssl_flush_pending;
index 70c310b05346e1a4974cc744134f3a53f0e0c81d..7d26f694009847aa3d54210e258f43c1282014a0 100644 (file)
@@ -333,6 +333,7 @@ static int buffer_flush(struct file_ostream *fstream)
 static void o_stream_file_cork(struct ostream_private *stream, bool set)
 {
        struct file_ostream *fstream = (struct file_ostream *)stream;
+       struct iostream_private *iostream = &fstream->ostream.iostream;
        int ret;
 
        if (stream->corked != set && !stream->ostream.closed) {
@@ -345,8 +346,10 @@ static void o_stream_file_cork(struct ostream_private *stream, bool set)
                        if (fstream->io == NULL &&
                            (ret == 0 || fstream->flush_pending) &&
                            !stream->ostream.closed) {
-                               fstream->io = io_add(fstream->fd, IO_WRITE,
-                                                    stream_send_io, fstream);
+                               fstream->io = io_add_to(
+                                       io_stream_get_ioloop(iostream),
+                                       fstream->fd, IO_WRITE,
+                                       stream_send_io, fstream);
                        }
                }
 
@@ -371,11 +374,13 @@ static void
 o_stream_file_flush_pending(struct ostream_private *stream, bool set)
 {
        struct file_ostream *fstream = (struct file_ostream *) stream;
+       struct iostream_private *iostream = &fstream->ostream.iostream;
 
        fstream->flush_pending = set;
        if (set && !stream->corked && fstream->io == NULL) {
-               fstream->io = io_add(fstream->fd, IO_WRITE,
-                                    stream_send_io, fstream);
+               fstream->io = io_add_to(io_stream_get_ioloop(iostream),
+                                       fstream->fd, IO_WRITE,
+                                       stream_send_io, fstream);
        }
 }
 
@@ -459,6 +464,7 @@ static void o_stream_grow_buffer(struct file_ostream *fstream, size_t bytes)
 static void stream_send_io(struct file_ostream *fstream)
 {
        struct ostream *ostream = &fstream->ostream.ostream;
+       struct iostream_private *iostream = &fstream->ostream.iostream;
        bool use_cork = !fstream->ostream.corked;
        int ret;
 
@@ -488,8 +494,9 @@ static void stream_send_io(struct file_ostream *fstream)
                   might have just returned 0 without there being any data
                   to be sent. */
                if (fstream->io == NULL) {
-                       fstream->io = io_add(fstream->fd, IO_WRITE,
-                                            stream_send_io, fstream);
+                       fstream->io = io_add_to(io_stream_get_ioloop(iostream),
+                                               fstream->fd, IO_WRITE,
+                                               stream_send_io, fstream);
                }
        }
 
@@ -499,6 +506,7 @@ static void stream_send_io(struct file_ostream *fstream)
 static size_t o_stream_add(struct file_ostream *fstream,
                           const void *data, size_t size)
 {
+       struct iostream_private *iostream = &fstream->ostream.iostream;
        size_t unused, sent;
        int i;
 
@@ -529,8 +537,9 @@ static size_t o_stream_add(struct file_ostream *fstream,
 
        if (sent != 0 && fstream->io == NULL &&
            !fstream->ostream.corked && !fstream->file) {
-               fstream->io = io_add(fstream->fd, IO_WRITE, stream_send_io,
-                                    fstream);
+               fstream->io = io_add_to(io_stream_get_ioloop(iostream),
+                                       fstream->fd, IO_WRITE, stream_send_io,
+                                       fstream);
        }
 
        return sent;
@@ -927,12 +936,13 @@ o_stream_file_send_istream(struct ostream_private *outstream,
        return io_stream_copy_same_stream(outstream, instream);
 }
 
-static void o_stream_file_switch_ioloop(struct ostream_private *stream)
+static void o_stream_file_switch_ioloop_to(struct ostream_private *stream,
+                                          struct ioloop *ioloop)
 {
        struct file_ostream *fstream = (struct file_ostream *)stream;
 
        if (fstream->io != NULL)
-               fstream->io = io_loop_move_io(&fstream->io);
+               fstream->io = io_loop_move_io_to(ioloop, &fstream->io);
 }
 
 struct ostream *
@@ -956,7 +966,7 @@ o_stream_create_file_common(struct file_ostream *fstream,
        fstream->ostream.sendv = o_stream_file_sendv;
        fstream->ostream.write_at = o_stream_file_write_at;
        fstream->ostream.send_istream = o_stream_file_send_istream;
-       fstream->ostream.switch_ioloop = o_stream_file_switch_ioloop;
+       fstream->ostream.switch_ioloop_to = o_stream_file_switch_ioloop_to;
 
        fstream->writev = o_stream_file_writev;
 
index e0a7d81be7bad0ed05701f57ee1b7f1413cb59c9..f60bc75e2139bd0d7bf314c78b54be887295aec6 100644 (file)
@@ -25,7 +25,8 @@ struct ostream_private {
        enum ostream_send_istream_result
                (*send_istream)(struct ostream_private *outstream,
                                struct istream *instream);
-       void (*switch_ioloop)(struct ostream_private *stream);
+       void (*switch_ioloop_to)(struct ostream_private *stream,
+                                struct ioloop *ioloop);
 
 /* data: */
        struct ostream ostream;
index 7004d858ea79b24400a34a72ee6daca823cbc66b..543880d87c96d39557d075b4a90c081f08c5081a 100644 (file)
@@ -499,13 +499,18 @@ io_stream_copy(struct ostream *outstream, struct istream *instream)
        return OSTREAM_SEND_ISTREAM_RESULT_FINISHED;
 }
 
-void o_stream_switch_ioloop(struct ostream *stream)
+void o_stream_switch_ioloop_to(struct ostream *stream, struct ioloop *ioloop)
 {
        struct ostream_private *_stream = stream->real_stream;
 
-       io_stream_switch_ioloop_to(&_stream->iostream, current_ioloop);
+       io_stream_switch_ioloop_to(&_stream->iostream, ioloop);
+
+       _stream->switch_ioloop_to(_stream, ioloop);
+}
 
-       _stream->switch_ioloop(_stream);
+void o_stream_switch_ioloop(struct ostream *stream)
+{
+       o_stream_switch_ioloop_to(stream, current_ioloop);
 }
 
 static void o_stream_default_close(struct iostream_private *stream,
@@ -669,10 +674,12 @@ o_stream_default_send_istream(struct ostream_private *outstream,
        return io_stream_copy(&outstream->ostream, instream);
 }
 
-static void o_stream_default_switch_ioloop(struct ostream_private *_stream)
+static void
+o_stream_default_switch_ioloop_to(struct ostream_private *_stream,
+                                 struct ioloop *ioloop)
 {
        if (_stream->parent != NULL)
-               o_stream_switch_ioloop(_stream->parent);
+               o_stream_switch_ioloop_to(_stream->parent, ioloop);
 }
 
 struct ostream *
@@ -723,8 +730,8 @@ o_stream_create(struct ostream_private *_stream, struct ostream *parent, int fd)
                _stream->write_at = o_stream_default_write_at;
        if (_stream->send_istream == NULL)
                _stream->send_istream = o_stream_default_send_istream;
-       if (_stream->switch_ioloop == NULL)
-               _stream->switch_ioloop = o_stream_default_switch_ioloop;
+       if (_stream->switch_ioloop_to == NULL)
+               _stream->switch_ioloop_to = o_stream_default_switch_ioloop_to;
 
        io_stream_init(&_stream->iostream);
        return &_stream->ostream;
index 67416423f0106e52b0676066686a7af94b44147c..9e76f98db3956d56d10e7e5250ee1fa1ac952b5f 100644 (file)
@@ -210,7 +210,8 @@ int o_stream_pwrite(struct ostream *stream, const void *data, size_t size,
 void o_stream_get_last_write_time(struct ostream *stream, struct timeval *tv_r);
 
 /* If there are any I/O loop items associated with the stream, move all of
-   them to current_ioloop. */
+   them to provided/current ioloop. */
+void o_stream_switch_ioloop_to(struct ostream *stream, struct ioloop *ioloop);
 void o_stream_switch_ioloop(struct ostream *stream);
 
 #endif