dovecot-1.0: If we do multiple writev() calls and the last one f...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Aug 9 21:26:07 EEST 2007
details: http://hg.dovecot.org/dovecot-1.0/rev/bd113e9fe67b
changeset: 5380:bd113e9fe67b
user: Timo Sirainen <tss at iki.fi>
date: Thu Aug 09 21:26:01 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 7f620247ac5a -r bd113e9fe67b src/lib/ostream-file.c
--- a/src/lib/ostream-file.c Thu Aug 09 21:02:51 2007 +0300
+++ b/src/lib/ostream-file.c Thu Aug 09 21:26:01 2007 +0300
@@ -152,6 +152,8 @@ static ssize_t o_stream_writev(struct fi
}
if (ret > 0)
ret += sent;
+ else if (sent > 0)
+ ret = sent;
}
if (ret < 0) {
@@ -421,7 +423,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;
@@ -429,6 +431,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)
@@ -445,13 +448,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);
@@ -476,6 +481,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