[NET] introduce sk_stream_wait_close, from tcp code

Will be used by the poor cousins.
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@conectiva.com.br>
parent 3beb5b39
......@@ -461,6 +461,7 @@ do { if (!(__sk)->sk_backlog.tail) { \
})
extern int sk_stream_wait_connect(struct sock *sk, long *timeo_p);
extern void sk_stream_wait_close(struct sock *sk, long timeo_p);
extern int sk_wait_data(struct sock *sk, long *timeo);
......
......@@ -76,3 +76,31 @@ int sk_stream_wait_connect(struct sock *sk, long *timeo_p)
}
EXPORT_SYMBOL(sk_stream_wait_connect);
/**
* sk_stream_closing - Return 1 if we still have things to send in our buffers.
* @sk - socket to verify
*/
static inline int sk_stream_closing(struct sock *sk)
{
return (1 << sk->sk_state) &
(TCPF_FIN_WAIT1 | TCPF_CLOSING | TCPF_LAST_ACK);
}
void sk_stream_wait_close(struct sock *sk, long timeout)
{
if (timeout) {
DEFINE_WAIT(wait);
do {
prepare_to_wait(sk->sk_sleep, &wait,
TASK_INTERRUPTIBLE);
if (sk_wait_event(sk, &timeout, !sk_stream_closing(sk)))
break;
} while (!signal_pending(current) && timeout);
finish_wait(sk->sk_sleep, &wait);
}
}
EXPORT_SYMBOL(sk_stream_wait_close);
......@@ -1712,17 +1712,6 @@ void tcp_shutdown(struct sock *sk, int how)
}
}
/*
* Return 1 if we still have things to send in our buffers.
*/
static inline int closing(struct sock *sk)
{
return (1 << sk->sk_state) &
(TCPF_FIN_WAIT1 | TCPF_CLOSING | TCPF_LAST_ACK);
}
static __inline__ void tcp_kill_sk_queues(struct sock *sk)
{
/* First the read buffer. */
......@@ -1865,22 +1854,7 @@ void tcp_close(struct sock *sk, long timeout)
tcp_send_fin(sk);
}
if (timeout) {
struct task_struct *tsk = current;
DEFINE_WAIT(wait);
do {
prepare_to_wait(sk->sk_sleep, &wait,
TASK_INTERRUPTIBLE);
if (!closing(sk))
break;
release_sock(sk);
timeout = schedule_timeout(timeout);
lock_sock(sk);
} while (!signal_pending(tsk) && timeout);
finish_wait(sk->sk_sleep, &wait);
}
sk_stream_wait_close(sk, timeout);
adjudge_to_death:
/* It is the last release_sock in its life. It will remove backlog. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment