dovecot-2.2: lib: io_stream_copy() no longer attempts to read fu...

dovecot at dovecot.org dovecot at dovecot.org
Mon Aug 11 12:57:12 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/e593dce9468d
changeset: 17698:e593dce9468d
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Aug 11 15:54:43 2014 +0300
description:
lib: io_stream_copy() no longer attempts to read full block sizes from input.
Although that may be more efficient for writing (to files), it causes
unnecessary work for the input stream. The writing part should also be
optimized anyway if the caller corks the output stream.

diffstat:

 src/lib/iostream-temp.c   |   6 ++----
 src/lib/ostream-file.c    |   3 +--
 src/lib/ostream-private.h |   3 +--
 src/lib/ostream.c         |  15 +++++----------
 4 files changed, 9 insertions(+), 18 deletions(-)

diffs (95 lines):

diff -r 0e04f9c171fc -r e593dce9468d src/lib/iostream-temp.c
--- a/src/lib/iostream-temp.c	Mon Aug 11 15:47:57 2014 +0300
+++ b/src/lib/iostream-temp.c	Mon Aug 11 15:54:43 2014 +0300
@@ -129,8 +129,7 @@
 
 	input = i_stream_create_limit(tstream->dupstream, size);
 	do {
-		ret = io_stream_copy(&tstream->ostream.ostream,
-				     input, IO_BLOCK_SIZE);
+		ret = io_stream_copy(&tstream->ostream.ostream, input);
 	} while (input->v_offset < tstream->dupstream_offset && ret > 0);
 	if (ret < 0 && tstream->ostream.ostream.stream_errno == 0) {
 		i_assert(input->stream_errno != 0);
@@ -187,8 +186,7 @@
 			return -1;
 		outstream->flags &= ~IOSTREAM_TEMP_FLAG_TRY_FD_DUP;
 	}
-	return io_stream_copy(&outstream->ostream.ostream,
-			      instream, IO_BLOCK_SIZE);
+	return io_stream_copy(&outstream->ostream.ostream, instream);
 }
 
 static int
diff -r 0e04f9c171fc -r e593dce9468d src/lib/ostream-file.c
--- a/src/lib/ostream-file.c	Mon Aug 11 15:47:57 2014 +0300
+++ b/src/lib/ostream-file.c	Mon Aug 11 15:54:43 2014 +0300
@@ -857,8 +857,7 @@
 		}
 	}
 
-	return io_stream_copy(&outstream->ostream, instream,
-			      foutstream->optimal_block_size);
+	return io_stream_copy(&outstream->ostream, instream);
 }
 
 static off_t o_stream_file_send_istream(struct ostream_private *outstream,
diff -r 0e04f9c171fc -r e593dce9468d src/lib/ostream-private.h
--- a/src/lib/ostream-private.h	Mon Aug 11 15:47:57 2014 +0300
+++ b/src/lib/ostream-private.h	Mon Aug 11 15:54:43 2014 +0300
@@ -46,8 +46,7 @@
 o_stream_create(struct ostream_private *_stream, struct ostream *parent, int fd)
 	ATTR_NULL(2);
 
-off_t io_stream_copy(struct ostream *outstream, struct istream *instream,
-		     size_t block_size);
+off_t io_stream_copy(struct ostream *outstream, struct istream *instream);
 
 void o_stream_copy_error_from_parent(struct ostream_private *_stream);
 /* This should be called before sending data to parent stream. It makes sure
diff -r 0e04f9c171fc -r e593dce9468d src/lib/ostream.c
--- a/src/lib/ostream.c	Mon Aug 11 15:47:57 2014 +0300
+++ b/src/lib/ostream.c	Mon Aug 11 15:54:43 2014 +0300
@@ -357,8 +357,7 @@
 	return ret;
 }
 
-off_t io_stream_copy(struct ostream *outstream, struct istream *instream,
-		     size_t block_size)
+off_t io_stream_copy(struct ostream *outstream, struct istream *instream)
 {
 	uoff_t start_offset;
 	struct const_iovec iov;
@@ -366,9 +365,8 @@
 	ssize_t ret;
 
 	start_offset = instream->v_offset;
-	for (;;) {
-		(void)i_stream_read_data(instream, &data, &iov.iov_len,
-					 block_size-1);
+	do {
+		(void)i_stream_read_data(instream, &data, &iov.iov_len, 0);
 		if (iov.iov_len == 0) {
 			/* all sent */
 			break;
@@ -382,10 +380,7 @@
 			return -1;
 		}
 		i_stream_skip(instream, ret);
-
-		if ((size_t)ret != iov.iov_len)
-			break;
-	}
+	} while ((size_t)ret == iov.iov_len);
 
 	return (off_t)(instream->v_offset - start_offset);
 }
@@ -528,7 +523,7 @@
 static off_t o_stream_default_send_istream(struct ostream_private *outstream,
 					   struct istream *instream)
 {
-	return io_stream_copy(&outstream->ostream, instream, IO_BLOCK_SIZE);
+	return io_stream_copy(&outstream->ostream, instream);
 }
 
 static void o_stream_default_switch_ioloop(struct ostream_private *_stream)


More information about the dovecot-cvs mailing list