diff options
author | Lukas Larsson <[email protected]> | 2011-11-09 11:52:14 +0100 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2011-12-01 14:10:02 +0100 |
commit | 54bdd9a15d2e130c76f76ca322af56b306d02078 (patch) | |
tree | 13a2f1d7c3d38291464d94b805b63a6feeeaee82 /erts/emulator/drivers/unix | |
parent | bfa81856150b59ea4578e0eef79b97ab0decb8f7 (diff) | |
download | otp-54bdd9a15d2e130c76f76ca322af56b306d02078.tar.gz otp-54bdd9a15d2e130c76f76ca322af56b306d02078.tar.bz2 otp-54bdd9a15d2e130c76f76ca322af56b306d02078.zip |
Implement blocking calls for sendfile
Move sendfile data to invoke data instead of file_descr.
Remove usage of ready_output when doing a send.
If told to send 0 bytes, file_sendfile now sends the entire file
for linux.
Diffstat (limited to 'erts/emulator/drivers/unix')
-rw-r--r-- | erts/emulator/drivers/unix/unix_efile.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/erts/emulator/drivers/unix/unix_efile.c b/erts/emulator/drivers/unix/unix_efile.c index 8b612164da..05c2f1fce9 100644 --- a/erts/emulator/drivers/unix/unix_efile.c +++ b/erts/emulator/drivers/unix/unix_efile.c @@ -1471,19 +1471,34 @@ 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 *ret_nbytes) + off_t offset, size_t *nbytes) { #if defined(__linux__) || (defined(__sun) && defined(__SVR4)) - ssize_t retval; - do { - retval = sendfile(out_fd, in_fd, &offset, *ret_nbytes); - } while (retval == -1 && (errno == EINTR || errno == EAGAIN)); - *ret_nbytes = retval; + ssize_t retval, nbytes_sent = 0; + if (*nbytes == 0) { + *nbytes = (1 << 20) - 1; + do { + retval = sendfile(out_fd, in_fd, &offset, *nbytes); + nbytes_sent += retval; + printf("retval: %d, errno: %d, offset: %d, nbytes: %d\r\n", retval, errno, offset,*nbytes); + } while ((retval == -1 && errno == EINTR) + || (retval > 0 && errno == EAGAIN)); + } else { + do { + retval = sendfile(out_fd, in_fd, &offset, *nbytes); + if (retval > 0) { + nbytes_sent += retval; + *nbytes -= retval; + } + } while ((retval == -1 && errno == EINTR) + || (*nbytes > 0 && errno == EAGAIN)); + } + *nbytes = nbytes_sent; return check_error(retval == -1 ? -1 : 0, errInfo); #elif defined(DARWIN) - off_t len = *ret_nbytes; + off_t len = *nbytes; int retval = sendfile(in_fd, out_fd, *offset, &len, NULL, 0); - *ret_nbytes = len; + *nbytes = len; return check_error(retval, errInfo); #elif defined(__FreeBSD__) || defined(__DragonFly__) off_t len = 0; |