diff options
Diffstat (limited to 'net/unix/af_unix.c')
-rw-r--r-- | net/unix/af_unix.c | 75 |
1 files changed, 66 insertions, 9 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index e18cd3628db4..783317dacd30 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
@@ -169,6 +169,11 @@ static inline int unix_may_send(struct sock *sk, struct sock *osk) | |||
169 | return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); | 169 | return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); |
170 | } | 170 | } |
171 | 171 | ||
172 | static inline int unix_recvq_full(struct sock const *sk) | ||
173 | { | ||
174 | return skb_queue_len(&sk->sk_receive_queue) > sk->sk_max_ack_backlog; | ||
175 | } | ||
176 | |||
172 | static struct sock *unix_peer_get(struct sock *s) | 177 | static struct sock *unix_peer_get(struct sock *s) |
173 | { | 178 | { |
174 | struct sock *peer; | 179 | struct sock *peer; |
@@ -482,6 +487,8 @@ static int unix_socketpair(struct socket *, struct socket *); | |||
482 | static int unix_accept(struct socket *, struct socket *, int); | 487 | static int unix_accept(struct socket *, struct socket *, int); |
483 | static int unix_getname(struct socket *, struct sockaddr *, int *, int); | 488 | static int unix_getname(struct socket *, struct sockaddr *, int *, int); |
484 | static unsigned int unix_poll(struct file *, struct socket *, poll_table *); | 489 | static unsigned int unix_poll(struct file *, struct socket *, poll_table *); |
490 | static unsigned int unix_dgram_poll(struct file *, struct socket *, | ||
491 | poll_table *); | ||
485 | static int unix_ioctl(struct socket *, unsigned int, unsigned long); | 492 | static int unix_ioctl(struct socket *, unsigned int, unsigned long); |
486 | static int unix_shutdown(struct socket *, int); | 493 | static int unix_shutdown(struct socket *, int); |
487 | static int unix_stream_sendmsg(struct kiocb *, struct socket *, | 494 | static int unix_stream_sendmsg(struct kiocb *, struct socket *, |
@@ -527,7 +534,7 @@ static const struct proto_ops unix_dgram_ops = { | |||
527 | .socketpair = unix_socketpair, | 534 | .socketpair = unix_socketpair, |
528 | .accept = sock_no_accept, | 535 | .accept = sock_no_accept, |
529 | .getname = unix_getname, | 536 | .getname = unix_getname, |
530 | .poll = datagram_poll, | 537 | .poll = unix_dgram_poll, |
531 | .ioctl = unix_ioctl, | 538 | .ioctl = unix_ioctl, |
532 | .listen = sock_no_listen, | 539 | .listen = sock_no_listen, |
533 | .shutdown = unix_shutdown, | 540 | .shutdown = unix_shutdown, |
@@ -548,7 +555,7 @@ static const struct proto_ops unix_seqpacket_ops = { | |||
548 | .socketpair = unix_socketpair, | 555 | .socketpair = unix_socketpair, |
549 | .accept = unix_accept, | 556 | .accept = unix_accept, |
550 | .getname = unix_getname, | 557 | .getname = unix_getname, |
551 | .poll = datagram_poll, | 558 | .poll = unix_dgram_poll, |
552 | .ioctl = unix_ioctl, | 559 | .ioctl = unix_ioctl, |
553 | .listen = unix_listen, | 560 | .listen = unix_listen, |
554 | .shutdown = unix_shutdown, | 561 | .shutdown = unix_shutdown, |
@@ -983,8 +990,7 @@ static long unix_wait_for_peer(struct sock *other, long timeo) | |||
983 | 990 | ||
984 | sched = !sock_flag(other, SOCK_DEAD) && | 991 | sched = !sock_flag(other, SOCK_DEAD) && |
985 | !(other->sk_shutdown & RCV_SHUTDOWN) && | 992 | !(other->sk_shutdown & RCV_SHUTDOWN) && |
986 | (skb_queue_len(&other->sk_receive_queue) > | 993 | unix_recvq_full(other); |
987 | other->sk_max_ack_backlog); | ||
988 | 994 | ||
989 | unix_state_unlock(other); | 995 | unix_state_unlock(other); |
990 | 996 | ||
@@ -1058,8 +1064,7 @@ restart: | |||
1058 | if (other->sk_state != TCP_LISTEN) | 1064 | if (other->sk_state != TCP_LISTEN) |
1059 | goto out_unlock; | 1065 | goto out_unlock; |
1060 | 1066 | ||
1061 | if (skb_queue_len(&other->sk_receive_queue) > | 1067 | if (unix_recvq_full(other)) { |
1062 | other->sk_max_ack_backlog) { | ||
1063 | err = -EAGAIN; | 1068 | err = -EAGAIN; |
1064 | if (!timeo) | 1069 | if (!timeo) |
1065 | goto out_unlock; | 1070 | goto out_unlock; |
@@ -1428,9 +1433,7 @@ restart: | |||
1428 | goto out_unlock; | 1433 | goto out_unlock; |
1429 | } | 1434 | } |
1430 | 1435 | ||
1431 | if (unix_peer(other) != sk && | 1436 | if (unix_peer(other) != sk && unix_recvq_full(other)) { |
1432 | (skb_queue_len(&other->sk_receive_queue) > | ||
1433 | other->sk_max_ack_backlog)) { | ||
1434 | if (!timeo) { | 1437 | if (!timeo) { |
1435 | err = -EAGAIN; | 1438 | err = -EAGAIN; |
1436 | goto out_unlock; | 1439 | goto out_unlock; |
@@ -1991,6 +1994,60 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl | |||
1991 | return mask; | 1994 | return mask; |
1992 | } | 1995 | } |
1993 | 1996 | ||
1997 | static unsigned int unix_dgram_poll(struct file *file, struct socket *sock, | ||
1998 | poll_table *wait) | ||
1999 | { | ||
2000 | struct sock *sk = sock->sk, *other; | ||
2001 | unsigned int mask, writable; | ||
2002 | |||
2003 | poll_wait(file, sk->sk_sleep, wait); | ||
2004 | mask = 0; | ||
2005 | |||
2006 | /* exceptional events? */ | ||
2007 | if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) | ||
2008 | mask |= POLLERR; | ||
2009 | if (sk->sk_shutdown & RCV_SHUTDOWN) | ||
2010 | mask |= POLLRDHUP; | ||
2011 | if (sk->sk_shutdown == SHUTDOWN_MASK) | ||
2012 | mask |= POLLHUP; | ||
2013 | |||
2014 | /* readable? */ | ||
2015 | if (!skb_queue_empty(&sk->sk_receive_queue) || | ||
2016 | (sk->sk_shutdown & RCV_SHUTDOWN)) | ||
2017 | mask |= POLLIN | POLLRDNORM; | ||
2018 | |||
2019 | /* Connection-based need to check for termination and startup */ | ||
2020 | if (sk->sk_type == SOCK_SEQPACKET) { | ||
2021 | if (sk->sk_state == TCP_CLOSE) | ||
2022 | mask |= POLLHUP; | ||
2023 | /* connection hasn't started yet? */ | ||
2024 | if (sk->sk_state == TCP_SYN_SENT) | ||
2025 | return mask; | ||
2026 | } | ||
2027 | |||
2028 | /* writable? */ | ||
2029 | writable = unix_writable(sk); | ||
2030 | if (writable) { | ||
2031 | other = unix_peer_get(sk); | ||
2032 | if (other) { | ||
2033 | if (unix_peer(other) != sk) { | ||
2034 | poll_wait(file, &unix_sk(other)->peer_wait, | ||
2035 | wait); | ||
2036 | if (unix_recvq_full(other)) | ||
2037 | writable = 0; | ||
2038 | } | ||
2039 | |||
2040 | sock_put(other); | ||
2041 | } | ||
2042 | } | ||
2043 | |||
2044 | if (writable) | ||
2045 | mask |= POLLOUT | POLLWRNORM | POLLWRBAND; | ||
2046 | else | ||
2047 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); | ||
2048 | |||
2049 | return mask; | ||
2050 | } | ||
1994 | 2051 | ||
1995 | #ifdef CONFIG_PROC_FS | 2052 | #ifdef CONFIG_PROC_FS |
1996 | static struct sock *first_unix_socket(int *i) | 2053 | static struct sock *first_unix_socket(int *i) |