SO_REUSEPORT on macOS with libuv

759 views Asked by At

the SO_REUSEPORT option not works on macOS with libuv.

uv_loop_init

uv_tcp_init_ex

uv_fileno // get fd

int option_value = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &option_value, sizeof (int)

uv_tcp_bind

uv_thread_create 4

I see 4 same address and port binding at 0.0.0.0:8080, but only thread1's connection_cb works, so can I use this option with my program? thx.

1

There are 1 answers

2
saghul On BEST ANSWER

macOS (and other BSDs) have a different SO_REUSEPORT implementation than Linux. On (relatively) recent Linux versions it will allow you to kernel level load balancing, but on BSDs only the last socket to bind will get the connections.

Long story short, it cannot be made to work, alas.