Better sendfile / zerocopy detection.

There's still a bunch of OS-dependent fu because every platform that
supports sendfile(2) does it differently.
This commit is contained in:
Bruce A. Mah 2014-04-14 14:16:07 -07:00
parent 3e9b0eb334
commit 3f8c33cd76
No known key found for this signature in database
GPG Key ID: 4984910A8CAAEE8A
3 changed files with 25 additions and 12 deletions

View File

@ -84,4 +84,9 @@ AC_CHECK_FUNCS([cpuset_setaffinity sched_setaffinity],
AC_DEFINE([HAVE_CPU_AFFINITY], [1],
[Have CPU affinity support.]))
# Check for sendfile support. FreeBSD, Linux, and MacOS all support
# this system call, but they're all different in terms of what headers
# it needs and what arguments it expects.
AC_CHECK_FUNCS([sendfile])
AC_OUTPUT([Makefile src/Makefile examples/Makefile])

View File

@ -258,6 +258,16 @@ get_optional_features(void)
numfeatures++;
#endif /* HAVE_TCP_CONGESTION */
#if defined(HAVE_SENDFILE)
if (numfeatures > 0) {
strncat(features, ", ",
sizeof(features) - strlen(features) - 1);
}
strncat(features, "sendfile / zerocopy",
sizeof(features) - strlen(features) - 1);
numfeatures++;
#endif /* HAVE_SENDFILE */
if (numfeatures == 0) {
strncat(features, "None",
sizeof(features) - strlen(features) - 1);

View File

@ -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
#if defined(HAS_SENDFILE)
return 1;
#else
#ifdef __FreeBSD__
return 1;
#else
#if defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_6) /* OS X */
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: