aboutsummaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
authorBruce A. Mah <bmah@es.net>2014-04-14 14:16:07 -0700
committerBruce A. Mah <bmah@es.net>2014-04-14 14:16:07 -0700
commit3f8c33cd766934e0eebb8f4c753cd9c034fa25b4 (patch)
treeb0c1bec7da28d49df87a4a2f3646a32d317f351d /src/net.c
parent3e9b0eb334781971dca88bf975ef1a63fb307a67 (diff)
downloadiperf3-3f8c33cd766934e0eebb8f4c753cd9c034fa25b4.tar.gz
Better sendfile / zerocopy detection.
There's still a bunch of OS-dependent fu because every platform that supports sendfile(2) does it differently.
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/net.c b/src/net.c
index 8a24154..9b5ba3d 100644
--- a/src/net.c
+++ b/src/net.c
@@ -1,11 +1,12 @@
/*
- * Copyright (c) 2009-2011, The Regents of the University of California,
+ * Copyright (c) 2009-2014, The Regents of the University of California,
* through Lawrence Berkeley National Laboratory (subject to receipt of any
* required approvals from the U.S. Dept. of Energy). All rights reserved.
*
* This code is distributed under a BSD style license, see the LICENSE file
* for complete information.
*/
+#include "iperf_config.h"
#include <stdio.h>
#include <unistd.h>
@@ -20,6 +21,7 @@
#include <string.h>
#include <sys/fcntl.h>
+#ifdef HAVE_SENDFILE
#ifdef linux
#include <sys/sendfile.h>
#else
@@ -34,6 +36,7 @@
#endif
#endif
#endif
+#endif HAVE_SENDFILE
#include "iperf_util.h"
#include "net.h"
@@ -218,19 +221,12 @@ Nwrite(int fd, const char *buf, size_t count, int prot)
int
has_sendfile(void)
{
-#ifdef linux
- return 1;
-#else
-#ifdef __FreeBSD__
- return 1;
-#else
-#if defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_6) /* OS X */
+#if defined(HAS_SENDFILE)
return 1;
-#else
+#else /* HAS_SENDFILE */
return 0;
-#endif
-#endif
-#endif
+#endif /* HAS_SENDFILE */
+
}
@@ -242,6 +238,7 @@ int
Nsendfile(int fromfd, int tofd, const char *buf, size_t count)
{
off_t offset;
+#if defined(HAVE_SENDFILE)
#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_6))
off_t sent;
#endif
@@ -271,6 +268,7 @@ Nsendfile(int fromfd, int tofd, const char *buf, size_t count)
#endif
#endif
#endif
+#endif /* HAVE_SENDFILE */
if (r < 0) {
switch (errno) {
case EINTR: