]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: io_stream_copy() no longer attempts to read full block sizes from input.
authorTimo Sirainen <tss@iki.fi>
Mon, 11 Aug 2014 12:54:43 +0000 (15:54 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 11 Aug 2014 12:54:43 +0000 (15:54 +0300)
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.

src/lib/iostream-temp.c
src/lib/ostream-file.c
src/lib/ostream-private.h
src/lib/ostream.c

index 06245a6faf4541bcd39261baebd9cbcba7523784..e671b5c5313f017e5ed80e30fa40f9dea920d97d 100644 (file)
@@ -129,8 +129,7 @@ static int o_stream_temp_dup_cancel(struct temp_ostream *tstream)
 
        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 @@ static off_t o_stream_temp_send_istream(struct ostream_private *_outstream,
                        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
index ca01f80f27b420b25751320003dc34d401c0b17f..b7d19a72079f8d8731f0919ee959af44d88f3e22 100644 (file)
@@ -857,8 +857,7 @@ static off_t io_stream_copy_stream(struct ostream_private *outstream,
                }
        }
 
-       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,
index 7991529ab8b0fc84d388f57fb50be6813ebcfdea..a2e39c3b3a4dbd8cc8b7776b757c769475f17ca6 100644 (file)
@@ -46,8 +46,7 @@ struct ostream *
 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
index 7c02976477ff9d5c4e1ecb1d5423555d44bf8ee8..23ccb18509fb103c1c72ecf0e69e76a35e8f8a1b 100644 (file)
@@ -357,8 +357,7 @@ int o_stream_pwrite(struct ostream *stream, const void *data, size_t size,
        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 @@ off_t io_stream_copy(struct ostream *outstream, struct istream *instream,
        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 @@ off_t io_stream_copy(struct ostream *outstream, struct istream *instream,
                        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 @@ o_stream_default_write_at(struct ostream_private *_stream,
 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)