From 07a8b16dfd661154dcbfdd11492b1238af65f751 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 8 Feb 2003 15:53:07 +0200 Subject: [PATCH] Don't bother trying sendfile() more than once with the stream. --HG-- branch : HEAD --- src/lib/ostream-file.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/ostream-file.c b/src/lib/ostream-file.c index de7f4f9dfb..1f75058874 100644 --- a/src/lib/ostream-file.c +++ b/src/lib/ostream-file.c @@ -64,6 +64,7 @@ struct file_ostream { unsigned int full:1; /* if head == tail, is buffer empty or full? */ unsigned int corked:1; unsigned int no_socket_cork:1; + unsigned int no_sendfile:1; unsigned int autoclose_fd:1; }; @@ -641,6 +642,7 @@ static off_t io_stream_copy(struct _ostream *outstream, static off_t _send_istream(struct _ostream *outstream, struct istream *instream) { + struct file_ostream *foutstream = (struct file_ostream *) outstream; off_t ret; i_assert(instream->v_limit <= OFF_T_MAX); @@ -649,14 +651,17 @@ static off_t _send_istream(struct _ostream *outstream, struct istream *instream) if (instream->v_offset == instream->v_limit) return 0; - ret = io_stream_sendfile(outstream, instream); - if (ret >= 0 || outstream->ostream.stream_errno != EINVAL) - return ret; + if (!foutstream->no_sendfile) { + ret = io_stream_sendfile(outstream, instream); + if (ret >= 0 || outstream->ostream.stream_errno != EINVAL) + return ret; - /* sendfile() not supported (with this fd), fallback to - regular sending */ + /* sendfile() not supported (with this fd), fallback to + regular sending */ + outstream->ostream.stream_errno = 0; + foutstream->no_sendfile = TRUE; + } - outstream->ostream.stream_errno = 0; return io_stream_copy(outstream, instream); } -- 2.47.3