Solaris sendfile: correctly detect amount of data sent

Original message:

   Solaris sendfile seems to fail when sending moderately large (<1GB)
   files. Not a 32/64 problem, but a buffer problem.

   Anyone else ever try this? It is definitely broken in http-server.c.

   It seems to be broken in the following way:

   When sendfile sends partial data (EAGAIN, would block), "res" is
   always -1, rather than the amount sent.

   Here's a patch that reads from the "offset" pointer instead to
   discover what was sent. This seems to work:
This commit is contained in:
Michael Herf 2011-08-15 13:39:10 -04:00 committed by Nick Mathewson
parent aff6ba15a1
commit 643922e907

View File

@ -2267,12 +2267,18 @@ evbuffer_write_sendfile(struct evbuffer *buffer, evutil_socket_t fd,
}
return (res);
#elif defined(SENDFILE_IS_SOLARIS)
res = sendfile(fd, info->fd, &offset, chain->off);
if (res == -1 && EVUTIL_ERR_RW_RETRIABLE(errno)) {
/* if this is EAGAIN or EINTR return 0; otherwise, -1 */
return (0);
{
const off_t offset_orig = offset;
res = sendfile(fd, info->fd, &offset, chain->off);
if (res == -1 && EVUTIL_ERR_RW_RETRIABLE(errno)) {
if (offset - offset_orig)
return offset - offset_orig;
/* if this is EAGAIN or EINTR and no bytes were
* written, return 0 */
return (0);
}
return (res);
}
return (res);
#endif
}
#endif