Last active
July 24, 2019 03:03
-
-
Save kkumar-fk/b19ac21e4ceed37046dc1c88a7cdcf63 to your computer and use it in GitHub Desktop.
code blob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct sock *reuseport_select_sock(struct sock *sk, unsigned int phash) | |
{ | |
/* Get control block of sockets in this SO_REUSEPORT group */ | |
struct sock_reuseport *reuse = sk->sk_reuseport_cb; | |
/* Get count of sockets in the group */ | |
int num_socks = reuse->num_socks; | |
/* Calculate value between 0 and 'num_socks-1' (both inclusive) */ | |
unsigned int index = reciprocal_scale(phash, num_socks); | |
/* Index into the SO_REUSEPORT group using this index, and return that socket */ | |
return reuse->socks[index]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment