]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added o_stream_switch_ioloop() and implemented it to all ostreams.
authorTimo Sirainen <tss@iki.fi>
Wed, 7 Sep 2011 07:59:35 +0000 (10:59 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 7 Sep 2011 07:59:35 +0000 (10:59 +0300)
src/lib-ssl-iostream/ostream-openssl.c
src/lib/ostream-file.c
src/lib/ostream-internal.h
src/lib/ostream.c
src/lib/ostream.h
src/plugins/zlib/ostream-bzlib.c
src/plugins/zlib/ostream-zlib.c

index a3c79ce25405b71f7824bb8d71463c00f151356c..6c03eea6c3cfe68b154f8b555e32f6076a3d237c 100644 (file)
@@ -180,6 +180,13 @@ o_stream_ssl_sendv(struct ostream_private *stream,
        return bytes_sent != 0 ? (ssize_t)bytes_sent : ret;
 }
 
+static void o_stream_ssl_switch_ioloop(struct ostream_private *stream)
+{
+       struct ssl_ostream *sstream = (struct ssl_ostream *)stream;
+
+       o_stream_switch_ioloop(sstream->ssl_io->plain_output);
+}
+
 static int plain_flush_callback(struct ssl_ostream *sstream)
 {
        int ret, ret2;
@@ -209,6 +216,7 @@ struct ostream *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;
 
        o_stream_set_flush_callback(ssl_io->plain_output,
                                    plain_flush_callback, sstream);
index e9fbe8a81427a7c8f8a0ae1dcf869b7e884f8d7c..7abaca409e9c1cf462a9e75ccfda5a7cd9c84378 100644 (file)
@@ -870,6 +870,14 @@ static off_t o_stream_file_send_istream(struct ostream_private *outstream,
        return io_stream_copy_stream(outstream, instream, same_stream);
 }
 
+static void o_stream_file_switch_ioloop(struct ostream_private *stream)
+{
+       struct file_ostream *fstream = (struct file_ostream *)stream;
+
+       if (fstream->io != NULL)
+               fstream->io = io_loop_move_io(&fstream->io);
+}
+
 static struct file_ostream *
 o_stream_create_fd_common(int fd, bool autoclose_fd)
 {
@@ -891,6 +899,7 @@ o_stream_create_fd_common(int fd, bool autoclose_fd)
        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;
 
        return fstream;
 }
index 59925ebd6a5cca0b5a39587a7fba937f4facaeb7..8aa11151b35e127379b569e3c0e0d333221fcc52 100644 (file)
@@ -21,6 +21,7 @@ struct ostream_private {
                        const void *data, size_t size, uoff_t offset);
        off_t (*send_istream)(struct ostream_private *outstream,
                              struct istream *instream);
+       void (*switch_ioloop)(struct ostream_private *stream);
 
 /* data: */
        struct ostream ostream;
index f3fe855843f7174f8cc3ee7cdb697966e6b7042e..de5be265c8b2973efd71f9804b5488125d98e1d6 100644 (file)
@@ -292,3 +292,11 @@ off_t io_stream_copy(struct ostream *outstream, struct istream *instream,
 
        return (off_t)(instream->v_offset - start_offset);
 }
+
+void o_stream_switch_ioloop(struct ostream *stream)
+{
+       struct ostream_private *_stream = stream->real_stream;
+
+       if (_stream->switch_ioloop != NULL)
+               _stream->switch_ioloop(_stream);
+}
index 9d0fe7fd5ccb01d2b9f73c152dae20c757007f34..dd1dee85f6a2bc6f445a5d1178b30955d9cff763 100644 (file)
@@ -106,4 +106,8 @@ off_t o_stream_send_istream(struct ostream *outstream,
 int o_stream_pwrite(struct ostream *stream, const void *data, size_t size,
                    uoff_t offset);
 
+/* If there are any I/O loop items associated with the stream, move all of
+   them to current_ioloop. */
+void o_stream_switch_ioloop(struct ostream *stream);
+
 #endif
index 588f5b534b624f844cb00f317c913c4197c8fe32..47f2b96aa0014b4e0ecd93e154f7ba5ac44b94d3 100644 (file)
@@ -146,6 +146,13 @@ static int o_stream_bzlib_flush(struct ostream_private *stream)
        return ret;
 }
 
+static void o_stream_bzlib_switch_ioloop(struct ostream_private *stream)
+{
+       struct bzlib_ostream *zstream = (struct bzlib_ostream *)stream;
+
+       o_stream_switch_ioloop(zstream->output);
+}
+
 static ssize_t
 o_stream_bzlib_sendv(struct ostream_private *stream,
                    const struct const_iovec *iov, unsigned int iov_count)
@@ -176,6 +183,7 @@ struct ostream *o_stream_create_bz2(struct ostream *output, int level)
        zstream->ostream.sendv = o_stream_bzlib_sendv;
        zstream->ostream.cork = o_stream_bzlib_cork;
        zstream->ostream.flush = o_stream_bzlib_flush;
+       zstream->ostream.switch_ioloop = o_stream_bzlib_switch_ioloop;
        zstream->ostream.iostream.close = o_stream_bzlib_close;
        zstream->output = output;
        o_stream_ref(output);
index 1510f89a986a11d02a4f49045a1e3ddc1e890597..26865f6d8f0b0c169e2fb7e782e19041ce334eb6 100644 (file)
@@ -209,6 +209,13 @@ static int o_stream_zlib_flush(struct ostream_private *stream)
        return ret;
 }
 
+static void o_stream_zlib_switch_ioloop(struct ostream_private *stream)
+{
+       struct zlib_ostream *zstream = (struct zlib_ostream *)stream;
+
+       o_stream_switch_ioloop(zstream->output);
+}
+
 static ssize_t
 o_stream_zlib_sendv(struct ostream_private *stream,
                    const struct const_iovec *iov, unsigned int iov_count)
@@ -260,6 +267,7 @@ o_stream_create_zlib(struct ostream *output, int level, bool gz)
        zstream->ostream.sendv = o_stream_zlib_sendv;
        zstream->ostream.cork = o_stream_zlib_cork;
        zstream->ostream.flush = o_stream_zlib_flush;
+       zstream->ostream.switch_ioloop = o_stream_zlib_switch_ioloop;
        zstream->ostream.iostream.close = o_stream_zlib_close;
        zstream->output = output;
        zstream->crc = 0;