diff options
author | Tom Herbert <tom@herbertland.com> | 2016-03-07 17:11:05 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-03-09 16:36:14 -0500 |
commit | 473bd239b808a8af5241ce9996a16d283d88ddff (patch) | |
tree | 1a02155265887fa8e2893ddc144a656c240349ee /include/net/tcp.h | |
parent | fa9835e52e3ea946916c2ce6c625c86421131740 (diff) |
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.
Signed-off-by: Tom Herbert <tom@herbertland.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/tcp.h')
-rw-r--r-- | include/net/tcp.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h index e90db8546806..0302636af98c 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h | |||
@@ -1816,4 +1816,28 @@ static inline void skb_set_tcp_pure_ack(struct sk_buff *skb) | |||
1816 | skb->truesize = 2; | 1816 | skb->truesize = 2; |
1817 | } | 1817 | } |
1818 | 1818 | ||
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 | |||
1819 | #endif /* _TCP_H */ | 1843 | #endif /* _TCP_H */ |