dovecot-2.2: lib: ostream-file checks "sendfile() not supported"...

dovecot at dovecot.org dovecot at dovecot.org
Thu Nov 13 08:02:53 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/24d2d52d5355
changeset: 18079:24d2d52d5355
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Nov 13 10:01:37 2014 +0200
description:
lib: ostream-file checks "sendfile() not supported" a bit better.
There are other reasons why stream_errno=EINVAL could have been set, at
least in theory.

diffstat:

 src/lib/ostream-file.c |  22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diffs (67 lines):

diff -r ba74ec089370 -r 24d2d52d5355 src/lib/ostream-file.c
--- a/src/lib/ostream-file.c	Thu Nov 13 09:53:35 2014 +0200
+++ b/src/lib/ostream-file.c	Thu Nov 13 10:01:37 2014 +0200
@@ -697,13 +697,16 @@
 }
 
 static off_t io_stream_sendfile(struct ostream_private *outstream,
-				struct istream *instream, int in_fd)
+				struct istream *instream, int in_fd,
+				bool *sendfile_not_supported_r)
 {
 	struct file_ostream *foutstream = (struct file_ostream *)outstream;
 	uoff_t start_offset;
 	uoff_t in_size, offset, send_size, v_offset;
 	ssize_t ret;
 
+	*sendfile_not_supported_r = FALSE;
+
 	if ((ret = i_stream_get_size(instream, TRUE, &in_size)) <= 0) {
 		outstream->ostream.stream_errno = ret == 0 ? ESPIPE :
 			instream->stream_errno;
@@ -740,9 +743,10 @@
 					break;
 				}
 			}
-
-			outstream->ostream.stream_errno = errno;
-			if (errno != EINVAL) {
+			if (errno == EINVAL)
+				*sendfile_not_supported_r = TRUE;
+			else {
+				outstream->ostream.stream_errno = errno;
 				/* close only if error wasn't because
 				   sendfile() isn't supported */
 				stream_closed(foutstream);
@@ -762,7 +766,8 @@
 		i_assert(!foutstream->file ||
 			 instream->v_offset - start_offset == in_size);
 		if (i_stream_read(instream) > 0) {
-			if (io_stream_sendfile(outstream, instream, in_fd) < 0)
+			if (io_stream_sendfile(outstream, instream, in_fd,
+					       sendfile_not_supported_r) < 0)
 				return -1;
 		}
 	}
@@ -894,17 +899,18 @@
 	bool same_stream;
 	int in_fd;
 	off_t ret;
+	bool sendfile_not_supported;
 
 	in_fd = !instream->readable_fd ? -1 : i_stream_get_fd(instream);
 	if (!foutstream->no_sendfile && in_fd != -1 &&
 	    in_fd != foutstream->fd && instream->seekable) {
-		ret = io_stream_sendfile(outstream, instream, in_fd);
-		if (ret >= 0 || outstream->ostream.stream_errno != EINVAL)
+		ret = io_stream_sendfile(outstream, instream, in_fd,
+					 &sendfile_not_supported);
+		if (ret >= 0 || !sendfile_not_supported)
 			return ret;
 
 		/* sendfile() not supported (with this fd), fallback to
 		   regular sending. */
-		outstream->ostream.stream_errno = 0;
 		foutstream->no_sendfile = TRUE;
 	}
 


More information about the dovecot-cvs mailing list