Commit a8688821 authored by Cong Wang's avatar Cong Wang Committed by Jakub Kicinski

tcp: refactor tcp_read_skb() a bit

As tcp_read_skb() only reads one skb at a time, the while loop is
unnecessary, we can turn it into an if. This also simplifies the
code logic.

Cc: Eric Dumazet <edumazet@google.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: default avatarCong Wang <cong.wang@bytedance.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c457985a
......@@ -1761,25 +1761,17 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
if (sk->sk_state == TCP_LISTEN)
return -ENOTCONN;
while ((skb = tcp_recv_skb(sk, seq, &offset)) != NULL) {
int used;
skb = tcp_recv_skb(sk, seq, &offset);
if (!skb)
return 0;
__skb_unlink(skb, &sk->sk_receive_queue);
WARN_ON(!skb_set_owner_sk_safe(skb, sk));
used = recv_actor(sk, skb);
if (used <= 0) {
if (!copied)
copied = used;
break;
}
seq += used;
copied += used;
if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) {
copied = recv_actor(sk, skb);
if (copied > 0) {
seq += copied;
if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
++seq;
break;
}
break;
}
consume_skb(skb);
WRITE_ONCE(tp->copied_seq, seq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment