Skip to content

Commit f900035

Browse files
devnexenbukka
andcommitted
network: on freebsd using SO_REUSEPORT_LB for a better distribution.
SO_REUSEPORT on FreeBSD acts differently as the underlying semantic is different (as it predates Linux) since it s more for UDP/multicasts. The SO_REUSEPORT_LB flag, however, uses load balancing for group of address:port combinations which is how Linux is implemented. Co-authored-by: Jakub Zelenka <bukka@php.net>
1 parent aead67d commit f900035

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

main/network.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,13 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po
512512
#endif
513513
#ifdef SO_REUSEPORT
514514
if (sockopts & STREAM_SOCKOP_SO_REUSEPORT) {
515+
# ifdef SO_REUSEPORT_LB
516+
/* Historically, SO_REUSEPORT on FreeBSD predates Linux version, however does not
517+
* involve load balancing grouping thus SO_REUSEPORT_LB is the genuine equivalent.*/
518+
setsockopt(sock, SOL_SOCKET, SO_REUSEPORT_LB, (char*)&sockoptval, sizeof(sockoptval));
519+
# else
515520
setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (char*)&sockoptval, sizeof(sockoptval));
521+
# endif
516522
}
517523
#endif
518524
#ifdef SO_BROADCAST

0 commit comments

Comments
 (0)