If sendfile blocks and sends zero bytes, treat it as blocking and not

end-of-file.  This is a really rare corner case.
This commit is contained in:
Emil Mikulic
2006-12-13 13:55:48 +00:00
parent c23550f165
commit 6690b3c7cf

View File

@@ -2126,14 +2126,21 @@ static ssize_t send_from_file(const int s, const int fd,
{ {
#ifdef __FreeBSD__ #ifdef __FreeBSD__
off_t sent; off_t sent;
if (sendfile(fd, s, ofs, size, NULL, &sent, 0) == -1) int ret = sendfile(fd, s, ofs, size, NULL, &sent, 0);
{
/* It is possible for sendfile to send zero bytes due to a blocking
* condition. Handle this correctly.
*/
if (ret == -1)
if (errno == EAGAIN) if (errno == EAGAIN)
if (sent == 0)
return -1;
else
return sent; return sent;
else else
return -1; return -1;
} else
else return size; return size;
#else #else
#if defined(__linux) || defined(__sun__) #if defined(__linux) || defined(__sun__)
return sendfile(s, fd, &ofs, size); return sendfile(s, fd, &ofs, size);