History

tcp: Add tcp_inq to get available receive bytes on socket

Create a common kernel function to get the number of bytes available on a TCP socket. This is based on code in INQ getsockopt and we now call the function for that getsockopt.

Tom Herbert committed 10 years ago

Commit 473bd231 parent fa9835e2 files · +25 −14Browse files

Unified · Split

2 files
  1. include/net/tcp.h +24 −0
  2. net/ipv4/tcp.c +1 −14
include/net/tcp.h+24−0
@@ -1816,4 +1816,28 @@ static inline void skb_set_tcp_pure_ack(struct sk_buff *skb) · 1815 unmodified lines
18161816 skb->truesize = 2;
18171817 }
18181818
1819+static inline int tcp_inq(struct sock *sk)
1820+{
1821+ struct tcp_sock *tp = tcp_sk(sk);
1822+ int answ;
1823+
1824+ if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
1825+ answ = 0;
1826+ } else if (sock_flag(sk, SOCK_URGINLINE) ||
1827+ !tp->urg_data ||
1828+ before(tp->urg_seq, tp->copied_seq) ||
1829+ !before(tp->urg_seq, tp->rcv_nxt)) {
1830+
1831+ answ = tp->rcv_nxt - tp->copied_seq;
1832+
1833+ /* Subtract 1, if FIN was received */
1834+ if (answ && sock_flag(sk, SOCK_DONE))
1835+ answ--;
1836+ } else {
1837+ answ = tp->urg_seq - tp->copied_seq;
1838+ }
1839+
1840+ return answ;
1841+}
1842+
18191843 #endif /* _TCP_H */
net/ipv4/tcp.c+1−14
@@ -556,20 +556,7 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg) · 555 unmodified lines
556556 return -EINVAL;
557557
558558 slow = lock_sock_fast(sk);
559− if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
560− answ = 0;
561− else if (sock_flag(sk, SOCK_URGINLINE) ||
562− !tp->urg_data ||
563− before(tp->urg_seq, tp->copied_seq) ||
564− !before(tp->urg_seq, tp->rcv_nxt)) {
565−
566− answ = tp->rcv_nxt - tp->copied_seq;
567−
568− /* Subtract 1, if FIN was received */
569− if (answ && sock_flag(sk, SOCK_DONE))
570− answ--;
571− } else
572− answ = tp->urg_seq - tp->copied_seq;
559+ answ = tcp_inq(sk);
573560 unlock_sock_fast(sk, slow);
574561 break;
575562 case SIOCATMARK:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t