1
1

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.
Этот коммит содержится в:
Brian Candler 2014-12-22 10:38:59 +00:00
родитель fab3e1dd85
Коммит 588ee5223e

Просмотреть файл

@ -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 */
}