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:
@@ -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)
|
||||||
return sent;
|
if (sent == 0)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user