Messages in this thread Patch in this message | | | From | kuznet@ms2 ... | Subject | Re: accept on unix-domain sockets | Date | Tue, 9 Nov 1999 20:08:22 +0300 (MSK) |
| |
Hello!
> Is there a final solution in sight which will be implemented in the kernel > or must we use the patch of Lars Heete ?
Patch by Lars Heete is final solution (in its second edition)
Alexey Kuznetsov
diff -ur --new-file linux.orig/net/unix/af_unix.c linux/net/unix/af_unix.c --- linux.orig/net/unix/af_unix.c Wed Sep 8 22:33:26 1999 +++ linux/net/unix/af_unix.c Sun Nov 7 17:43:25 1999 @@ -944,6 +944,42 @@ return 0; } +/* + * Wait for a packet.. + */ + +static int unix_wait_for_connect(struct sock * sk, int *err) +{ + int error; + + DECLARE_WAITQUEUE(wait, current); + + __set_current_state(TASK_INTERRUPTIBLE); + add_wait_queue(sk->sleep, &wait); + + if (!skb_queue_empty(&sk->receive_queue)) + goto ready; + + /* handle signals */ + error = -ERESTARTSYS; + if (signal_pending(current)) + goto out; + + schedule(); + +ready: + current->state = TASK_RUNNING; + remove_wait_queue(sk->sleep, &wait); + return 0; + +out: + current->state = TASK_RUNNING; + remove_wait_queue(sk->sleep, &wait); + *err = error; + return error; +} + + static int unix_accept(struct socket *sock, struct socket *newsock, int flags) { unix_socket *sk = sock->sk; @@ -961,16 +997,24 @@ /* If socket state is TCP_LISTEN it cannot change, so that no locks are necessary. + + It's not possible to use skb_recv_datagram here, + because this checks if the socket is connected. */ - - skb = skb_recv_datagram(sk, 0, flags&O_NONBLOCK, &err); - if (!skb) - goto out; + + while ((skb = skb_dequeue(&sk->receive_queue)) == NULL) { + if (flags&O_NONBLOCK) { + err = -EAGAIN; + goto out; + } + if (unix_wait_for_connect(sk, &err) != 0) + goto out; + } tsk = skb->sk; + kfree_skb(skb); if (skb_queue_len(&sk->receive_queue) <= sk->max_ack_backlog/2) wake_up_interruptible(&sk->protinfo.af_unix.peer_wait); - skb_free_datagram(sk, skb); /* attach accepted sock to socket */ unix_state_wlock(tsk); - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |