diff options
Diffstat (limited to 'net/unix')
-rw-r--r-- | net/unix/af_unix.c | 79 |
1 files changed, 70 insertions, 9 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index e18cd3628db4..657835f227d3 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_datagram_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_datagram_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_datagram_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,64 @@ 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_datagram_poll(struct file *file, struct socket *sock, | ||
1998 | poll_table *wait) | ||
1999 | { | ||
2000 | struct sock *sk = sock->sk, *peer; | ||
2001 | unsigned int mask; | ||
2002 | |||
2003 | poll_wait(file, sk->sk_sleep, wait); | ||
2004 | |||
2005 | peer = unix_peer_get(sk); | ||
2006 | if (peer) { | ||
2007 | if (peer != sk) { | ||
2008 | /* | ||
2009 | * Writability of a connected socket additionally | ||
2010 | * depends on the state of the receive queue of the | ||
2011 | * peer. | ||
2012 | */ | ||
2013 | poll_wait(file, &unix_sk(peer)->peer_wait, wait); | ||
2014 | } else { | ||
2015 | sock_put(peer); | ||
2016 | peer = NULL; | ||
2017 | } | ||
2018 | } | ||
2019 | |||
2020 | mask = 0; | ||
2021 | |||
2022 | /* exceptional events? */ | ||
2023 | if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) | ||
2024 | mask |= POLLERR; | ||
2025 | if (sk->sk_shutdown & RCV_SHUTDOWN) | ||
2026 | mask |= POLLRDHUP; | ||
2027 | if (sk->sk_shutdown == SHUTDOWN_MASK) | ||
2028 | mask |= POLLHUP; | ||
2029 | |||
2030 | /* readable? */ | ||
2031 | if (!skb_queue_empty(&sk->sk_receive_queue) || | ||
2032 | (sk->sk_shutdown & RCV_SHUTDOWN)) | ||
2033 | mask |= POLLIN | POLLRDNORM; | ||
2034 | |||
2035 | /* Connection-based need to check for termination and startup */ | ||
2036 | if (sk->sk_type == SOCK_SEQPACKET) { | ||
2037 | if (sk->sk_state == TCP_CLOSE) | ||
2038 | mask |= POLLHUP; | ||
2039 | /* connection hasn't started yet? */ | ||
2040 | if (sk->sk_state == TCP_SYN_SENT) | ||
2041 | return mask; | ||
2042 | } | ||
2043 | |||
2044 | /* writable? */ | ||
2045 | if (unix_writable(sk) && !(peer && unix_recvq_full(peer))) | ||
2046 | mask |= POLLOUT | POLLWRNORM | POLLWRBAND; | ||
2047 | else | ||
2048 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); | ||
2049 | |||
2050 | if (peer) | ||
2051 | sock_put(peer); | ||
2052 | |||
2053 | return mask; | ||
2054 | } | ||
1994 | 2055 | ||
1995 | #ifdef CONFIG_PROC_FS | 2056 | #ifdef CONFIG_PROC_FS |
1996 | static struct sock *first_unix_socket(int *i) | 2057 | static struct sock *first_unix_socket(int *i) |