linux sendfile: Fix handling of non-blocking sockets

FreeBSD sendfile() may perform a partial transfer and return EAGAIN if
the socket is non-blocking.  Linux sendfile() expects no error in this
case, so squash EAGAIN.

PR:		282495
Tested by:	pieter@krikkit.xyz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D47447
This commit is contained in:
Mark Johnston 2024-11-13 14:15:47 +00:00
parent 0a897e6754
commit a43b745aaf

View file

@ -2538,6 +2538,13 @@ sendfile_sendfile(struct thread *td, struct file *fp, l_int out,
current_offset = *offset;
error = fo_sendfile(fp, out, NULL, NULL, current_offset, count,
sbytes, 0, td);
if (error == EAGAIN && *sbytes > 0) {
/*
* The socket is non-blocking and we didn't finish sending.
* Squash the error, since that's what Linux does.
*/
error = 0;
}
if (error == 0) {
current_offset += *sbytes;
if (offset != NULL)