unix: do not close udp sockets on bind error

This makes Unix behave in the same way as Windows.

Fixes: https://github.com/libuv/libuv/issues/1336
PR-URL: https://github.com/libuv/libuv/pull/1337
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
Marc Schlaich 2017-05-08 12:06:07 +02:00 committed by cjihrig
parent cb0cc7346d
commit e11dcd4377

View File

@ -307,7 +307,7 @@ int uv__udp_bind(uv_udp_t* handle,
if (flags & UV_UDP_REUSEADDR) {
err = uv__set_reuse(fd);
if (err)
goto out;
return err;
}
if (flags & UV_UDP_IPV6ONLY) {
@ -315,11 +315,11 @@ int uv__udp_bind(uv_udp_t* handle,
yes = 1;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof yes) == -1) {
err = -errno;
goto out;
return err;
}
#else
err = -ENOTSUP;
goto out;
return err;
#endif
}
@ -329,20 +329,14 @@ int uv__udp_bind(uv_udp_t* handle,
/* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a
* socket created with AF_INET to an AF_INET6 address or vice versa. */
err = -EINVAL;
goto out;
return err;
}
if (addr->sa_family == AF_INET6)
handle->flags |= UV_HANDLE_IPV6;
handle->flags |= UV_HANDLE_BOUND;
return 0;
out:
uv__close(handle->io_watcher.fd);
handle->io_watcher.fd = -1;
return err;
}