aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2024-11-13 14:15:47 +0000
committerMark Johnston <markj@FreeBSD.org>2024-11-13 14:15:47 +0000
commita43b745aaf4f5bbc96875d2ab3ec9bea8024eda4 (patch)
tree192f7c3b75b9b9ccf3ac8b1fde04652a26932dc3
parent0a897e67548156ed731dae68eafd21728894ef91 (diff)
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
-rw-r--r--sys/compat/linux/linux_socket.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c
index 15431bf3127c..6c6751ad30a8 100644
--- a/sys/compat/linux/linux_socket.c
+++ b/sys/compat/linux/linux_socket.c
@@ -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)