Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 279146
b: refs/heads/master
c: 885ee74
h: refs/heads/master
v: v3
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Dec 30, 2011
1 parent e7a7f01 commit a7bb24c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 257b529876cb45ec791eaa89e3d2ee0d16b49383
refs/heads/master: 885ee74d5d3058e4a904671ed7929c9540c95fa5
3 changes: 3 additions & 0 deletions trunk/include/net/af_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ struct unix_sock {

#define peer_wait peer_wq.wait

long unix_inq_len(struct sock *sk);
long unix_outq_len(struct sock *sk);

#ifdef CONFIG_SYSCTL
extern int unix_sysctl_register(struct net *net);
extern void unix_sysctl_unregister(struct net *net);
Expand Down
59 changes: 36 additions & 23 deletions trunk/net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,36 @@ static int unix_shutdown(struct socket *sock, int mode)
return 0;
}

long unix_inq_len(struct sock *sk)
{
struct sk_buff *skb;
long amount = 0;

if (sk->sk_state == TCP_LISTEN)
return -EINVAL;

spin_lock(&sk->sk_receive_queue.lock);
if (sk->sk_type == SOCK_STREAM ||
sk->sk_type == SOCK_SEQPACKET) {
skb_queue_walk(&sk->sk_receive_queue, skb)
amount += skb->len;
} else {
skb = skb_peek(&sk->sk_receive_queue);
if (skb)
amount = skb->len;
}
spin_unlock(&sk->sk_receive_queue.lock);

return amount;
}
EXPORT_SYMBOL_GPL(unix_inq_len);

long unix_outq_len(struct sock *sk)
{
return sk_wmem_alloc_get(sk);
}
EXPORT_SYMBOL_GPL(unix_outq_len);

static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
{
struct sock *sk = sock->sk;
Expand All @@ -2073,33 +2103,16 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)

switch (cmd) {
case SIOCOUTQ:
amount = sk_wmem_alloc_get(sk);
amount = unix_outq_len(sk);
err = put_user(amount, (int __user *)arg);
break;
case SIOCINQ:
{
struct sk_buff *skb;

if (sk->sk_state == TCP_LISTEN) {
err = -EINVAL;
break;
}

spin_lock(&sk->sk_receive_queue.lock);
if (sk->sk_type == SOCK_STREAM ||
sk->sk_type == SOCK_SEQPACKET) {
skb_queue_walk(&sk->sk_receive_queue, skb)
amount += skb->len;
} else {
skb = skb_peek(&sk->sk_receive_queue);
if (skb)
amount = skb->len;
}
spin_unlock(&sk->sk_receive_queue.lock);
amount = unix_inq_len(sk);
if (amount < 0)
err = amount;
else
err = put_user(amount, (int __user *)arg);
break;
}

break;
default:
err = -ENOIOCTLCMD;
break;
Expand Down

0 comments on commit a7bb24c

Please sign in to comment.