Skip to content

Commit

Permalink
[NET]: Name magic constants in sock_wake_async()
Browse files Browse the repository at this point in the history
The sock_wake_async() performs a bit different actions
depending on "how" argument. Unfortunately this argument
ony has numerical magic values.

I propose to give names to their constants to help people
reading this function callers understand what's going on
without looking into this function all the time.

I suppose this is 2.6.25 material, but if it's not (or the
naming seems poor/bad/awful), I can rework it against the
current net-2.6 tree.

Signed-off-by: Pavel Emelyanov <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
xemul authored and davem330 committed Jan 28, 2008
1 parent ce865a6 commit 8d8ad9d
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 28 deletions.
7 changes: 7 additions & 0 deletions include/linux/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ struct net_proto_family {
struct iovec;
struct kvec;

enum {
SOCK_WAKE_IO,
SOCK_WAKE_WAITD,
SOCK_WAKE_SPACE,
SOCK_WAKE_URG,
};

extern int sock_wake_async(struct socket *sk, int how, int band);
extern int sock_register(const struct net_proto_family *fam);
extern void sock_unregister(int family);
Expand Down
2 changes: 1 addition & 1 deletion net/atm/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static void vcc_write_space(struct sock *sk)
if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
wake_up_interruptible(sk->sk_sleep);

sk_wake_async(sk, 2, POLL_OUT);
sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
}

read_unlock(&sk->sk_callback_lock);
Expand Down
8 changes: 4 additions & 4 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ static void sock_def_error_report(struct sock *sk)
read_lock(&sk->sk_callback_lock);
if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
wake_up_interruptible(sk->sk_sleep);
sk_wake_async(sk,0,POLL_ERR);
sk_wake_async(sk, SOCK_WAKE_IO, POLL_ERR);
read_unlock(&sk->sk_callback_lock);
}

Expand All @@ -1507,7 +1507,7 @@ static void sock_def_readable(struct sock *sk, int len)
read_lock(&sk->sk_callback_lock);
if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
wake_up_interruptible(sk->sk_sleep);
sk_wake_async(sk,1,POLL_IN);
sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
read_unlock(&sk->sk_callback_lock);
}

Expand All @@ -1524,7 +1524,7 @@ static void sock_def_write_space(struct sock *sk)

/* Should agree with poll, otherwise some programs break */
if (sock_writeable(sk))
sk_wake_async(sk, 2, POLL_OUT);
sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
}

read_unlock(&sk->sk_callback_lock);
Expand All @@ -1539,7 +1539,7 @@ void sk_send_sigurg(struct sock *sk)
{
if (sk->sk_socket && sk->sk_socket->file)
if (send_sigurg(&sk->sk_socket->file->f_owner))
sk_wake_async(sk, 3, POLL_PRI);
sk_wake_async(sk, SOCK_WAKE_URG, POLL_PRI);
}

void sk_reset_timer(struct sock *sk, struct timer_list* timer,
Expand Down
2 changes: 1 addition & 1 deletion net/core/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void sk_stream_write_space(struct sock *sk)
if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
wake_up_interruptible(sk->sk_sleep);
if (sock->fasync_list && !(sk->sk_shutdown & SEND_SHUTDOWN))
sock_wake_async(sock, 2, POLL_OUT);
sock_wake_async(sock, SOCK_WAKE_SPACE, POLL_OUT);
}
}

Expand Down
8 changes: 4 additions & 4 deletions net/dccp/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static void dccp_rcv_close(struct sock *sk, struct sk_buff *skb)
dccp_send_reset(sk, DCCP_RESET_CODE_CLOSED);
dccp_fin(sk, skb);
dccp_set_state(sk, DCCP_CLOSED);
sk_wake_async(sk, 1, POLL_HUP);
sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_HUP);
}

static void dccp_rcv_closereq(struct sock *sk, struct sk_buff *skb)
Expand Down Expand Up @@ -90,7 +90,7 @@ static void dccp_rcv_reset(struct sock *sk, struct sk_buff *skb)
dccp_fin(sk, skb);

if (err && !sock_flag(sk, SOCK_DEAD))
sk_wake_async(sk, 0, POLL_ERR);
sk_wake_async(sk, SOCK_WAKE_IO, POLL_ERR);
dccp_time_wait(sk, DCCP_TIME_WAIT, 0);
}

Expand Down Expand Up @@ -416,7 +416,7 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,

if (!sock_flag(sk, SOCK_DEAD)) {
sk->sk_state_change(sk);
sk_wake_async(sk, 0, POLL_OUT);
sk_wake_async(sk, SOCK_WAKE_IO, POLL_OUT);
}

if (sk->sk_write_pending || icsk->icsk_ack.pingpong ||
Expand Down Expand Up @@ -624,7 +624,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
switch (old_state) {
case DCCP_PARTOPEN:
sk->sk_state_change(sk);
sk_wake_async(sk, 0, POLL_OUT);
sk_wake_async(sk, SOCK_WAKE_IO, POLL_OUT);
break;
}
} else if (unlikely(dh->dccph_type == DCCP_PKT_SYNC)) {
Expand Down
2 changes: 1 addition & 1 deletion net/dccp/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void dccp_write_space(struct sock *sk)
wake_up_interruptible(sk->sk_sleep);
/* Should agree with poll, otherwise some programs break */
if (sock_writeable(sk))
sk_wake_async(sk, 2, POLL_OUT);
sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);

read_unlock(&sk->sk_callback_lock);
}
Expand Down
12 changes: 6 additions & 6 deletions net/ipv4/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -3595,9 +3595,9 @@ static void tcp_fin(struct sk_buff *skb, struct sock *sk, struct tcphdr *th)
/* Do not send POLL_HUP for half duplex close. */
if (sk->sk_shutdown == SHUTDOWN_MASK ||
sk->sk_state == TCP_CLOSE)
sk_wake_async(sk, 1, POLL_HUP);
sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_HUP);
else
sk_wake_async(sk, 1, POLL_IN);
sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
}
}

Expand Down Expand Up @@ -4956,7 +4956,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,

if (!sock_flag(sk, SOCK_DEAD)) {
sk->sk_state_change(sk);
sk_wake_async(sk, 0, POLL_OUT);
sk_wake_async(sk, SOCK_WAKE_IO, POLL_OUT);
}

if (sk->sk_write_pending ||
Expand Down Expand Up @@ -5186,9 +5186,9 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
* are not waked up, because sk->sk_sleep ==
* NULL and sk->sk_socket == NULL.
*/
if (sk->sk_socket) {
sk_wake_async(sk,0,POLL_OUT);
}
if (sk->sk_socket)
sk_wake_async(sk,
SOCK_WAKE_IO, POLL_OUT);

tp->snd_una = TCP_SKB_CB(skb)->ack_seq;
tp->snd_wnd = ntohs(th->window) <<
Expand Down
2 changes: 1 addition & 1 deletion net/rxrpc/af_rxrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void rxrpc_write_space(struct sock *sk)
if (rxrpc_writable(sk)) {
if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
wake_up_interruptible(sk->sk_sleep);
sk_wake_async(sk, 2, POLL_OUT);
sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
}
read_unlock(&sk->sk_callback_lock);
}
Expand Down
3 changes: 2 additions & 1 deletion net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -6008,7 +6008,8 @@ static void __sctp_write_space(struct sctp_association *asoc)
*/
if (sock->fasync_list &&
!(sk->sk_shutdown & SEND_SHUTDOWN))
sock_wake_async(sock, 2, POLL_OUT);
sock_wake_async(sock,
SOCK_WAKE_SPACE, POLL_OUT);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,20 +1070,19 @@ int sock_wake_async(struct socket *sock, int how, int band)
if (!sock || !sock->fasync_list)
return -1;
switch (how) {
case 1:

case SOCK_WAKE_WAITD:
if (test_bit(SOCK_ASYNC_WAITDATA, &sock->flags))
break;
goto call_kill;
case 2:
case SOCK_WAKE_SPACE:
if (!test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags))
break;
/* fall through */
case 0:
case SOCK_WAKE_IO:
call_kill:
__kill_fasync(sock->fasync_list, SIGIO, band);
break;
case 3:
case SOCK_WAKE_URG:
__kill_fasync(sock->fasync_list, SIGURG, band);
}
return 0;
Expand Down
8 changes: 4 additions & 4 deletions net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static void unix_write_space(struct sock *sk)
if (unix_writable(sk)) {
if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
wake_up_interruptible_sync(sk->sk_sleep);
sk_wake_async(sk, 2, POLL_OUT);
sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
}
read_unlock(&sk->sk_callback_lock);
}
Expand Down Expand Up @@ -403,7 +403,7 @@ static int unix_release_sock (struct sock *sk, int embrion)
unix_state_unlock(skpair);
skpair->sk_state_change(skpair);
read_lock(&skpair->sk_callback_lock);
sk_wake_async(skpair,1,POLL_HUP);
sk_wake_async(skpair, SOCK_WAKE_WAITD, POLL_HUP);
read_unlock(&skpair->sk_callback_lock);
}
sock_put(skpair); /* It may now die */
Expand Down Expand Up @@ -1900,9 +1900,9 @@ static int unix_shutdown(struct socket *sock, int mode)
other->sk_state_change(other);
read_lock(&other->sk_callback_lock);
if (peer_mode == SHUTDOWN_MASK)
sk_wake_async(other,1,POLL_HUP);
sk_wake_async(other, SOCK_WAKE_WAITD, POLL_HUP);
else if (peer_mode & RCV_SHUTDOWN)
sk_wake_async(other,1,POLL_IN);
sk_wake_async(other, SOCK_WAKE_WAITD, POLL_IN);
read_unlock(&other->sk_callback_lock);
}
if (other)
Expand Down

0 comments on commit 8d8ad9d

Please sign in to comment.