dovecot-2.1: Added o_stream_switch_ioloop() and implemented it t...

dovecot at dovecot.org dovecot at dovecot.org
Wed Sep 7 11:00:58 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/977dcd541f69
changeset: 13417:977dcd541f69
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Sep 07 10:59:35 2011 +0300
description:
Added o_stream_switch_ioloop() and implemented it to all ostreams.

diffstat:

 src/lib-ssl-iostream/ostream-openssl.c |  8 ++++++++
 src/lib/ostream-file.c                 |  9 +++++++++
 src/lib/ostream-internal.h             |  1 +
 src/lib/ostream.c                      |  8 ++++++++
 src/lib/ostream.h                      |  4 ++++
 src/plugins/zlib/ostream-bzlib.c       |  8 ++++++++
 src/plugins/zlib/ostream-zlib.c        |  8 ++++++++
 7 files changed, 46 insertions(+), 0 deletions(-)

diffs (139 lines):

diff -r e5570ee5d695 -r 977dcd541f69 src/lib-ssl-iostream/ostream-openssl.c
--- a/src/lib-ssl-iostream/ostream-openssl.c	Wed Sep 07 10:38:01 2011 +0300
+++ b/src/lib-ssl-iostream/ostream-openssl.c	Wed Sep 07 10:59:35 2011 +0300
@@ -180,6 +180,13 @@
 	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 @@
 	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 -r e5570ee5d695 -r 977dcd541f69 src/lib/ostream-file.c
--- a/src/lib/ostream-file.c	Wed Sep 07 10:38:01 2011 +0300
+++ b/src/lib/ostream-file.c	Wed Sep 07 10:59:35 2011 +0300
@@ -870,6 +870,14 @@
 	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 @@
 	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 -r e5570ee5d695 -r 977dcd541f69 src/lib/ostream-internal.h
--- a/src/lib/ostream-internal.h	Wed Sep 07 10:38:01 2011 +0300
+++ b/src/lib/ostream-internal.h	Wed Sep 07 10:59:35 2011 +0300
@@ -21,6 +21,7 @@
 			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 -r e5570ee5d695 -r 977dcd541f69 src/lib/ostream.c
--- a/src/lib/ostream.c	Wed Sep 07 10:38:01 2011 +0300
+++ b/src/lib/ostream.c	Wed Sep 07 10:59:35 2011 +0300
@@ -292,3 +292,11 @@
 
 	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 -r e5570ee5d695 -r 977dcd541f69 src/lib/ostream.h
--- a/src/lib/ostream.h	Wed Sep 07 10:38:01 2011 +0300
+++ b/src/lib/ostream.h	Wed Sep 07 10:59:35 2011 +0300
@@ -106,4 +106,8 @@
 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 -r e5570ee5d695 -r 977dcd541f69 src/plugins/zlib/ostream-bzlib.c
--- a/src/plugins/zlib/ostream-bzlib.c	Wed Sep 07 10:38:01 2011 +0300
+++ b/src/plugins/zlib/ostream-bzlib.c	Wed Sep 07 10:59:35 2011 +0300
@@ -146,6 +146,13 @@
 	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 @@
 	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 -r e5570ee5d695 -r 977dcd541f69 src/plugins/zlib/ostream-zlib.c
--- a/src/plugins/zlib/ostream-zlib.c	Wed Sep 07 10:38:01 2011 +0300
+++ b/src/plugins/zlib/ostream-zlib.c	Wed Sep 07 10:59:35 2011 +0300
@@ -209,6 +209,13 @@
 	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 @@
 	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;


More information about the dovecot-cvs mailing list