From 9c76d0d74218575c3898ec2e12311800c54c4adc Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 27 Jan 2012 00:31:13 +0100 Subject: [PATCH] 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. --- src/unix/udp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/unix/udp.c b/src/unix/udp.c index 3e5de929..6db0ea10 100644 --- a/src/unix/udp.c +++ b/src/unix/udp.c @@ -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;