Skip to content

Commit

Permalink
Windows: enable SO_REUSEADDR for datagram sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Jan 31, 2012
1 parent 8c8e653 commit 62d9360
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/win/udp.c
Expand Up @@ -166,9 +166,9 @@ static int uv__bind(uv_udp_t* handle,
struct sockaddr* addr,
int addrsize,
unsigned int flags) {
DWORD err;
int r;
SOCKET sock;
DWORD no = 0, yes = 1;

if ((flags & UV_UDP_IPV6ONLY) && domain != AF_INET6) {
/* UV_UDP_IPV6ONLY is supported only for IPV6 sockets */
Expand All @@ -190,7 +190,6 @@ static int uv__bind(uv_udp_t* handle,
}

if (domain == AF_INET6 && !(flags & UV_UDP_IPV6ONLY)) {
DWORD off = 0;
/* On windows IPV6ONLY is on by default. */
/* If the user doesn't specify it libuv turns it off. */

Expand All @@ -200,14 +199,22 @@ static int uv__bind(uv_udp_t* handle,
setsockopt(sock,
IPPROTO_IPV6,
IPV6_V6ONLY,
(const char*) &off,
sizeof off);
(char*) &no,
sizeof no);
}

r = bind(handle->socket, addr, addrsize);
r = setsockopt(sock,
SOL_SOCKET,
SO_REUSEADDR,
(char*) &yes,
sizeof yes);
if (r == SOCKET_ERROR) {
uv__set_sys_error(handle->loop, WSAGetLastError());
return -1;
}

r = bind(handle->socket, addr, addrsize);
if (r == SOCKET_ERROR) {
err = WSAGetLastError();
uv__set_sys_error(handle->loop, WSAGetLastError());
return -1;
}
Expand Down

0 comments on commit 62d9360

Please sign in to comment.