Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge remote-tracking branch 'origin/v0.6'

  • Loading branch information...
bnoordhuis committed Jan 23, 2012
2 parents 517bfc8 + edbabe6 commit 1cca230d76f1990f310bb005121b46a7f8b73534
Showing with 71 additions and 0 deletions.
  1. +26 −0 include/uv.h
  2. +24 −0 src/unix/udp.c
  3. +21 −0 src/win/udp.c
@@ -653,6 +653,32 @@ UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle,
const char* multicast_addr, const char* interface_addr,
uv_membership membership);

/*
* Set the multicast ttl
*
* Arguments:
* handle UDP handle. Should have been initialized with
* `uv_udp_init`.
* ttl 1 through 255
*
* Returns:
* 0 on success, -1 on error.
*/
int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);

/*
* Set broadcast on or off
*
* Arguments:
* handle UDP handle. Should have been initialized with
* `uv_udp_init`.
* on 1 for on, 0 for off
*
* Returns:
* 0 on success, -1 on error.
*/
int uv_udp_set_broadcast(uv_udp_t* handle, int on);

/*
* Send data. If the socket has not previously been bound with `uv_udp_bind`
* or `uv_udp_bind6`, it is bound to 0.0.0.0 (the "all interfaces" address)
@@ -337,6 +337,12 @@ static int uv__bind(uv_udp_t* handle,
goto out;
}

yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) == -1) {
uv__set_sys_error(handle->loop, errno);
goto out;
}

if (flags & UV_UDP_IPV6ONLY) {
#ifdef IPV6_V6ONLY
yes = 1;
@@ -506,6 +512,24 @@ int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr,
return 0;
}

int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) {
if (setsockopt(handle->fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof ttl) == -1) {
uv__set_sys_error(handle->loop, errno);
return -1;
}

return 0;
}

int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
if (setsockopt(handle->fd, SOL_SOCKET, SO_BROADCAST, &on, sizeof on) == -1) {
uv__set_sys_error(handle->loop, errno);
return -1;
}

return 0;
}


int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
int* namelen) {
@@ -574,3 +574,24 @@ void uv_process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle,
DECREASE_PENDING_REQ_COUNT(handle);
}


int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) {
if (setsockopt(handle->socket, IPPROTO_IP, IP_MULTICAST_TTL,
(const char*)&ttl, sizeof ttl) == -1) {
uv__set_sys_error(handle->loop, WSAGetLastError());
return -1;
}

return 0;
}


int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
if (setsockopt(handle->socket, SOL_SOCKET, SO_BROADCAST, (const char*)&on,
sizeof on) == -1) {
uv__set_sys_error(handle->loop, WSAGetLastError());
return -1;
}

return 0;
}

0 comments on commit 1cca230

Please sign in to comment.
You can’t perform that action at this time.