From 314ec086f3a015f97cc5dafc3038b3bf782d92af Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Nov 2004 22:05:59 +0000 Subject: r3944: Fix the problem we get on Linux where sendfile fails, but we've already sent the header using send(). As our implementation of sendfile can't return EINTR (it restarts in that case) use an errno of EINTR to signal the linux sendfile fail after header case. When that happens send the rest of the data and then turn off sendfile. Sendfile should be safe to enable on all systems now (even though it may not help in all performance cases). Jeremy. (This used to be commit 78236382f7ffe08d7924907be49493779521837f) --- source3/lib/sendfile.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/sendfile.c b/source3/lib/sendfile.c index 4aa76a0c74..75fb635fa2 100644 --- a/source3/lib/sendfile.c +++ b/source3/lib/sendfile.c @@ -65,8 +65,20 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T of nwritten = sendfile(tofd, fromfd, &offset, total); #endif } while (nwritten == -1 && errno == EINTR); - if (nwritten == -1) + if (nwritten == -1) { + if (errno == ENOSYS) { + /* Ok - we're in a world of pain here. We just sent + * the header, but the sendfile failed. We have to + * emulate the sendfile at an upper layer before we + * disable it's use. So we do something really ugly. + * We set the errno to a strange value so we can detect + * this at the upper level and take care of it without + * layer violation. JRA. + */ + errno = EINTR; /* Normally we can never return this. */ + } return -1; + } if (nwritten == 0) return -1; /* I think we're at EOF here... */ total -= nwritten; @@ -131,8 +143,20 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T of do { nwritten = sendfile(tofd, fromfd, &small_offset, small_total); } while (nwritten == -1 && errno == EINTR); - if (nwritten == -1) + if (nwritten == -1) { + if (errno == ENOSYS) { + /* Ok - we're in a world of pain here. We just sent + * the header, but the sendfile failed. We have to + * emulate the sendfile at an upper layer before we + * disable it's use. So we do something really ugly. + * We set the errno to a strange value so we can detect + * this at the upper level and take care of it without + * layer violation. JRA. + */ + errno = EINTR; /* Normally we can never return this. */ + } return -1; + } if (nwritten == 0) return -1; /* I think we're at EOF here... */ small_total -= nwritten; -- cgit