Skip to content

Commit 51d4aab

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 51d4aab

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

main/network.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const struct in6_addr in6addr_any = {0}; /* IN6ADDR_ANY_INIT; */
8787
# define PHP_TIMEOUT_ERROR_VALUE ETIMEDOUT
8888
#endif
8989

90+
9091
#ifdef HAVE_GETADDRINFO
9192
# if !defined(PHP_WIN32) && !defined(HAVE_GAI_STRERROR)
9293
/* {{{ php_gai_strerror */
@@ -512,7 +513,13 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po
512513
#endif
513514
#ifdef SO_REUSEPORT
514515
if (sockopts & STREAM_SOCKOP_SO_REUSEPORT) {
516+
# ifdef SO_REUSEPORT_LB
517+
/* Historically, SO_REUSEPORT on FreeBSD predates Linux version, however does not
518+
* involve load balancing grouping thus SO_REUSEPORT_LB is the genuine equivalent.*/
519+
setsockopt(sock, SOL_SOCKET, SO_REUSEPORT_LB, (char*)&sockoptval, sizeof(sockoptval));
520+
# else
515521
setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (char*)&sockoptval, sizeof(sockoptval));
522+
# endif
516523
}
517524
#endif
518525
#ifdef SO_BROADCAST

0 commit comments

Comments
 (0)