git: a43b745aaf4f - main - linux sendfile: Fix handling of non-blocking sockets
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 13 Nov 2024 14:16:36 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=a43b745aaf4f5bbc96875d2ab3ec9bea8024eda4
commit a43b745aaf4f5bbc96875d2ab3ec9bea8024eda4
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-11-13 14:15:47 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-11-13 14:15:47 +0000
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
---
sys/compat/linux/linux_socket.c | 7 +++++++
1 file changed, 7 insertions(+)
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)