aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/drivers
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2011-12-02 17:13:49 +0100
committerLukas Larsson <[email protected]>2011-12-05 19:39:40 +0100
commit250a556b1e3eb8486ec294f94d3b918c9ac91542 (patch)
treec3d8795be62b7b349aae6aec92f6f8d1583415db /erts/emulator/drivers
parent62fffa75e2003b3f19eb7614307942028a400fd1 (diff)
downloadotp-250a556b1e3eb8486ec294f94d3b918c9ac91542.tar.gz
otp-250a556b1e3eb8486ec294f94d3b918c9ac91542.tar.bz2
otp-250a556b1e3eb8486ec294f94d3b918c9ac91542.zip
Make solaris use sendfilev
sendfilev is a richer API which allows us to do non blocking TCP on solaris. The normal sendfile API seems to have some issue with non blocking sockets and the return value of sendfile.
Diffstat (limited to 'erts/emulator/drivers')
-rw-r--r--erts/emulator/drivers/common/erl_efile.h5
-rw-r--r--erts/emulator/drivers/unix/unix_efile.c24
2 files changed, 28 insertions, 1 deletions
diff --git a/erts/emulator/drivers/common/erl_efile.h b/erts/emulator/drivers/common/erl_efile.h
index 349ab0e17b..ed8910a8b8 100644
--- a/erts/emulator/drivers/common/erl_efile.h
+++ b/erts/emulator/drivers/common/erl_efile.h
@@ -67,6 +67,11 @@
#define FILENAMES_16BIT 1
#endif
+// We use sendfilev if it exist on solaris
+#if !defined(HAVE_SENDFILE) && defined(HAVE_SENDFILEV)
+#define HAVE_SENDFILE
+#endif
+
/*
* An handle to an open directory. To be cast to the correct type
* in the system-dependent directory functions.
diff --git a/erts/emulator/drivers/unix/unix_efile.c b/erts/emulator/drivers/unix/unix_efile.c
index 72911641d3..2b68334ad7 100644
--- a/erts/emulator/drivers/unix/unix_efile.c
+++ b/erts/emulator/drivers/unix/unix_efile.c
@@ -1488,7 +1488,7 @@ efile_sendfile(Efile_error* errInfo, int in_fd, int out_fd,
off_t *offset, Uint64 *nbytes, struct t_sendfile_hdtl* hdtl)
{
Uint64 written = 0;
-#if defined(__linux__) || (defined(__sun) && defined(__SVR4))
+#if defined(__linux__)
ssize_t retval;
do {
// check if *nbytes is 0 or greater than the largest size_t
@@ -1503,6 +1503,28 @@ efile_sendfile(Efile_error* errInfo, int in_fd, int out_fd,
} while (retval != -1 && retval == SENDFILE_CHUNK_SIZE);
*nbytes = written;
return check_error(retval == -1 ? -1 : 0, errInfo);
+#elif defined(__sun) && defined(__SVR4) && defined(HAVE_SENDFILEV)
+ ssize_t retval;
+ size_t len;
+ sendfilevec_t fdrec;
+ fdrec.sfv_fd = in_fd;
+ fdrec.sfv_flag = SFV_NOWAIT;
+ do {
+ fdrec.sfv_off = *offset;
+ len = 0;
+ if (*nbytes == 0 || *nbytes > SENDFILE_CHUNK_SIZE)
+ fdrec.sfv_len = SENDFILE_CHUNK_SIZE;
+ else
+ fdrec.sfv_len = *nbytes;
+ retval = sendfilev(out_fd, &fdrec, 1, &len);
+ if (retval != -1 || errno == EAGAIN || errno == EINTR) {
+ *offset += len;
+ *nbytes -= len;
+ written += len;
+ }
+ } while (len == SENDFILE_CHUNK_SIZE);
+ *nbytes = written;
+ return check_error(retval == -1 ? -1 : 0, errInfo);
#elif defined(DARWIN)
int retval;
off_t len;