linux: fix up SO_REUSEPORT back-port

Commit 3d2c820 back-ports a patch from the master branch that disables
the use of SO_REUSEPORT on Linux for reasons mentioned in the commit
log.

Unfortunately, the back-port was incomplete; another setsockopt() call
site in src/unix/udp.c was overlooked.  This commit rectifies that.

Hat tip to Luca Bruno for helping troubleshoot the issue.
This commit is contained in:
Ben Noordhuis 2013-11-25 16:09:55 +01:00
parent c3e05bafa5
commit 74457d08ba

View File

@ -491,7 +491,7 @@ int uv__udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned flags) {
int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
int saved_errno;
int status;
int yes;
int err;
saved_errno = errno;
status = -1;
@ -502,28 +502,12 @@ int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
goto out;
}
yes = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) == -1) {
uv__set_sys_error(handle->loop, errno);
err = uv__set_reuse(sock);
if (err) {
uv__set_sys_error(handle->loop, -err);
goto out;
}
/* On the BSDs, SO_REUSEADDR lets you reuse an address that's in the TIME_WAIT
* state (i.e. was until recently tied to a socket) while SO_REUSEPORT lets
* multiple processes bind to the same address. Yes, it's something of a
* misnomer but then again, SO_REUSEADDR was already taken.
*
* None of the above applies to Linux: SO_REUSEADDR implies SO_REUSEPORT on
* Linux and hence it does not have SO_REUSEPORT at all.
*/
#ifdef SO_REUSEPORT
yes = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof yes) == -1) {
uv__set_sys_error(handle->loop, errno);
goto out;
}
#endif
handle->io_watcher.fd = sock;
status = 0;