dovecot: If we do multiple writev() calls and the last one fails...

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 9 21:26:05 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/28b9873da2cc
changeset: 6254:28b9873da2cc
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Aug 09 21:26:02 2007 +0300
description:
If we do multiple writev() calls and the last one fails, we shouldn't treat
all of it as a failure because some data was already sent. Also added some
more asserts.

diffstat:

1 file changed, 9 insertions(+), 3 deletions(-)
src/lib/ostream-file.c |   12 +++++++++---

diffs (55 lines):

diff -r f108845caaa1 -r 28b9873da2cc src/lib/ostream-file.c
--- a/src/lib/ostream-file.c	Thu Aug 09 21:03:20 2007 +0300
+++ b/src/lib/ostream-file.c	Thu Aug 09 21:26:02 2007 +0300
@@ -203,6 +203,8 @@ static ssize_t o_stream_writev(struct fi
 		if (ret > 0) {
 			fstream->real_offset += ret;
 			ret += sent;
+		} else {
+			ret = sent;
 		}
 	}
 
@@ -461,7 +463,7 @@ static ssize_t _sendv(struct _ostream *s
 		      unsigned int iov_count)
 {
 	struct file_ostream *fstream = (struct file_ostream *)stream;
-	size_t size, added, optimal_size;
+	size_t size, total_size, added, optimal_size;
 	unsigned int i;
 	ssize_t ret = 0;
 
@@ -469,6 +471,7 @@ static ssize_t _sendv(struct _ostream *s
 
 	for (i = 0, size = 0; i < iov_count; i++)
 		size += iov[i].iov_len;
+	total_size = size;
 
 	if (size > get_unused_space(fstream) && !IS_STREAM_EMPTY(fstream)) {
 		if (_flush(stream) < 0)
@@ -485,13 +488,15 @@ static ssize_t _sendv(struct _ostream *s
 			return -1;
 
 		size = ret;
-		while (size > 0 && size >= iov[0].iov_len) {
+		while (size > 0 && iov_count > 0 && size >= iov[0].iov_len) {
 			size -= iov[0].iov_len;
 			iov++;
 			iov_count--;
 		}
 
-		if (iov_count > 0) {
+		if (iov_count == 0)
+			i_assert(size == 0);
+		else {
 			added = o_stream_add(fstream,
 					CONST_PTR_OFFSET(iov[0].iov_base, size),
 					iov[0].iov_len - size);
@@ -516,6 +521,7 @@ static ssize_t _sendv(struct _ostream *s
 			break;
 	}
 	stream->ostream.offset += ret;
+	i_assert(ret < (ssize_t)total_size);
 	return ret;
 }
 


More information about the dovecot-cvs mailing list