mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
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:
parent
c23550f165
commit
6690b3c7cf
@ -2126,14 +2126,21 @@ static ssize_t send_from_file(const int s, const int fd,
|
||||
{
|
||||
#ifdef __FreeBSD__
|
||||
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)
|
||||
return sent;
|
||||
if (sent == 0)
|
||||
return -1;
|
||||
else
|
||||
return sent;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else return size;
|
||||
else
|
||||
return size;
|
||||
#else
|
||||
#if defined(__linux) || defined(__sun__)
|
||||
return sendfile(s, fd, &ofs, size);
|
||||
|
Loading…
Reference in New Issue
Block a user