Skip to content

Commit

Permalink
net: pass back whether socket was empty post accept
Browse files Browse the repository at this point in the history
This adds an 'is_empty' argument to struct proto_accept_arg, which can
be used to pass back information on whether or not the given socket has
more connections to accept post the one just accepted.

To utilize this information, the caller should initialize the 'is_empty'
field to, eg, -1 and then check for 0/1 after the accept. If the field
has been set, the caller knows whether there are more pending connections
or not. If the field remains -1 after the accept call, the protocol
doesn't support passing back this information.

This patch wires it up for ipv4/6 TCP.

Acked-by: Jakub Kicinski <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed May 14, 2024
1 parent 0645fbe commit 7951e36
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ static inline void sk_prot_clear_nulls(struct sock *sk, int size)
struct proto_accept_arg {
int flags;
int err;
int is_empty;
bool kern;
};

Expand Down
1 change: 1 addition & 0 deletions net/ipv4/inet_connection_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ struct sock *inet_csk_accept(struct sock *sk, struct proto_accept_arg *arg)
goto out_err;
}
req = reqsk_queue_remove(queue, sk);
arg->is_empty = reqsk_queue_empty(queue);
newsk = req->sk;

if (sk->sk_protocol == IPPROTO_TCP &&
Expand Down

0 comments on commit 7951e36

Please sign in to comment.