dovecot-2.2: ostream-buffer: Allow modifying the buffer outside ...

dovecot at dovecot.org dovecot at dovecot.org
Mon Aug 11 16:32:29 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/4968b36d9ac8
changeset: 17703:4968b36d9ac8
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Aug 11 19:30:15 2014 +0300
description:
ostream-buffer: Allow modifying the buffer outside ostream, unless o_stream_seek() is used.
Now we'll just append to the end of the buffer instead of forcibly trying to
write at the offset where the last ostream write ended.

diffstat:

 src/lib/ostream-buffer.c |  13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diffs (41 lines):

diff -r 4cca68644428 -r 4968b36d9ac8 src/lib/ostream-buffer.c
--- a/src/lib/ostream-buffer.c	Mon Aug 11 19:19:45 2014 +0300
+++ b/src/lib/ostream-buffer.c	Mon Aug 11 19:30:15 2014 +0300
@@ -7,10 +7,14 @@
 struct buffer_ostream {
 	struct ostream_private ostream;
 	buffer_t *buf;
+	bool seeked;
 };
 
 static int o_stream_buffer_seek(struct ostream_private *stream, uoff_t offset)
 {
+	struct buffer_ostream *bstream = (struct buffer_ostream *)stream;
+
+	bstream->seeked = TRUE;
 	stream->ostream.offset = offset;
 	return 1;
 }
@@ -30,17 +34,18 @@
 		      const struct const_iovec *iov, unsigned int iov_count)
 {
 	struct buffer_ostream *bstream = (struct buffer_ostream *)stream;
-	size_t left, n;
+	size_t left, n, offset;
 	ssize_t ret = 0;
 	unsigned int i;
 
+	offset = bstream->seeked ? stream->ostream.offset : bstream->buf->used;
+
 	for (i = 0; i < iov_count; i++) {
 		left = bstream->ostream.max_buffer_size -
 			stream->ostream.offset;
 		n = I_MIN(left, iov[i].iov_len);
-		buffer_write(bstream->buf, stream->ostream.offset,
-			     iov[i].iov_base, n);
-		stream->ostream.offset += n;
+		buffer_write(bstream->buf, offset, iov[i].iov_base, n);
+		stream->ostream.offset += n; offset += n;
 		ret += n;
 		if (n != iov[i].iov_len)
 			break;


More information about the dovecot-cvs mailing list