1
0
mirror of https://github.com/libuv/libuv synced 2025-03-28 21:13:16 +00:00

include: merge uv_udp_bind and uv_udp_bind6

Merge uv_udp_bind6() into uv_udp_bind().  uv_udp_bind() now takes a
const struct sockaddr*.
This commit is contained in:
Ben Noordhuis 2013-09-03 23:49:26 +02:00
parent 5c675c4a4e
commit bcee403ed2
11 changed files with 26 additions and 47 deletions

View File

@ -804,7 +804,7 @@ struct uv_connect_s {
*/
enum uv_udp_flags {
/* Disables dual stack mode. Used with uv_udp_bind6(). */
/* Disables dual stack mode. */
UV_UDP_IPV6ONLY = 1,
/*
* Indicates message was truncated because read buffer was too small. The
@ -883,7 +883,8 @@ UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
*
* Arguments:
* handle UDP handle. Should have been initialized with `uv_udp_init`.
* addr struct sockaddr_in with the address and port to bind to.
* addr struct sockaddr_in or struct sockaddr_in6 with the address and
* port to bind to.
* flags Unused.
*
* Returns:
@ -898,23 +899,8 @@ UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
* opt-in mechanism in future versions of libuv.
*/
UV_EXTERN int uv_udp_bind(uv_udp_t* handle,
const struct sockaddr_in* addr,
unsigned flags);
/*
* Bind to a IPv6 address and port.
*
* Arguments:
* handle UDP handle. Should have been initialized with `uv_udp_init`.
* addr struct sockaddr_in with the address and port to bind to.
* flags Should be 0 or UV_UDP_IPV6ONLY.
*
* Returns:
* 0 on success, or an error code < 0 on failure.
*/
UV_EXTERN int uv_udp_bind6(uv_udp_t* handle,
const struct sockaddr_in6* addr,
unsigned flags);
const struct sockaddr* addr,
unsigned int flags);
UV_EXTERN int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
int* namelen);

View File

@ -209,28 +209,21 @@ int uv_tcp_bind(uv_tcp_t* handle, const struct sockaddr* addr) {
int uv_udp_bind(uv_udp_t* handle,
const struct sockaddr_in* addr,
const struct sockaddr* addr,
unsigned int flags) {
if (handle->type == UV_UDP && addr->sin_family == AF_INET) {
return uv__udp_bind(handle,
(const struct sockaddr*) addr,
sizeof(*addr),
flags);
}
return UV_EINVAL;
}
unsigned int addrlen;
if (handle->type != UV_UDP)
return UV_EINVAL;
int uv_udp_bind6(uv_udp_t* handle,
const struct sockaddr_in6* addr,
unsigned int flags) {
if (handle->type == UV_UDP && addr->sin6_family == AF_INET6) {
return uv__udp_bind(handle,
(const struct sockaddr*) addr,
sizeof(*addr),
flags);
}
return UV_EINVAL;
if (addr->sa_family == AF_INET)
addrlen = sizeof(struct sockaddr_in);
else if (addr->sa_family == AF_INET6)
addrlen = sizeof(struct sockaddr_in6);
else
return UV_EINVAL;
return uv__udp_bind(handle, addr, addrlen, flags);
}

View File

@ -174,7 +174,7 @@ static int pummel(unsigned int n_senders,
struct sockaddr_in addr;
ASSERT(0 == uv_ip4_addr("0.0.0.0", BASE_PORT + i, &addr));
ASSERT(0 == uv_udp_init(loop, &s->udp_handle));
ASSERT(0 == uv_udp_bind(&s->udp_handle, &addr, 0));
ASSERT(0 == uv_udp_bind(&s->udp_handle, (const struct sockaddr*) &addr, 0));
ASSERT(0 == uv_udp_recv_start(&s->udp_handle, alloc_cb, recv_cb));
uv_unref((uv_handle_t*)&s->udp_handle);
}

View File

@ -282,7 +282,7 @@ static int udp_listener(void) {
return 1;
}
r = uv_udp_bind(&udpServer, &addr, 0);
r = uv_udp_bind(&udpServer, (const struct sockaddr*) &addr, 0);
if (r) {
fprintf(stderr, "Bind error\n");
return 1;

View File

@ -308,7 +308,7 @@ TEST_IMPL(udp_ref2) {
uv_udp_t h;
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
uv_udp_init(uv_default_loop(), &h);
uv_udp_bind(&h, &addr, 0);
uv_udp_bind(&h, (const struct sockaddr*) &addr, 0);
uv_udp_recv_start(&h, (uv_alloc_cb)fail_cb, (uv_udp_recv_cb)fail_cb);
uv_unref((uv_handle_t*)&h);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);

View File

@ -108,7 +108,7 @@ static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) {
r = uv_udp_init(uv_default_loop(), &server);
ASSERT(r == 0);
r = uv_udp_bind6(&server, &addr6, bind_flags);
r = uv_udp_bind(&server, (const struct sockaddr*) &addr6, bind_flags);
ASSERT(r == 0);
r = uv_udp_recv_start(&server, alloc_cb, recv_cb);

View File

@ -111,7 +111,7 @@ TEST_IMPL(udp_multicast_join) {
ASSERT(r == 0);
/* bind to the desired port */
r = uv_udp_bind(&client, &addr, 0);
r = uv_udp_bind(&client, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
/* join the multicast channel */

View File

@ -63,7 +63,7 @@ TEST_IMPL(udp_multicast_ttl) {
ASSERT(r == 0);
ASSERT(0 == uv_ip4_addr("0.0.0.0", 0, &addr));
r = uv_udp_bind(&server, &addr, 0);
r = uv_udp_bind(&server, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
r = uv_udp_set_multicast_ttl(&server, 32);

View File

@ -140,7 +140,7 @@ TEST_IMPL(udp_open) {
r = uv_udp_open(&client, sock);
ASSERT(r == 0);
r = uv_udp_bind(&client, &addr, 0);
r = uv_udp_bind(&client, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
r = uv_udp_recv_start(&client, alloc_cb, recv_cb);

View File

@ -43,7 +43,7 @@ TEST_IMPL(udp_options) {
uv_unref((uv_handle_t*)&h); /* don't keep the loop alive */
r = uv_udp_bind(&h, &addr, 0);
r = uv_udp_bind(&h, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
r = uv_udp_set_broadcast(&h, 1);

View File

@ -175,7 +175,7 @@ TEST_IMPL(udp_send_and_recv) {
r = uv_udp_init(uv_default_loop(), &server);
ASSERT(r == 0);
r = uv_udp_bind(&server, &addr, 0);
r = uv_udp_bind(&server, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);
r = uv_udp_recv_start(&server, alloc_cb, sv_recv_cb);