From: Olaf Kirch <[EMAIL PROTECTED]>

This patch cleans up some code in irda_recvmsg_stream, replacing some
homebrew code with prepare_to_wait/finish_wait, and by making the
code honor sock_rcvtimeo.

Signed-off-by: Olaf Kirch <[EMAIL PROTECTED]>
Signed-off-by: Samuel Ortiz <[EMAIL PROTECTED]>
---
 net/irda/af_irda.c |   31 +++++++++++++------------------
 1 files changed, 13 insertions(+), 18 deletions(-)

Index: net-2.6.22-quilt/net/irda/af_irda.c
===================================================================
--- net-2.6.22-quilt.orig/net/irda/af_irda.c    2007-04-18 01:40:14.000000000 
+0300
+++ net-2.6.22-quilt/net/irda/af_irda.c 2007-04-18 01:40:28.000000000 +0300
@@ -1403,8 +1403,8 @@
        struct irda_sock *self = irda_sk(sk);
        int noblock = flags & MSG_DONTWAIT;
        size_t copied = 0;
-       int target = 1;
-       DECLARE_WAITQUEUE(waitq, current);
+       int target;
+       long timeo;
 
        IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
 
@@ -1417,8 +1417,8 @@
        if (flags & MSG_OOB)
                return -EOPNOTSUPP;
 
-       if (flags & MSG_WAITALL)
-               target = size;
+       target = sock_rcvlowat(sk, flags & MSG_WAITALL, size);
+       timeo = sock_rcvtimeo(sk, noblock);
 
        msg->msg_namelen = 0;
 
@@ -1426,19 +1426,14 @@
                int chunk;
                struct sk_buff *skb = skb_dequeue(&sk->sk_receive_queue);
 
-               if (skb==NULL) {
+               if (skb == NULL) {
+                       DEFINE_WAIT(wait);
                        int ret = 0;
 
                        if (copied >= target)
                                break;
 
-                       /* The following code is a cut'n'paste of the
-                        * wait_event_interruptible() macro.
-                        * We don't us the macro because the test condition
-                        * is messy. - Jean II */
-                       set_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
-                       add_wait_queue(sk->sk_sleep, &waitq);
-                       set_current_state(TASK_INTERRUPTIBLE);
+                       prepare_to_wait_exclusive(sk->sk_sleep, &wait, 
TASK_INTERRUPTIBLE);
 
                        /*
                         *      POSIX 1003.1g mandates this order.
@@ -1451,17 +1446,17 @@
                        else if (noblock)
                                ret = -EAGAIN;
                        else if (signal_pending(current))
-                               ret = -ERESTARTSYS;
+                               ret = sock_intr_errno(timeo);
+                       else if (sk->sk_state != TCP_ESTABLISHED)
+                               ret = -ENOTCONN;
                        else if (skb_peek(&sk->sk_receive_queue) == NULL)
                                /* Wait process until data arrives */
                                schedule();
 
-                       current->state = TASK_RUNNING;
-                       remove_wait_queue(sk->sk_sleep, &waitq);
-                       clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
+                       finish_wait(sk->sk_sleep, &wait);
 
-                       if(ret)
-                               return(ret);
+                       if (ret)
+                               return ret;
                        if (sk->sk_shutdown & RCV_SHUTDOWN)
                                break;
 

--

-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to