Fix calculation of sendfile throughput on OSX
Note that sendfile can return -1 for EINTR whilst having already sent partial results; these were not being counted previously.
This commit is contained in:
parent
fab3e1dd85
commit
588ee5223e
24
src/net.c
24
src/net.c
@ -302,23 +302,19 @@ Nsendfile(int fromfd, int tofd, const char *buf, size_t count)
|
|||||||
offset = count - nleft;
|
offset = count - nleft;
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
r = sendfile(tofd, fromfd, &offset, nleft);
|
r = sendfile(tofd, fromfd, &offset, nleft);
|
||||||
#else
|
if (r > 0)
|
||||||
#ifdef __FreeBSD__
|
nleft -= r;
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
r = sendfile(fromfd, tofd, offset, nleft, NULL, &sent, 0);
|
r = sendfile(fromfd, tofd, offset, nleft, NULL, &sent, 0);
|
||||||
if (r == 0)
|
nleft -= sent;
|
||||||
r = sent;
|
#elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_6) /* OS X */
|
||||||
#else
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_6) /* OS X */
|
|
||||||
sent = nleft;
|
sent = nleft;
|
||||||
r = sendfile(fromfd, tofd, offset, &sent, NULL, 0);
|
r = sendfile(fromfd, tofd, offset, &sent, NULL, 0);
|
||||||
if (r == 0)
|
nleft -= sent;
|
||||||
r = sent;
|
|
||||||
#else
|
#else
|
||||||
/* Shouldn't happen. */
|
/* Shouldn't happen. */
|
||||||
r = -1;
|
r = -1;
|
||||||
errno = ENOSYS;
|
errno = ENOSYS;
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
@ -333,14 +329,16 @@ Nsendfile(int fromfd, int tofd, const char *buf, size_t count)
|
|||||||
default:
|
default:
|
||||||
return NET_HARDERROR;
|
return NET_HARDERROR;
|
||||||
}
|
}
|
||||||
} else if (r == 0)
|
}
|
||||||
|
#ifdef linux
|
||||||
|
else if (r == 0)
|
||||||
return NET_SOFTERROR;
|
return NET_SOFTERROR;
|
||||||
nleft -= r;
|
#endif
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
#else /* HAVE_SENDFILE */
|
#else /* HAVE_SENDFILE */
|
||||||
errno = ENOSYS; /* error if somehow get called without HAVE_SENDFILE */
|
errno = ENOSYS; /* error if somehow get called without HAVE_SENDFILE */
|
||||||
return -1;
|
return NET_HARDERROR;
|
||||||
#endif /* HAVE_SENDFILE */
|
#endif /* HAVE_SENDFILE */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user