unix: turn on SO_REUSEPORT for UDP sockets

Required on BSD-like systems for local UDP multicast. Without it, the bind()
call fails with EADDRINUSE.
This commit is contained in:
Ben Noordhuis 2012-01-27 00:31:13 +01:00
parent b88bc43543
commit 9c76d0d742

View File

@ -340,6 +340,14 @@ static int uv__bind(uv_udp_t* handle,
goto out;
}
#ifdef SO_REUSEPORT /* Apple's version of SO_REUSEADDR... */
yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof yes) == -1) {
uv__set_sys_error(handle->loop, errno);
goto out;
}
#endif
if (flags & UV_UDP_IPV6ONLY) {
#ifdef IPV6_V6ONLY
yes = 1;