From: Timo Sirainen Date: Sat, 19 Jun 2004 00:59:31 +0000 (+0300) Subject: i_stream_read_data(): don't call read() unless we have to X-Git-Tag: 1.1.alpha1~3941 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37ab3cde96bfa4bc5304c0c348fc420aec79572d;p=thirdparty%2Fdovecot%2Fcore.git i_stream_read_data(): don't call read() unless we have to --HG-- branch : HEAD --- diff --git a/src/lib/istream.c b/src/lib/istream.c index 23feaed052..aced7bbc8b 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -179,19 +179,18 @@ unsigned char *i_stream_get_modifyable_data(struct istream *stream, int i_stream_read_data(struct istream *stream, const unsigned char **data, size_t *size, size_t threshold) { - struct _istream *_stream = stream->real_stream; ssize_t ret = 0; - while (_stream->pos - _stream->skip <= threshold) { + do { + *data = i_stream_get_data(stream, size); + if (*size > threshold) + return 1; + /* we need more data */ ret = i_stream_read(stream); - if (ret < 0) - break; - } + } while (ret >= 0); - *data = i_stream_get_data(stream, size); - return *size > threshold ? 1 : - ret == -2 ? -2 : + return ret == -2 ? -2 : *size > 0 ? 0 : -1; }