diff mbox series

[2/5] tcp: handle SPLICE_F_NONBLOCK in tcp_splice_read

Message ID 20190511165727.31599-2-source@stbuehler.de (mailing list archive)
State RFC
Headers show
Series [1/5] fs: RWF flags override default IOCB flags from file flags | expand

Commit Message

Stefan Bühler May 11, 2019, 4:57 p.m. UTC
Now both O_NONBLOCK and SPLICE_F_NONBLOCK will trigger non-blocking
behavior.

The spice man page is unclear about the exact semantics:

First it says splice may still block if SPLICE_F_NONBLOCK is set but
O_NONBLOCK isn't.

Then it says it might return EAGAIN if one or the other is set (and on
my debian system it says EAGAIN can only be returned if
SPLICE_F_NONBLOCK was set).

Signed-off-by: Stefan Bühler <source@stbuehler.de>
---
 net/ipv4/tcp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 6baa6dc1b13b..65f9917ed8ca 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -784,6 +784,8 @@  ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
 	long timeo;
 	ssize_t spliced;
 	int ret;
+	bool noblock = (sock->file->f_flags & O_NONBLOCK) ||
+		       (flags & SPLICE_F_NONBLOCK);
 
 	sock_rps_record_flow(sk);
 	/*
@@ -796,7 +798,7 @@  ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
 
 	lock_sock(sk);
 
-	timeo = sock_rcvtimeo(sk, sock->file->f_flags & O_NONBLOCK);
+	timeo = sock_rcvtimeo(sk, noblock);
 	while (tss.len) {
 		ret = __tcp_splice_read(sk, &tss);
 		if (ret < 0)