aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/drivers/unix/unix_efile.c
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2011-11-11 16:19:07 +0100
committerLukas Larsson <[email protected]>2011-12-01 14:10:03 +0100
commit020e988424cf0d15ebab8de50638492defb6f2b5 (patch)
treea953bbef07196e93619fd7b57c2d6f2783a993b9 /erts/emulator/drivers/unix/unix_efile.c
parent54bdd9a15d2e130c76f76ca322af56b306d02078 (diff)
downloadotp-020e988424cf0d15ebab8de50638492defb6f2b5.tar.gz
otp-020e988424cf0d15ebab8de50638492defb6f2b5.tar.bz2
otp-020e988424cf0d15ebab8de50638492defb6f2b5.zip
Implement sendfile when there are no async threads
When there are no async threads sendfile will use the ready_output select on the socket fd to know when to send data. The file_desc will also be put in the sending sendfile_state which buffers all other commands to that file until the sendfile is done.
Diffstat (limited to 'erts/emulator/drivers/unix/unix_efile.c')
-rw-r--r--erts/emulator/drivers/unix/unix_efile.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/erts/emulator/drivers/unix/unix_efile.c b/erts/emulator/drivers/unix/unix_efile.c
index 05c2f1fce9..3a966757d9 100644
--- a/erts/emulator/drivers/unix/unix_efile.c
+++ b/erts/emulator/drivers/unix/unix_efile.c
@@ -1469,31 +1469,27 @@ efile_fadvise(Efile_error* errInfo, int fd, Sint64 offset,
}
#ifdef HAVE_SENDFILE
+#define SENDFILE_CHUNK_SIZE ((1 << 30) - 1)
int
efile_sendfile(Efile_error* errInfo, int in_fd, int out_fd,
- off_t offset, size_t *nbytes)
+ off_t *offset, size_t *nbytes)
{
#if defined(__linux__) || (defined(__sun) && defined(__SVR4))
- ssize_t retval, nbytes_sent = 0;
+ ssize_t retval, written = 0;
+ // printf("sendfile(%d,%d,%d,%d)\r\n",out_fd,in_fd,*offset,*nbytes);
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));
+ *nbytes = SENDFILE_CHUNK_SIZE; // chunk size
+ retval = sendfile(out_fd, in_fd, offset, *nbytes);
+ if (retval > 0)
+ written += retval;
+ } while (retval == SENDFILE_CHUNK_SIZE);
} 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));
+ retval = sendfile(out_fd, in_fd, offset, *nbytes);
+ if (retval > 0)
+ written = retval;
}
- *nbytes = nbytes_sent;
+ *nbytes = written;
return check_error(retval == -1 ? -1 : 0, errInfo);
#elif defined(DARWIN)
off_t len = *nbytes;