/* Sleep until data has arrive. But check for races..  */
static long unix_stream_data_wait(struct sock *sk, long timeo)
/* Sleep until data has arrive. But check for races..  */
static long unix_stream_data_wait(struct sock *sk, long timeo)
{
	DEFINE_WAIT(wait);
	unix_state_lock(sk);
	for (;;) {
		prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
		if (!skb_queue_empty(&sk->sk_receive_queue) ||
		    sk->sk_err ||
		    (sk->sk_shutdown & RCV_SHUTDOWN) ||
		    signal_pending(current) ||
		    !timeo)
			break;
		set_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
		unix_state_unlock(sk);
		timeo = schedule_timeout(timeo);
		unix_state_lock(sk);
		clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
	}
	finish_wait(sk->sk_sleep, &wait);
	unix_state_unlock(sk);
	return timeo;
}