aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix/af_unix.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2008-07-21 00:55:14 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2008-07-21 00:55:14 -0400
commit908cf4b925e419bc74f3297b2f0e51d6f8a81da2 (patch)
tree6c2da79366d4695a9c2560ab18259eca8a2a25b4 /net/unix/af_unix.c
parent92c49890922d54cba4b1eadeb0b185773c2c9570 (diff)
parent14b395e35d1afdd8019d11b92e28041fad591b71 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6 into next
Diffstat (limited to 'net/unix/af_unix.c')
-rw-r--r--net/unix/af_unix.c77
1 files changed, 66 insertions, 11 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index e18cd3628db4..70ceb1604ad8 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -8,8 +8,6 @@
8 * as published by the Free Software Foundation; either version 8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version. 9 * 2 of the License, or (at your option) any later version.
10 * 10 *
11 * Version: $Id: af_unix.c,v 1.133 2002/02/08 03:57:19 davem Exp $
12 *
13 * Fixes: 11 * Fixes:
14 * Linus Torvalds : Assorted bug cures. 12 * Linus Torvalds : Assorted bug cures.
15 * Niibe Yutaka : async I/O support. 13 * Niibe Yutaka : async I/O support.
@@ -169,6 +167,11 @@ static inline int unix_may_send(struct sock *sk, struct sock *osk)
169 return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); 167 return (unix_peer(osk) == NULL || unix_our_peer(sk, osk));
170} 168}
171 169
170static inline int unix_recvq_full(struct sock const *sk)
171{
172 return skb_queue_len(&sk->sk_receive_queue) > sk->sk_max_ack_backlog;
173}
174
172static struct sock *unix_peer_get(struct sock *s) 175static struct sock *unix_peer_get(struct sock *s)
173{ 176{
174 struct sock *peer; 177 struct sock *peer;
@@ -482,6 +485,8 @@ static int unix_socketpair(struct socket *, struct socket *);
482static int unix_accept(struct socket *, struct socket *, int); 485static int unix_accept(struct socket *, struct socket *, int);
483static int unix_getname(struct socket *, struct sockaddr *, int *, int); 486static int unix_getname(struct socket *, struct sockaddr *, int *, int);
484static unsigned int unix_poll(struct file *, struct socket *, poll_table *); 487static unsigned int unix_poll(struct file *, struct socket *, poll_table *);
488static unsigned int unix_dgram_poll(struct file *, struct socket *,
489 poll_table *);
485static int unix_ioctl(struct socket *, unsigned int, unsigned long); 490static int unix_ioctl(struct socket *, unsigned int, unsigned long);
486static int unix_shutdown(struct socket *, int); 491static int unix_shutdown(struct socket *, int);
487static int unix_stream_sendmsg(struct kiocb *, struct socket *, 492static int unix_stream_sendmsg(struct kiocb *, struct socket *,
@@ -527,7 +532,7 @@ static const struct proto_ops unix_dgram_ops = {
527 .socketpair = unix_socketpair, 532 .socketpair = unix_socketpair,
528 .accept = sock_no_accept, 533 .accept = sock_no_accept,
529 .getname = unix_getname, 534 .getname = unix_getname,
530 .poll = datagram_poll, 535 .poll = unix_dgram_poll,
531 .ioctl = unix_ioctl, 536 .ioctl = unix_ioctl,
532 .listen = sock_no_listen, 537 .listen = sock_no_listen,
533 .shutdown = unix_shutdown, 538 .shutdown = unix_shutdown,
@@ -548,7 +553,7 @@ static const struct proto_ops unix_seqpacket_ops = {
548 .socketpair = unix_socketpair, 553 .socketpair = unix_socketpair,
549 .accept = unix_accept, 554 .accept = unix_accept,
550 .getname = unix_getname, 555 .getname = unix_getname,
551 .poll = datagram_poll, 556 .poll = unix_dgram_poll,
552 .ioctl = unix_ioctl, 557 .ioctl = unix_ioctl,
553 .listen = unix_listen, 558 .listen = unix_listen,
554 .shutdown = unix_shutdown, 559 .shutdown = unix_shutdown,
@@ -983,8 +988,7 @@ static long unix_wait_for_peer(struct sock *other, long timeo)
983 988
984 sched = !sock_flag(other, SOCK_DEAD) && 989 sched = !sock_flag(other, SOCK_DEAD) &&
985 !(other->sk_shutdown & RCV_SHUTDOWN) && 990 !(other->sk_shutdown & RCV_SHUTDOWN) &&
986 (skb_queue_len(&other->sk_receive_queue) > 991 unix_recvq_full(other);
987 other->sk_max_ack_backlog);
988 992
989 unix_state_unlock(other); 993 unix_state_unlock(other);
990 994
@@ -1058,8 +1062,7 @@ restart:
1058 if (other->sk_state != TCP_LISTEN) 1062 if (other->sk_state != TCP_LISTEN)
1059 goto out_unlock; 1063 goto out_unlock;
1060 1064
1061 if (skb_queue_len(&other->sk_receive_queue) > 1065 if (unix_recvq_full(other)) {
1062 other->sk_max_ack_backlog) {
1063 err = -EAGAIN; 1066 err = -EAGAIN;
1064 if (!timeo) 1067 if (!timeo)
1065 goto out_unlock; 1068 goto out_unlock;
@@ -1428,9 +1431,7 @@ restart:
1428 goto out_unlock; 1431 goto out_unlock;
1429 } 1432 }
1430 1433
1431 if (unix_peer(other) != sk && 1434 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) { 1435 if (!timeo) {
1435 err = -EAGAIN; 1436 err = -EAGAIN;
1436 goto out_unlock; 1437 goto out_unlock;
@@ -1991,6 +1992,60 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl
1991 return mask; 1992 return mask;
1992} 1993}
1993 1994
1995static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,
1996 poll_table *wait)
1997{
1998 struct sock *sk = sock->sk, *other;
1999 unsigned int mask, writable;
2000
2001 poll_wait(file, sk->sk_sleep, wait);
2002 mask = 0;
2003
2004 /* exceptional events? */
2005 if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
2006 mask |= POLLERR;
2007 if (sk->sk_shutdown & RCV_SHUTDOWN)
2008 mask |= POLLRDHUP;
2009 if (sk->sk_shutdown == SHUTDOWN_MASK)
2010 mask |= POLLHUP;
2011
2012 /* readable? */
2013 if (!skb_queue_empty(&sk->sk_receive_queue) ||
2014 (sk->sk_shutdown & RCV_SHUTDOWN))
2015 mask |= POLLIN | POLLRDNORM;
2016
2017 /* Connection-based need to check for termination and startup */
2018 if (sk->sk_type == SOCK_SEQPACKET) {
2019 if (sk->sk_state == TCP_CLOSE)
2020 mask |= POLLHUP;
2021 /* connection hasn't started yet? */
2022 if (sk->sk_state == TCP_SYN_SENT)
2023 return mask;
2024 }
2025
2026 /* writable? */
2027 writable = unix_writable(sk);
2028 if (writable) {
2029 other = unix_peer_get(sk);
2030 if (other) {
2031 if (unix_peer(other) != sk) {
2032 poll_wait(file, &unix_sk(other)->peer_wait,
2033 wait);
2034 if (unix_recvq_full(other))
2035 writable = 0;
2036 }
2037
2038 sock_put(other);
2039 }
2040 }
2041
2042 if (writable)
2043 mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
2044 else
2045 set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
2046
2047 return mask;
2048}
1994 2049
1995#ifdef CONFIG_PROC_FS 2050#ifdef CONFIG_PROC_FS
1996static struct sock *first_unix_socket(int *i) 2051static struct sock *first_unix_socket(int *i)