From 0348a9c9c0114ddf83d776adc3d01ac60dfcccfc Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Fri, 25 Nov 2011 10:48:46 +0100 Subject: Implement sendfile using blocking io in asynch threads Move the command handling to outputv in preparation for header and trailer inclusion in the sendfile api. Use the standard efile communication functions for sendfile. --- erts/emulator/drivers/unix/unix_efile.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'erts/emulator/drivers/unix/unix_efile.c') diff --git a/erts/emulator/drivers/unix/unix_efile.c b/erts/emulator/drivers/unix/unix_efile.c index 5b001b3819..8b612164da 100644 --- a/erts/emulator/drivers/unix/unix_efile.c +++ b/erts/emulator/drivers/unix/unix_efile.c @@ -1471,31 +1471,24 @@ efile_fadvise(Efile_error* errInfo, int fd, Sint64 offset, #ifdef HAVE_SENDFILE int efile_sendfile(Efile_error* errInfo, int in_fd, int out_fd, - off_t *offset, size_t *count) + off_t offset, size_t *ret_nbytes) { #if defined(__linux__) || (defined(__sun) && defined(__SVR4)) - ssize_t retval = sendfile(out_fd, in_fd, offset, *count); - if (retval >= 0) { - if (retval != *count) { - *count = retval; - retval = -1; - errno = EAGAIN; - } else { - *count = retval; - } - } else if (retval == -1 && (errno == EINTR || errno == EAGAIN)) { - *count = 0; - } + ssize_t retval; + do { + retval = sendfile(out_fd, in_fd, &offset, *ret_nbytes); + } while (retval == -1 && (errno == EINTR || errno == EAGAIN)); + *ret_nbytes = retval; return check_error(retval == -1 ? -1 : 0, errInfo); #elif defined(DARWIN) - off_t len = *count; + off_t len = *ret_nbytes; int retval = sendfile(in_fd, out_fd, *offset, &len, NULL, 0); - *count = len; + *ret_nbytes = len; return check_error(retval, errInfo); #elif defined(__FreeBSD__) || defined(__DragonFly__) off_t len = 0; - int retval = sendfile(in_fd, out_fd, *offset, *count, NULL, &len, 0); - *count = len; + int retval = sendfile(in_fd, out_fd, *offset, *nbytes, NULL, &len, 0); + *nbytes = len; return check_error(retval, errInfo); #endif } -- cgit v1.2.3