From: Eric Dumazet edumazet@google.com
mainline inclusion from mainline-v5.17-rc1 commit 8bd172b787298124ef75c0e466101107c036d54d category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I65HYE
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
---------------------------
Testing timeo before sk_err/sk_state/sk_shutdown makes more sense.
Modern applications use non-blocking IO, while a socket is terminated only once during its life time.
Signed-off-by: Eric Dumazet edumazet@google.com Signed-off-by: David S. Miller davem@davemloft.net (cherry picked from commit 8bd172b787298124ef75c0e466101107c036d54d) Signed-off-by: Liu Jian liujian56@huawei.com --- net/ipv4/tcp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index e1cc494b5c78e..dcbc5ec00da87 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2215,10 +2215,10 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock, break;
if (copied) { - if (sk->sk_err || + if (!timeo || + sk->sk_err || sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN) || - !timeo || signal_pending(current)) break; } else {