Merge pull request #231 from candlerb/candlerb-sendfile-stats

Fix calculation of sendfile throughput on OSX and FreeBSD.
This commit is contained in:
Bruce A. Mah 2015-01-02 09:54:34 -08:00
commit c0f4fa6ac0

View File

@ -302,23 +302,19 @@ Nsendfile(int fromfd, int tofd, const char *buf, size_t count)
offset = count - nleft;
#ifdef linux
r = sendfile(tofd, fromfd, &offset, nleft);
#else
#ifdef __FreeBSD__
if (r > 0)
nleft -= r;
#elif defined(__FreeBSD__)
r = sendfile(fromfd, tofd, offset, nleft, NULL, &sent, 0);
if (r == 0)
r = sent;
#else
#if defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_6) /* OS X */
nleft -= sent;
#elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_6) /* OS X */
sent = nleft;
r = sendfile(fromfd, tofd, offset, &sent, NULL, 0);
if (r == 0)
r = sent;
nleft -= sent;
#else
/* Shouldn't happen. */
r = -1;
errno = ENOSYS;
#endif
#endif
#endif
if (r < 0) {
switch (errno) {
@ -333,14 +329,16 @@ Nsendfile(int fromfd, int tofd, const char *buf, size_t count)
default:
return NET_HARDERROR;
}
} else if (r == 0)
}
#ifdef linux
else if (r == 0)
return NET_SOFTERROR;
nleft -= r;
#endif
}
return count;
#else /* HAVE_SENDFILE */
errno = ENOSYS; /* error if somehow get called without HAVE_SENDFILE */
return -1;
return NET_HARDERROR;
#endif /* HAVE_SENDFILE */
}