[LLC]: Convert llc_ui_wait_for_ functions to use prepare_to_wait/finish_wait

And make it look more like the similar routines in the TCP/IP source code.
Signed-off-by: NJochen Friedrich <jochen@scram.de>
Signed-off-by: NArnaldo Carvalho de Melo <acme@mandriva.com>
上级 72b1ad4a
...@@ -426,12 +426,30 @@ static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -426,12 +426,30 @@ static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr,
sk->sk_state = TCP_CLOSE; sk->sk_state = TCP_CLOSE;
goto out; goto out;
} }
rc = llc_ui_wait_for_conn(sk, sk->sk_rcvtimeo);
if (rc) if (sk->sk_state == TCP_SYN_SENT) {
dprintk("%s: llc_ui_wait_for_conn failed=%d\n", __FUNCTION__, rc); const int timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
if (!timeo || !llc_ui_wait_for_conn(sk, timeo))
goto out;
rc = sock_intr_errno(timeo);
if (signal_pending(current))
goto out;
}
if (sk->sk_state == TCP_CLOSE)
goto sock_error;
sock->state = SS_CONNECTED;
rc = 0;
out: out:
release_sock(sk); release_sock(sk);
return rc; return rc;
sock_error:
rc = sock_error(sk) ? : -ECONNABORTED;
sock->state = SS_UNCONNECTED;
goto out;
} }
/** /**
...@@ -472,117 +490,88 @@ static int llc_ui_listen(struct socket *sock, int backlog) ...@@ -472,117 +490,88 @@ static int llc_ui_listen(struct socket *sock, int backlog)
static int llc_ui_wait_for_disc(struct sock *sk, int timeout) static int llc_ui_wait_for_disc(struct sock *sk, int timeout)
{ {
DECLARE_WAITQUEUE(wait, current); DEFINE_WAIT(wait);
int rc; int rc = 0;
add_wait_queue_exclusive(sk->sk_sleep, &wait); prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
for (;;) { while (sk->sk_state != TCP_CLOSE) {
__set_current_state(TASK_INTERRUPTIBLE); release_sock(sk);
rc = 0; timeout = schedule_timeout(timeout);
if (sk->sk_state != TCP_CLOSE) { lock_sock(sk);
release_sock(sk);
timeout = schedule_timeout(timeout);
lock_sock(sk);
} else
break;
rc = -ERESTARTSYS; rc = -ERESTARTSYS;
if (signal_pending(current)) if (signal_pending(current))
break; break;
rc = -EAGAIN; rc = -EAGAIN;
if (!timeout) if (!timeout)
break; break;
rc = 0;
prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
} }
__set_current_state(TASK_RUNNING); finish_wait(sk->sk_sleep, &wait);
remove_wait_queue(sk->sk_sleep, &wait);
return rc; return rc;
} }
static int llc_ui_wait_for_conn(struct sock *sk, int timeout) static int llc_ui_wait_for_conn(struct sock *sk, int timeout)
{ {
DECLARE_WAITQUEUE(wait, current); DEFINE_WAIT(wait);
int rc;
add_wait_queue_exclusive(sk->sk_sleep, &wait); prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
for (;;) {
__set_current_state(TASK_INTERRUPTIBLE); while (sk->sk_state == TCP_SYN_SENT) {
rc = -EAGAIN; release_sock(sk);
if (sk->sk_state == TCP_CLOSE) timeout = schedule_timeout(timeout);
break; lock_sock(sk);
rc = 0; if (signal_pending(current) || !timeout)
if (sk->sk_state != TCP_ESTABLISHED) {
release_sock(sk);
timeout = schedule_timeout(timeout);
lock_sock(sk);
} else
break;
rc = -ERESTARTSYS;
if (signal_pending(current))
break;
rc = -EAGAIN;
if (!timeout)
break; break;
prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
} }
__set_current_state(TASK_RUNNING); finish_wait(sk->sk_sleep, &wait);
remove_wait_queue(sk->sk_sleep, &wait); return timeout;
return rc;
} }
static int llc_ui_wait_for_data(struct sock *sk, int timeout) static int llc_ui_wait_for_data(struct sock *sk, int timeout)
{ {
DECLARE_WAITQUEUE(wait, current); DEFINE_WAIT(wait);
int rc = 0; int rc = 0;
add_wait_queue_exclusive(sk->sk_sleep, &wait);
for (;;) { for (;;) {
__set_current_state(TASK_INTERRUPTIBLE); prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
if (sk->sk_shutdown & RCV_SHUTDOWN) if (sk->sk_shutdown & RCV_SHUTDOWN)
break; break;
/* if (!skb_queue_empty(&sk->sk_receive_queue))
* Well, if we have backlog, try to process it now.
*/
if (sk->sk_backlog.tail) {
release_sock(sk);
lock_sock(sk);
}
rc = 0;
if (skb_queue_empty(&sk->sk_receive_queue)) {
release_sock(sk);
timeout = schedule_timeout(timeout);
lock_sock(sk);
} else
break; break;
release_sock(sk);
timeout = schedule_timeout(timeout);
lock_sock(sk);
rc = -ERESTARTSYS; rc = -ERESTARTSYS;
if (signal_pending(current)) if (signal_pending(current))
break; break;
rc = -EAGAIN; rc = -EAGAIN;
if (!timeout) if (!timeout)
break; break;
rc = 0;
} }
__set_current_state(TASK_RUNNING); finish_wait(sk->sk_sleep, &wait);
remove_wait_queue(sk->sk_sleep, &wait);
return rc; return rc;
} }
static int llc_ui_wait_for_busy_core(struct sock *sk, int timeout) static int llc_ui_wait_for_busy_core(struct sock *sk, int timeout)
{ {
DECLARE_WAITQUEUE(wait, current); DEFINE_WAIT(wait);
struct llc_sock *llc = llc_sk(sk); struct llc_sock *llc = llc_sk(sk);
int rc; int rc;
add_wait_queue_exclusive(sk->sk_sleep, &wait);
for (;;) { for (;;) {
dprintk("%s: looping...\n", __FUNCTION__); prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
__set_current_state(TASK_INTERRUPTIBLE);
rc = -ENOTCONN; rc = -ENOTCONN;
if (sk->sk_shutdown & RCV_SHUTDOWN) if (sk->sk_shutdown & RCV_SHUTDOWN)
break; break;
rc = 0; rc = 0;
if (llc_data_accept_state(llc->state) || llc->p_flag) { if (!llc_data_accept_state(llc->state) && !llc->p_flag)
release_sock(sk);
timeout = schedule_timeout(timeout);
lock_sock(sk);
} else
break; break;
release_sock(sk);
timeout = schedule_timeout(timeout);
lock_sock(sk);
rc = -ERESTARTSYS; rc = -ERESTARTSYS;
if (signal_pending(current)) if (signal_pending(current))
break; break;
...@@ -590,8 +579,7 @@ static int llc_ui_wait_for_busy_core(struct sock *sk, int timeout) ...@@ -590,8 +579,7 @@ static int llc_ui_wait_for_busy_core(struct sock *sk, int timeout)
if (!timeout) if (!timeout)
break; break;
} }
__set_current_state(TASK_RUNNING); finish_wait(sk->sk_sleep, &wait);
remove_wait_queue(sk->sk_sleep, &wait);
return rc; return rc;
} }
...@@ -621,9 +609,11 @@ static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags) ...@@ -621,9 +609,11 @@ static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags)
sk->sk_state != TCP_LISTEN)) sk->sk_state != TCP_LISTEN))
goto out; goto out;
/* wait for a connection to arrive. */ /* wait for a connection to arrive. */
rc = llc_ui_wait_for_data(sk, sk->sk_rcvtimeo); if (skb_queue_empty(&sk->sk_receive_queue)) {
if (rc) rc = llc_ui_wait_for_data(sk, sk->sk_rcvtimeo);
goto out; if (rc)
goto out;
}
dprintk("%s: got a new connection on %02X\n", __FUNCTION__, dprintk("%s: got a new connection on %02X\n", __FUNCTION__,
llc_sk(sk)->laddr.lsap); llc_sk(sk)->laddr.lsap);
skb = skb_dequeue(&sk->sk_receive_queue); skb = skb_dequeue(&sk->sk_receive_queue);
...@@ -672,19 +662,16 @@ static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock, ...@@ -672,19 +662,16 @@ static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
struct sockaddr_llc *uaddr = (struct sockaddr_llc *)msg->msg_name; struct sockaddr_llc *uaddr = (struct sockaddr_llc *)msg->msg_name;
struct sk_buff *skb; struct sk_buff *skb;
size_t copied = 0; size_t copied = 0;
int rc = -ENOMEM, timeout; int rc = -ENOMEM;
int noblock = flags & MSG_DONTWAIT; int noblock = flags & MSG_DONTWAIT;
dprintk("%s: receiving in %02X from %02X\n", __FUNCTION__, dprintk("%s: receiving in %02X from %02X\n", __FUNCTION__,
llc_sk(sk)->laddr.lsap, llc_sk(sk)->daddr.lsap); llc_sk(sk)->laddr.lsap, llc_sk(sk)->daddr.lsap);
lock_sock(sk); lock_sock(sk);
timeout = sock_rcvtimeo(sk, noblock); if (skb_queue_empty(&sk->sk_receive_queue)) {
rc = llc_ui_wait_for_data(sk, timeout); rc = llc_ui_wait_for_data(sk, sock_rcvtimeo(sk, noblock));
if (rc) { if (rc)
dprintk("%s: llc_ui_wait_for_data failed recv " goto out;
"in %02X from %02X\n", __FUNCTION__,
llc_sk(sk)->laddr.lsap, llc_sk(sk)->daddr.lsap);
goto out;
} }
skb = skb_dequeue(&sk->sk_receive_queue); skb = skb_dequeue(&sk->sk_receive_queue);
if (!skb) /* shutdown */ if (!skb) /* shutdown */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部