aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/tcp.h
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2021-02-12 15:22:14 -0800
committerDavid S. Miller <davem@davemloft.net>2021-02-12 17:28:26 -0800
commit05dc72aba364d374a27de567fac58c199ff5ee97 (patch)
tree22d94eb4e97e02482f4528a7590f112f819a10ac /include/net/tcp.h
parenttcp: fix SO_RCVLOWAT related hangs under mem pressure (diff)
downloadlinux-dev-05dc72aba364d374a27de567fac58c199ff5ee97.tar.xz
linux-dev-05dc72aba364d374a27de567fac58c199ff5ee97.zip
tcp: factorize logic into tcp_epollin_ready()
Both tcp_data_ready() and tcp_stream_is_readable() share the same logic. Add tcp_epollin_ready() helper to avoid duplication. Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Arjun Roy <arjunroy@google.com> Cc: Wei Wang <weiwan@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/tcp.h')
-rw-r--r--include/net/tcp.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 244208f6f6c2..484eb2362645 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1442,6 +1442,18 @@ static inline bool tcp_rmem_pressure(const struct sock *sk)
return atomic_read(&sk->sk_rmem_alloc) > threshold;
}
+static inline bool tcp_epollin_ready(const struct sock *sk, int target)
+{
+ const struct tcp_sock *tp = tcp_sk(sk);
+ int avail = READ_ONCE(tp->rcv_nxt) - READ_ONCE(tp->copied_seq);
+
+ if (avail <= 0)
+ return false;
+
+ return (avail >= target) || tcp_rmem_pressure(sk) ||
+ (tcp_receive_window(tp) <= inet_csk(sk)->icsk_ack.rcv_mss);
+}
+
extern void tcp_openreq_init_rwin(struct request_sock *req,
const struct sock *sk_listener,
const struct dst_entry *dst);