Mercurial > dovecot > core-2.2
changeset 3618:a16f27ce2eda HEAD
Changed iov_count to be unsigned int, it's large enough. Added overflow-flag
which gets sent if send() failed to both send and buffer the given data.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 25 Sep 2005 13:49:03 +0300 |
parents | 904849549eac |
children | 86ddbe18538c |
files | src/lib/ostream-file.c src/lib/ostream-internal.h src/lib/ostream.c src/lib/ostream.h |
diffstat | 4 files changed, 21 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/ostream-file.c Sun Sep 25 13:44:04 2005 +0300 +++ b/src/lib/ostream-file.c Sun Sep 25 13:49:03 2005 +0300 @@ -420,10 +420,11 @@ } static ssize_t _sendv(struct _ostream *stream, const struct const_iovec *iov, - size_t iov_count) + unsigned int iov_count) { struct file_ostream *fstream = (struct file_ostream *)stream; - size_t i, size, added, optimal_size; + size_t size, added, optimal_size; + unsigned int i; ssize_t ret = 0; stream->ostream.stream_errno = 0; @@ -431,7 +432,7 @@ for (i = 0, size = 0; i < iov_count; i++) size += iov[i].iov_len; - if (size > get_unused_space(fstream)) { + if (size > get_unused_space(fstream) && !IS_STREAM_EMPTY(fstream)) { if (_flush(stream) < 0) return -1; }
--- a/src/lib/ostream-internal.h Sun Sep 25 13:44:04 2005 +0300 +++ b/src/lib/ostream-internal.h Sun Sep 25 13:49:03 2005 +0300 @@ -15,7 +15,7 @@ size_t (*get_used_size)(struct _ostream *stream); int (*seek)(struct _ostream *stream, uoff_t offset); ssize_t (*sendv)(struct _ostream *stream, const struct const_iovec *iov, - size_t iov_count); + unsigned int iov_count); off_t (*send_istream)(struct _ostream *outstream, struct istream *instream);
--- a/src/lib/ostream.c Sun Sep 25 13:44:04 2005 +0300 +++ b/src/lib/ostream.c Sun Sep 25 13:49:03 2005 +0300 @@ -101,14 +101,23 @@ } ssize_t o_stream_sendv(struct ostream *stream, const struct const_iovec *iov, - size_t iov_count) + unsigned int iov_count) { struct _ostream *_stream = stream->real_stream; + unsigned int i; + size_t total_size; + ssize_t ret; if (stream->closed) return -1; - return _stream->sendv(_stream, iov, iov_count); + for (i = 0, total_size = 0; i < iov_count; i++) + total_size += iov[i].iov_len; + + ret = _stream->sendv(_stream, iov, iov_count); + if (ret != (ssize_t)total_size) + stream->overflow = TRUE; + return ret; } ssize_t o_stream_send_str(struct ostream *stream, const char *str)
--- a/src/lib/ostream.h Sun Sep 25 13:44:04 2005 +0300 +++ b/src/lib/ostream.h Sun Sep 25 13:49:03 2005 +0300 @@ -7,6 +7,10 @@ uoff_t offset; int stream_errno; + /* overflow is set when some of the data given to send() + functions was neither sent nor buffered. It's never unset inside + ostream code. */ + unsigned int overflow:1; unsigned int closed:1; struct _ostream *real_stream; @@ -58,7 +62,7 @@ /* Returns number of bytes sent, -1 = error */ ssize_t o_stream_send(struct ostream *stream, const void *data, size_t size); ssize_t o_stream_sendv(struct ostream *stream, const struct const_iovec *iov, - size_t iov_count); + unsigned int iov_count); ssize_t o_stream_send_str(struct ostream *stream, const char *str); /* Send data from input stream. Returns number of bytes sent, or -1 if error. Note that this function may block if either instream or outstream is