dovecot-1.1: safe_sendfile(): Error handling fixes for Linux and...

dovecot at dovecot.org dovecot at dovecot.org
Tue May 19 20:37:51 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.1/rev/1bc39800415d
changeset: 8278:1bc39800415d
user:      Timo Sirainen <tss at iki.fi>
date:      Tue May 19 13:34:54 2009 -0400
description:
safe_sendfile(): Error handling fixes for Linux and Solaris.

diffstat:

1 file changed, 6 insertions(+), 6 deletions(-)
src/lib/sendfile-util.c |   12 ++++++------

diffs (30 lines):

diff -r a352a1e26086 -r 1bc39800415d src/lib/sendfile-util.c
--- a/src/lib/sendfile-util.c	Mon May 18 02:41:10 2009 -0400
+++ b/src/lib/sendfile-util.c	Tue May 19 13:34:54 2009 -0400
@@ -49,12 +49,8 @@ ssize_t safe_sendfile(int out_fd, int in
 
 	safe_offset = (off_t)*offset;
 	ret = sendfile(out_fd, in_fd, &safe_offset, count);
+	/* ret=0 : trying to read past EOF, errno = EPIPE : remote is gone */
 	*offset = (uoff_t)safe_offset;
-
-	if (ret == 0) {
-		errno = EPIPE;
-		ret = -1;
-	}
 	return ret;
 }
 
@@ -116,7 +112,11 @@ ssize_t safe_sendfile(int out_fd, int in
 	ret = sendfile(out_fd, in_fd, &s_offset, count);
 
 	if (ret < 0) {
-		if (errno == EAFNOSUPPORT) {
+		/* if remote is gone, EPIPE is returned */
+		if (errno == EINVAL) {
+			/* most likely trying to read past EOF */
+			ret = 0;
+		} else if (errno == EAFNOSUPPORT) {
 			/* not supported, return Linux-like EINVAL so caller
 			   sees only consistent errnos. */
 			errno = EINVAL;


More information about the dovecot-cvs mailing list