aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlaf Kirch <olaf.kirch@oracle.com>2007-04-21 01:05:27 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-04-26 01:29:27 -0400
commit305f2aa18214555e611ad05e586dd385e64ab665 (patch)
tree13eb53d462c9a3fc42a30a4571c42f8632249d5d
parent9958089a43ae8a9af07402461c0b2b7548c7341e (diff)
[IrDA] af_irda: irda_recvmsg_stream cleanup
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 <olaf.kirch@oracle.com> Signed-off-by: Samuel Ortiz <samuel@sortiz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/irda/af_irda.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
index baca1565aa11..a0dbe07a1b19 100644
--- a/net/irda/af_irda.c
+++ b/net/irda/af_irda.c
@@ -1402,8 +1402,8 @@ static int irda_recvmsg_stream(struct kiocb *iocb, struct socket *sock,
1402 struct irda_sock *self = irda_sk(sk); 1402 struct irda_sock *self = irda_sk(sk);
1403 int noblock = flags & MSG_DONTWAIT; 1403 int noblock = flags & MSG_DONTWAIT;
1404 size_t copied = 0; 1404 size_t copied = 0;
1405 int target = 1; 1405 int target;
1406 DECLARE_WAITQUEUE(waitq, current); 1406 long timeo;
1407 1407
1408 IRDA_DEBUG(3, "%s()\n", __FUNCTION__); 1408 IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
1409 1409
@@ -1416,8 +1416,8 @@ static int irda_recvmsg_stream(struct kiocb *iocb, struct socket *sock,
1416 if (flags & MSG_OOB) 1416 if (flags & MSG_OOB)
1417 return -EOPNOTSUPP; 1417 return -EOPNOTSUPP;
1418 1418
1419 if (flags & MSG_WAITALL) 1419 target = sock_rcvlowat(sk, flags & MSG_WAITALL, size);
1420 target = size; 1420 timeo = sock_rcvtimeo(sk, noblock);
1421 1421
1422 msg->msg_namelen = 0; 1422 msg->msg_namelen = 0;
1423 1423
@@ -1425,19 +1425,14 @@ static int irda_recvmsg_stream(struct kiocb *iocb, struct socket *sock,
1425 int chunk; 1425 int chunk;
1426 struct sk_buff *skb = skb_dequeue(&sk->sk_receive_queue); 1426 struct sk_buff *skb = skb_dequeue(&sk->sk_receive_queue);
1427 1427
1428 if (skb==NULL) { 1428 if (skb == NULL) {
1429 DEFINE_WAIT(wait);
1429 int ret = 0; 1430 int ret = 0;
1430 1431
1431 if (copied >= target) 1432 if (copied >= target)
1432 break; 1433 break;
1433 1434
1434 /* The following code is a cut'n'paste of the 1435 prepare_to_wait_exclusive(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
1435 * wait_event_interruptible() macro.
1436 * We don't us the macro because the test condition
1437 * is messy. - Jean II */
1438 set_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
1439 add_wait_queue(sk->sk_sleep, &waitq);
1440 set_current_state(TASK_INTERRUPTIBLE);
1441 1436
1442 /* 1437 /*
1443 * POSIX 1003.1g mandates this order. 1438 * POSIX 1003.1g mandates this order.
@@ -1450,17 +1445,17 @@ static int irda_recvmsg_stream(struct kiocb *iocb, struct socket *sock,
1450 else if (noblock) 1445 else if (noblock)
1451 ret = -EAGAIN; 1446 ret = -EAGAIN;
1452 else if (signal_pending(current)) 1447 else if (signal_pending(current))
1453 ret = -ERESTARTSYS; 1448 ret = sock_intr_errno(timeo);
1449 else if (sk->sk_state != TCP_ESTABLISHED)
1450 ret = -ENOTCONN;
1454 else if (skb_peek(&sk->sk_receive_queue) == NULL) 1451 else if (skb_peek(&sk->sk_receive_queue) == NULL)
1455 /* Wait process until data arrives */ 1452 /* Wait process until data arrives */
1456 schedule(); 1453 schedule();
1457 1454
1458 current->state = TASK_RUNNING; 1455 finish_wait(sk->sk_sleep, &wait);
1459 remove_wait_queue(sk->sk_sleep, &waitq);
1460 clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
1461 1456
1462 if(ret) 1457 if (ret)
1463 return(ret); 1458 return ret;
1464 if (sk->sk_shutdown & RCV_SHUTDOWN) 1459 if (sk->sk_shutdown & RCV_SHUTDOWN)
1465 break; 1460 break;
1466 1461