Skip to content

Commit 8d8ad9d

Browse files
xemuldavem330
authored andcommitted
[NET]: Name magic constants in sock_wake_async()
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 <xemul@openvz.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ce865a6 commit 8d8ad9d

11 files changed

Lines changed: 35 additions & 28 deletions

File tree

‎include/linux/net.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ struct net_proto_family {
186186
struct iovec;
187187
struct kvec;
188188

189+
enum {
190+
SOCK_WAKE_IO,
191+
SOCK_WAKE_WAITD,
192+
SOCK_WAKE_SPACE,
193+
SOCK_WAKE_URG,
194+
};
195+
189196
extern int sock_wake_async(struct socket *sk, int how, int band);
190197
extern int sock_register(const struct net_proto_family *fam);
191198
extern void sock_unregister(int family);

‎net/atm/common.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static void vcc_write_space(struct sock *sk)
113113
if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
114114
wake_up_interruptible(sk->sk_sleep);
115115

116-
sk_wake_async(sk, 2, POLL_OUT);
116+
sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
117117
}
118118

119119
read_unlock(&sk->sk_callback_lock);

‎net/core/sock.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ static void sock_def_error_report(struct sock *sk)
14981498
read_lock(&sk->sk_callback_lock);
14991499
if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
15001500
wake_up_interruptible(sk->sk_sleep);
1501-
sk_wake_async(sk,0,POLL_ERR);
1501+
sk_wake_async(sk, SOCK_WAKE_IO, POLL_ERR);
15021502
read_unlock(&sk->sk_callback_lock);
15031503
}
15041504

@@ -1507,7 +1507,7 @@ static void sock_def_readable(struct sock *sk, int len)
15071507
read_lock(&sk->sk_callback_lock);
15081508
if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
15091509
wake_up_interruptible(sk->sk_sleep);
1510-
sk_wake_async(sk,1,POLL_IN);
1510+
sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
15111511
read_unlock(&sk->sk_callback_lock);
15121512
}
15131513

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

15251525
/* Should agree with poll, otherwise some programs break */
15261526
if (sock_writeable(sk))
1527-
sk_wake_async(sk, 2, POLL_OUT);
1527+
sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
15281528
}
15291529

15301530
read_unlock(&sk->sk_callback_lock);
@@ -1539,7 +1539,7 @@ void sk_send_sigurg(struct sock *sk)
15391539
{
15401540
if (sk->sk_socket && sk->sk_socket->file)
15411541
if (send_sigurg(&sk->sk_socket->file->f_owner))
1542-
sk_wake_async(sk, 3, POLL_PRI);
1542+
sk_wake_async(sk, SOCK_WAKE_URG, POLL_PRI);
15431543
}
15441544

15451545
void sk_reset_timer(struct sock *sk, struct timer_list* timer,

‎net/core/stream.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void sk_stream_write_space(struct sock *sk)
3535
if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
3636
wake_up_interruptible(sk->sk_sleep);
3737
if (sock->fasync_list && !(sk->sk_shutdown & SEND_SHUTDOWN))
38-
sock_wake_async(sock, 2, POLL_OUT);
38+
sock_wake_async(sock, SOCK_WAKE_SPACE, POLL_OUT);
3939
}
4040
}
4141

‎net/dccp/input.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void dccp_rcv_close(struct sock *sk, struct sk_buff *skb)
3737
dccp_send_reset(sk, DCCP_RESET_CODE_CLOSED);
3838
dccp_fin(sk, skb);
3939
dccp_set_state(sk, DCCP_CLOSED);
40-
sk_wake_async(sk, 1, POLL_HUP);
40+
sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_HUP);
4141
}
4242

4343
static void dccp_rcv_closereq(struct sock *sk, struct sk_buff *skb)
@@ -90,7 +90,7 @@ static void dccp_rcv_reset(struct sock *sk, struct sk_buff *skb)
9090
dccp_fin(sk, skb);
9191

9292
if (err && !sock_flag(sk, SOCK_DEAD))
93-
sk_wake_async(sk, 0, POLL_ERR);
93+
sk_wake_async(sk, SOCK_WAKE_IO, POLL_ERR);
9494
dccp_time_wait(sk, DCCP_TIME_WAIT, 0);
9595
}
9696

@@ -416,7 +416,7 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
416416

417417
if (!sock_flag(sk, SOCK_DEAD)) {
418418
sk->sk_state_change(sk);
419-
sk_wake_async(sk, 0, POLL_OUT);
419+
sk_wake_async(sk, SOCK_WAKE_IO, POLL_OUT);
420420
}
421421

422422
if (sk->sk_write_pending || icsk->icsk_ack.pingpong ||
@@ -624,7 +624,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
624624
switch (old_state) {
625625
case DCCP_PARTOPEN:
626626
sk->sk_state_change(sk);
627-
sk_wake_async(sk, 0, POLL_OUT);
627+
sk_wake_async(sk, SOCK_WAKE_IO, POLL_OUT);
628628
break;
629629
}
630630
} else if (unlikely(dh->dccph_type == DCCP_PKT_SYNC)) {

‎net/dccp/output.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void dccp_write_space(struct sock *sk)
170170
wake_up_interruptible(sk->sk_sleep);
171171
/* Should agree with poll, otherwise some programs break */
172172
if (sock_writeable(sk))
173-
sk_wake_async(sk, 2, POLL_OUT);
173+
sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
174174

175175
read_unlock(&sk->sk_callback_lock);
176176
}

‎net/ipv4/tcp_input.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,9 +3595,9 @@ static void tcp_fin(struct sk_buff *skb, struct sock *sk, struct tcphdr *th)
35953595
/* Do not send POLL_HUP for half duplex close. */
35963596
if (sk->sk_shutdown == SHUTDOWN_MASK ||
35973597
sk->sk_state == TCP_CLOSE)
3598-
sk_wake_async(sk, 1, POLL_HUP);
3598+
sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_HUP);
35993599
else
3600-
sk_wake_async(sk, 1, POLL_IN);
3600+
sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
36013601
}
36023602
}
36033603

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

49574957
if (!sock_flag(sk, SOCK_DEAD)) {
49584958
sk->sk_state_change(sk);
4959-
sk_wake_async(sk, 0, POLL_OUT);
4959+
sk_wake_async(sk, SOCK_WAKE_IO, POLL_OUT);
49604960
}
49614961

49624962
if (sk->sk_write_pending ||
@@ -5186,9 +5186,9 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
51865186
* are not waked up, because sk->sk_sleep ==
51875187
* NULL and sk->sk_socket == NULL.
51885188
*/
5189-
if (sk->sk_socket) {
5190-
sk_wake_async(sk,0,POLL_OUT);
5191-
}
5189+
if (sk->sk_socket)
5190+
sk_wake_async(sk,
5191+
SOCK_WAKE_IO, POLL_OUT);
51925192

51935193
tp->snd_una = TCP_SKB_CB(skb)->ack_seq;
51945194
tp->snd_wnd = ntohs(th->window) <<

‎net/rxrpc/af_rxrpc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void rxrpc_write_space(struct sock *sk)
6565
if (rxrpc_writable(sk)) {
6666
if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
6767
wake_up_interruptible(sk->sk_sleep);
68-
sk_wake_async(sk, 2, POLL_OUT);
68+
sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
6969
}
7070
read_unlock(&sk->sk_callback_lock);
7171
}

‎net/sctp/socket.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6008,7 +6008,8 @@ static void __sctp_write_space(struct sctp_association *asoc)
60086008
*/
60096009
if (sock->fasync_list &&
60106010
!(sk->sk_shutdown & SEND_SHUTDOWN))
6011-
sock_wake_async(sock, 2, POLL_OUT);
6011+
sock_wake_async(sock,
6012+
SOCK_WAKE_SPACE, POLL_OUT);
60126013
}
60136014
}
60146015
}

‎net/socket.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,20 +1070,19 @@ int sock_wake_async(struct socket *sock, int how, int band)
10701070
if (!sock || !sock->fasync_list)
10711071
return -1;
10721072
switch (how) {
1073-
case 1:
1074-
1073+
case SOCK_WAKE_WAITD:
10751074
if (test_bit(SOCK_ASYNC_WAITDATA, &sock->flags))
10761075
break;
10771076
goto call_kill;
1078-
case 2:
1077+
case SOCK_WAKE_SPACE:
10791078
if (!test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags))
10801079
break;
10811080
/* fall through */
1082-
case 0:
1081+
case SOCK_WAKE_IO:
10831082
call_kill:
10841083
__kill_fasync(sock->fasync_list, SIGIO, band);
10851084
break;
1086-
case 3:
1085+
case SOCK_WAKE_URG:
10871086
__kill_fasync(sock->fasync_list, SIGURG, band);
10881087
}
10891088
return 0;

0 commit comments

Comments
 (0)