aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2008-06-19 19:00:04 -0400
committerDavid S. Miller <davem@davemloft.net>2008-06-19 19:00:04 -0400
commit0344f1c66b544609e867bd24aa7bfa789dfa9830 (patch)
tree7f76abc095a90f7ad475417495d3d4f577080ae1 /net/unix
parentdad9b335c6940de2746a9788eb456d09cf102f81 (diff)
parentef3a62d272f033989e83eb1f26505f93f93e3e69 (diff)
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
Conflicts: net/mac80211/tx.c
Diffstat (limited to 'net/unix')
-rw-r--r--net/unix/af_unix.c79
1 files changed, 70 insertions, 9 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 392e80e3268d..b4280490cf6e 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -167,6 +167,11 @@ static inline int unix_may_send(struct sock *sk, struct sock *osk)
167 return (unix_peer(osk) == NULL || unix_our_peer(sk, osk)); 167 return (unix_peer(osk) == NULL || unix_our_peer(sk, osk));
168} 168}
169 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
170static struct sock *unix_peer_get(struct sock *s) 175static struct sock *unix_peer_get(struct sock *s)
171{ 176{
172 struct sock *peer; 177 struct sock *peer;
@@ -480,6 +485,8 @@ static int unix_socketpair(struct socket *, struct socket *);
480static int unix_accept(struct socket *, struct socket *, int); 485static int unix_accept(struct socket *, struct socket *, int);
481static int unix_getname(struct socket *, struct sockaddr *, int *, int); 486static int unix_getname(struct socket *, struct sockaddr *, int *, int);
482static 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_datagram_poll(struct file *, struct socket *,
489 poll_table *);
483static int unix_ioctl(struct socket *, unsigned int, unsigned long); 490static int unix_ioctl(struct socket *, unsigned int, unsigned long);
484static int unix_shutdown(struct socket *, int); 491static int unix_shutdown(struct socket *, int);
485static int unix_stream_sendmsg(struct kiocb *, struct socket *, 492static int unix_stream_sendmsg(struct kiocb *, struct socket *,
@@ -525,7 +532,7 @@ static const struct proto_ops unix_dgram_ops = {
525 .socketpair = unix_socketpair, 532 .socketpair = unix_socketpair,
526 .accept = sock_no_accept, 533 .accept = sock_no_accept,
527 .getname = unix_getname, 534 .getname = unix_getname,
528 .poll = datagram_poll, 535 .poll = unix_datagram_poll,
529 .ioctl = unix_ioctl, 536 .ioctl = unix_ioctl,
530 .listen = sock_no_listen, 537 .listen = sock_no_listen,
531 .shutdown = unix_shutdown, 538 .shutdown = unix_shutdown,
@@ -546,7 +553,7 @@ static const struct proto_ops unix_seqpacket_ops = {
546 .socketpair = unix_socketpair, 553 .socketpair = unix_socketpair,
547 .accept = unix_accept, 554 .accept = unix_accept,
548 .getname = unix_getname, 555 .getname = unix_getname,
549 .poll = datagram_poll, 556 .poll = unix_datagram_poll,
550 .ioctl = unix_ioctl, 557 .ioctl = unix_ioctl,
551 .listen = unix_listen, 558 .listen = unix_listen,
552 .shutdown = unix_shutdown, 559 .shutdown = unix_shutdown,
@@ -981,8 +988,7 @@ static long unix_wait_for_peer(struct sock *other, long timeo)
981 988
982 sched = !sock_flag(other, SOCK_DEAD) && 989 sched = !sock_flag(other, SOCK_DEAD) &&
983 !(other->sk_shutdown & RCV_SHUTDOWN) && 990 !(other->sk_shutdown & RCV_SHUTDOWN) &&
984 (skb_queue_len(&other->sk_receive_queue) > 991 unix_recvq_full(other);
985 other->sk_max_ack_backlog);
986 992
987 unix_state_unlock(other); 993 unix_state_unlock(other);
988 994
@@ -1056,8 +1062,7 @@ restart:
1056 if (other->sk_state != TCP_LISTEN) 1062 if (other->sk_state != TCP_LISTEN)
1057 goto out_unlock; 1063 goto out_unlock;
1058 1064
1059 if (skb_queue_len(&other->sk_receive_queue) > 1065 if (unix_recvq_full(other)) {
1060 other->sk_max_ack_backlog) {
1061 err = -EAGAIN; 1066 err = -EAGAIN;
1062 if (!timeo) 1067 if (!timeo)
1063 goto out_unlock; 1068 goto out_unlock;
@@ -1426,9 +1431,7 @@ restart:
1426 goto out_unlock; 1431 goto out_unlock;
1427 } 1432 }
1428 1433
1429 if (unix_peer(other) != sk && 1434 if (unix_peer(other) != sk && unix_recvq_full(other)) {
1430 (skb_queue_len(&other->sk_receive_queue) >
1431 other->sk_max_ack_backlog)) {
1432 if (!timeo) { 1435 if (!timeo) {
1433 err = -EAGAIN; 1436 err = -EAGAIN;
1434 goto out_unlock; 1437 goto out_unlock;
@@ -1989,6 +1992,64 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl
1989 return mask; 1992 return mask;
1990} 1993}
1991 1994
1995static unsigned int unix_datagram_poll(struct file *file, struct socket *sock,
1996 poll_table *wait)
1997{
1998 struct sock *sk = sock->sk, *peer;
1999 unsigned int mask;
2000
2001 poll_wait(file, sk->sk_sleep, wait);
2002
2003 peer = unix_peer_get(sk);
2004 if (peer) {
2005 if (peer != sk) {
2006 /*
2007 * Writability of a connected socket additionally
2008 * depends on the state of the receive queue of the
2009 * peer.
2010 */
2011 poll_wait(file, &unix_sk(peer)->peer_wait, wait);
2012 } else {
2013 sock_put(peer);
2014 peer = NULL;
2015 }
2016 }
2017
2018 mask = 0;
2019
2020 /* exceptional events? */
2021 if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue))
2022 mask |= POLLERR;
2023 if (sk->sk_shutdown & RCV_SHUTDOWN)
2024 mask |= POLLRDHUP;
2025 if (sk->sk_shutdown == SHUTDOWN_MASK)
2026 mask |= POLLHUP;
2027
2028 /* readable? */
2029 if (!skb_queue_empty(&sk->sk_receive_queue) ||
2030 (sk->sk_shutdown & RCV_SHUTDOWN))
2031 mask |= POLLIN | POLLRDNORM;
2032
2033 /* Connection-based need to check for termination and startup */
2034 if (sk->sk_type == SOCK_SEQPACKET) {
2035 if (sk->sk_state == TCP_CLOSE)
2036 mask |= POLLHUP;
2037 /* connection hasn't started yet? */
2038 if (sk->sk_state == TCP_SYN_SENT)
2039 return mask;
2040 }
2041
2042 /* writable? */
2043 if (unix_writable(sk) && !(peer && unix_recvq_full(peer)))
2044 mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
2045 else
2046 set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
2047
2048 if (peer)
2049 sock_put(peer);
2050
2051 return mask;
2052}
1992 2053
1993#ifdef CONFIG_PROC_FS 2054#ifdef CONFIG_PROC_FS
1994static struct sock *first_unix_socket(int *i) 2055static struct sock *first_unix_socket(int *i)