From: Timo Sirainen Date: Wed, 7 Sep 2011 07:59:35 +0000 (+0300) Subject: Added o_stream_switch_ioloop() and implemented it to all ostreams. X-Git-Tag: 2.1.alpha2~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71da447014454c84828d9dface77219875554d7d;p=thirdparty%2Fdovecot%2Fcore.git Added o_stream_switch_ioloop() and implemented it to all ostreams. --- diff --git a/src/lib-ssl-iostream/ostream-openssl.c b/src/lib-ssl-iostream/ostream-openssl.c index a3c79ce254..6c03eea6c3 100644 --- a/src/lib-ssl-iostream/ostream-openssl.c +++ b/src/lib-ssl-iostream/ostream-openssl.c @@ -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); diff --git a/src/lib/ostream-file.c b/src/lib/ostream-file.c index e9fbe8a814..7abaca409e 100644 --- a/src/lib/ostream-file.c +++ b/src/lib/ostream-file.c @@ -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; } diff --git a/src/lib/ostream-internal.h b/src/lib/ostream-internal.h index 59925ebd6a..8aa11151b3 100644 --- a/src/lib/ostream-internal.h +++ b/src/lib/ostream-internal.h @@ -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; diff --git a/src/lib/ostream.c b/src/lib/ostream.c index f3fe855843..de5be265c8 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -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); +} diff --git a/src/lib/ostream.h b/src/lib/ostream.h index 9d0fe7fd5c..dd1dee85f6 100644 --- a/src/lib/ostream.h +++ b/src/lib/ostream.h @@ -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 diff --git a/src/plugins/zlib/ostream-bzlib.c b/src/plugins/zlib/ostream-bzlib.c index 588f5b534b..47f2b96aa0 100644 --- a/src/plugins/zlib/ostream-bzlib.c +++ b/src/plugins/zlib/ostream-bzlib.c @@ -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); diff --git a/src/plugins/zlib/ostream-zlib.c b/src/plugins/zlib/ostream-zlib.c index 1510f89a98..26865f6d8f 100644 --- a/src/plugins/zlib/ostream-zlib.c +++ b/src/plugins/zlib/ostream-zlib.c @@ -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;