Skip to content
Browse files

unix, windows: Use of address struct by reference in uv_tcp_connect, …

…uv_*_bind.
  • Loading branch information...
1 parent e4d8cba commit 1ca0eb570f5bd58ab0917bd3f179390e60b0916c @txdv txdv committed Jan 18, 2013
View
30 include/uv.h
@@ -661,23 +661,20 @@ UV_EXTERN int uv_tcp_keepalive(uv_tcp_t* handle,
*/
UV_EXTERN int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable);
-UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in);
-UV_EXTERN int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6);
+UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr* addr);
UV_EXTERN int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name,
int* namelen);
UV_EXTERN int uv_tcp_getpeername(uv_tcp_t* handle, struct sockaddr* name,
int* namelen);
/*
- * uv_tcp_connect, uv_tcp_connect6
- * These functions establish IPv4 and IPv6 TCP connections. Provide an
+ * uv_tcp_connect
+ * This function establishes an IPv4 or IPv6 TCP connection. Provide an
* initialized TCP handle and an uninitialized uv_connect_t*. The callback
* will be made when the connection is established.
*/
UV_EXTERN int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle,
- struct sockaddr_in address, uv_connect_cb cb);
-UV_EXTERN int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle,
- struct sockaddr_in6 address, uv_connect_cb cb);
+ struct sockaddr* addr, uv_connect_cb cb);
/* uv_connect_t is a subclass of uv_req_t */
struct uv_connect_s {
@@ -751,32 +748,19 @@ UV_EXTERN int uv_udp_init(uv_loop_t*, uv_udp_t* handle);
UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
/*
- * Bind to a IPv4 address and port.
+ * Bind to a an 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.
+ * addr struct sockaddr with the address and port to bind to.
* flags Unused.
*
* Returns:
* 0 on success, -1 on error.
*/
-UV_EXTERN int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr,
+UV_EXTERN int uv_udp_bind(uv_udp_t* handle, struct sockaddr* 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, -1 on error.
- */
-UV_EXTERN int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr,
- unsigned flags);
UV_EXTERN int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
int* namelen);
View
41 src/unix/tcp.c
@@ -128,19 +128,16 @@ static int uv__connect(uv_connect_t* req,
}
-int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
- return uv__bind(handle,
- AF_INET,
- (struct sockaddr*)&addr,
- sizeof(struct sockaddr_in));
-}
-
+int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr* addr) {
+ if (addr->sa_family != AF_INET && addr->sa_family != AF_INET6) {
+ uv__set_artificial_error(handle->loop, UV_EINVAL);
+ return -1;
+ }
-int uv__tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
return uv__bind(handle,
- AF_INET6,
- (struct sockaddr*)&addr,
- sizeof(struct sockaddr_in6));
+ addr->sa_family,
+ addr,
+ addr->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6));
}
@@ -257,28 +254,18 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
int uv__tcp_connect(uv_connect_t* req,
uv_tcp_t* handle,
- struct sockaddr_in addr,
+ struct sockaddr* addr,
uv_connect_cb cb) {
int saved_errno;
int status;
- saved_errno = errno;
- status = uv__connect(req, handle, (struct sockaddr*)&addr, sizeof addr, cb);
- errno = saved_errno;
-
- return status;
-}
-
-
-int uv__tcp_connect6(uv_connect_t* req,
- uv_tcp_t* handle,
- struct sockaddr_in6 addr,
- uv_connect_cb cb) {
- int saved_errno;
- int status;
+ if (addr->sa_family != AF_INET && addr->sa_family != AF_INET6) {
+ uv__set_artificial_error(handle->loop, UV_EINVAL);
+ return -1;
+ }
saved_errno = errno;
- status = uv__connect(req, handle, (struct sockaddr*)&addr, sizeof addr, cb);
+ status = uv__connect(req, handle, addr, addr->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), cb);
errno = saved_errno;
return status;
View
20 src/unix/udp.c
@@ -456,20 +456,16 @@ int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) {
}
-int uv__udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned flags) {
- return uv__bind(handle,
- AF_INET,
- (struct sockaddr*)&addr,
- sizeof addr,
- flags);
-}
-
+int uv__udp_bind(uv_udp_t* handle, struct sockaddr* addr, unsigned flags) {
+ if (addr->sa_family != AF_INET && addr->sa_family != AF_INET6) {
+ uv__set_artificial_error(handle->loop, UV_EINVAL);
+ return -1;
+ }
-int uv__udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned flags) {
return uv__bind(handle,
- AF_INET6,
- (struct sockaddr*)&addr,
- sizeof addr,
+ addr->sa_family,
+ addr,
+ addr->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6),
flags);
}
View
48 src/uv-common.c
@@ -196,8 +196,8 @@ int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size) {
}
-int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
- if (handle->type != UV_TCP || addr.sin_family != AF_INET) {
+int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr* addr) {
+ if (handle->type != UV_TCP) {
uv__set_artificial_error(handle->loop, UV_EINVAL);
return -1;
}
@@ -206,19 +206,9 @@ int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
}
-int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
- if (handle->type != UV_TCP || addr.sin6_family != AF_INET6) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
- }
-
- return uv__tcp_bind6(handle, addr);
-}
-
-
-int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr,
+int uv_udp_bind(uv_udp_t* handle, struct sockaddr *addr,
unsigned int flags) {
- if (handle->type != UV_UDP || addr.sin_family != AF_INET) {
+ if (handle->type != UV_UDP) {
uv__set_artificial_error(handle->loop, UV_EINVAL);
return -1;
}
@@ -227,40 +217,16 @@ int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr,
}
-int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr,
- unsigned int flags) {
- if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
- }
-
- return uv__udp_bind6(handle, addr, flags);
-}
-
-
int uv_tcp_connect(uv_connect_t* req,
uv_tcp_t* handle,
- struct sockaddr_in address,
+ struct sockaddr* addr,
uv_connect_cb cb) {
- if (handle->type != UV_TCP || address.sin_family != AF_INET) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
- }
-
- return uv__tcp_connect(req, handle, address, cb);
-}
-
-
-int uv_tcp_connect6(uv_connect_t* req,
- uv_tcp_t* handle,
- struct sockaddr_in6 address,
- uv_connect_cb cb) {
- if (handle->type != UV_TCP || address.sin6_family != AF_INET6) {
+ if (handle->type != UV_TCP) {
uv__set_artificial_error(handle->loop, UV_EINVAL);
return -1;
}
- return uv__tcp_connect6(req, handle, address, cb);
+ return uv__tcp_connect(req, handle, addr, cb);
}
View
13 src/uv-common.h
@@ -77,22 +77,15 @@ int uv__set_artificial_error(uv_loop_t* loop, uv_err_code code);
uv_err_t uv__new_sys_error(int sys_error);
uv_err_t uv__new_artificial_error(uv_err_code code);
-int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr);
-int uv__tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr);
+int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr* addr);
-int uv__udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned flags);
-int uv__udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned flags);
+int uv__udp_bind(uv_udp_t* handle, struct sockaddr* addr, unsigned flags);
int uv__tcp_connect(uv_connect_t* req,
uv_tcp_t* handle,
- struct sockaddr_in address,
+ struct sockaddr* addr,
uv_connect_cb cb);
-int uv__tcp_connect6(uv_connect_t* req,
- uv_tcp_t* handle,
- struct sockaddr_in6 address,
- uv_connect_cb cb);
-
void uv__fs_poll_close(uv_fs_poll_t* handle);
View
2 test/blackhole-server.c
@@ -105,7 +105,7 @@ HELPER_IMPL(tcp4_blackhole_server) {
r = uv_tcp_init(loop, &tcp_server);
ASSERT(r == 0);
- r = uv_tcp_bind(&tcp_server, addr);
+ r = uv_tcp_bind(&tcp_server, (struct sockaddr *)&addr);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&tcp_server, 128, connection_cb);
View
4 test/echo-server.c
@@ -225,7 +225,7 @@ static int tcp4_echo_start(int port) {
return 1;
}
- r = uv_tcp_bind(&tcpServer, addr);
+ r = uv_tcp_bind(&tcpServer, (struct sockaddr *)&addr);
if (r) {
/* TODO: Error codes */
fprintf(stderr, "Bind error\n");
@@ -259,7 +259,7 @@ static int tcp6_echo_start(int port) {
}
/* IPv6 is optional as not all platforms support it */
- r = uv_tcp_bind6(&tcpServer, addr6);
+ r = uv_tcp_bind(&tcpServer, (struct sockaddr *)&addr6);
if (r) {
/* show message but return OK */
fprintf(stderr, "IPv6 not supported\n");
View
2 test/test-callback-stack.c
@@ -184,7 +184,7 @@ TEST_IMPL(callback_stack) {
nested++;
- if (uv_tcp_connect(&connect_req, &client, addr, connect_cb)) {
+ if (uv_tcp_connect(&connect_req, &client, (struct sockaddr *)&addr, connect_cb)) {
FATAL("uv_tcp_connect failed");
}
nested--;
View
4 test/test-connection-fail.c
@@ -103,8 +103,8 @@ static void connection_fail(uv_connect_cb connect_cb) {
/* We are never doing multiple reads/connects at a time anyway. */
/* so these handles can be pre-initialized. */
- uv_tcp_bind(&tcp, client_addr);
- r = uv_tcp_connect(&req, &tcp, server_addr, connect_cb);
+ uv_tcp_bind(&tcp, (struct sockaddr *)&client_addr);
+ r = uv_tcp_connect(&req, &tcp, (struct sockaddr *)&server_addr, connect_cb);
ASSERT(!r);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
View
4 test/test-delayed-accept.c
@@ -109,7 +109,7 @@ static void start_server(void) {
r = uv_tcp_init(uv_default_loop(), server);
ASSERT(r == 0);
- r = uv_tcp_bind(server, addr);
+ r = uv_tcp_bind(server, (struct sockaddr *)&addr);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)server, 128, connection_cb);
@@ -165,7 +165,7 @@ static void client_connect(void) {
r = uv_tcp_init(uv_default_loop(), client);
ASSERT(r == 0);
- r = uv_tcp_connect(connect_req, client, addr, connect_cb);
+ r = uv_tcp_connect(connect_req, client, (struct sockaddr *)&addr, connect_cb);
ASSERT(r == 0);
}
View
6 test/test-getsockname.c
@@ -177,7 +177,7 @@ static int tcp_listener(void) {
return 1;
}
- r = uv_tcp_bind(&tcpServer, addr);
+ r = uv_tcp_bind(&tcpServer, (struct sockaddr *)&addr);
if (r) {
fprintf(stderr, "Bind error\n");
return 1;
@@ -215,7 +215,7 @@ static void tcp_connector(void) {
tcp.data = &connect_req;
ASSERT(!r);
- r = uv_tcp_connect(&connect_req, &tcp, server_addr, on_connect);
+ r = uv_tcp_connect(&connect_req, &tcp, (struct sockaddr *)&server_addr, on_connect);
ASSERT(!r);
/* Fetch the actual port used by the connecting socket. */
@@ -273,7 +273,7 @@ static int udp_listener(void) {
return 1;
}
- r = uv_udp_bind(&udpServer, addr, 0);
+ r = uv_udp_bind(&udpServer, (struct sockaddr *)&addr, 0);
if (r) {
fprintf(stderr, "Bind error\n");
return 1;
View
3 test/test-ipc-send-recv.c
@@ -132,14 +132,15 @@ TEST_IMPL(ipc_send_recv_pipe) {
TEST_IMPL(ipc_send_recv_tcp) {
+ struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
int r;
ctx.expected_type = UV_TCP;
r = uv_tcp_init(uv_default_loop(), &ctx.send.tcp);
ASSERT(r == 0);
- r = uv_tcp_bind(&ctx.send.tcp, uv_ip4_addr("127.0.0.1", TEST_PORT));
+ r = uv_tcp_bind(&ctx.send.tcp, (struct sockaddr*)&addr);
ASSERT(r == 0);
r = run_test();
View
11 test/test-ipc.c
@@ -122,7 +122,7 @@ static void make_many_connections(void) {
addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
- r = uv_tcp_connect(&conn->conn_req, (uv_tcp_t*)&conn->conn, addr, connect_cb);
+ r = uv_tcp_connect(&conn->conn_req, (uv_tcp_t*)&conn->conn, (struct sockaddr *)&addr, connect_cb);
ASSERT(r == 0);
conn->conn.data = conn;
@@ -534,6 +534,7 @@ int ipc_helper(int listen_after_write) {
*/
uv_write_t write_req;
+ struct sockaddr_in addr;
int r;
uv_buf_t buf;
@@ -549,7 +550,8 @@ int ipc_helper(int listen_after_write) {
r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);
- r = uv_tcp_bind(&tcp_server, uv_ip4_addr("0.0.0.0", TEST_PORT));
+ addr = uv_ip4_addr("0.0.0.0", TEST_PORT);
+ r = uv_tcp_bind(&tcp_server, (struct sockaddr *)&addr);
ASSERT(r == 0);
if (!listen_after_write) {
@@ -599,7 +601,8 @@ int ipc_helper_tcp_connection(void) {
r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);
- r = uv_tcp_bind(&tcp_server, uv_ip4_addr("0.0.0.0", TEST_PORT));
+ addr = uv_ip4_addr("0.0.0.0", TEST_PORT);
+ r = uv_tcp_bind(&tcp_server, (struct sockaddr *)&addr);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&tcp_server, 12, ipc_on_connection_tcp_conn);
@@ -610,7 +613,7 @@ int ipc_helper_tcp_connection(void) {
ASSERT(r == 0);
addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
- r = uv_tcp_connect(&conn.conn_req, (uv_tcp_t*)&conn.conn, addr, connect_child_process_cb);
+ r = uv_tcp_connect(&conn.conn_req, (uv_tcp_t*)&conn.conn, (struct sockaddr *)&addr, connect_child_process_cb);
ASSERT(r == 0);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
View
4 test/test-multiple-listen.c
@@ -51,7 +51,7 @@ static void start_server(void) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_bind(&server, addr);
+ r = uv_tcp_bind(&server, (struct sockaddr*)&addr);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&server, 128, connection_cb);
@@ -81,7 +81,7 @@ static void client_connect(void) {
r = uv_tcp_init(uv_default_loop(), &client);
ASSERT(r == 0);
- r = uv_tcp_connect(connect_req, &client, addr, connect_cb);
+ r = uv_tcp_connect(connect_req, &client, (struct sockaddr*)&addr, connect_cb);
ASSERT(r == 0);
}
View
6 test/test-ping-pong.c
@@ -159,8 +159,8 @@ static void tcp_pinger_v6_new(void) {
/* We are never doing multiple reads/connects at a time anyway. */
/* so these handles can be pre-initialized. */
- r = uv_tcp_connect6(&pinger->connect_req, &pinger->stream.tcp, server_addr,
- pinger_on_connect);
+ r = uv_tcp_connect(&pinger->connect_req, &pinger->stream.tcp,
+ (struct sockaddr *)&server_addr, pinger_on_connect);
ASSERT(!r);
/* Synchronous connect callbacks are not allowed. */
@@ -184,7 +184,7 @@ static void tcp_pinger_new(void) {
/* We are never doing multiple reads/connects at a time anyway. */
/* so these handles can be pre-initialized. */
- r = uv_tcp_connect(&pinger->connect_req, &pinger->stream.tcp, server_addr,
+ r = uv_tcp_connect(&pinger->connect_req, &pinger->stream.tcp, (struct sockaddr*)&server_addr,
pinger_on_connect);
ASSERT(!r);
View
6 test/test-ref.c
@@ -257,7 +257,7 @@ TEST_IMPL(tcp_ref3) {
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
uv_tcp_t h;
uv_tcp_init(uv_default_loop(), &h);
- uv_tcp_connect(&connect_req, &h, addr, connect_and_shutdown);
+ uv_tcp_connect(&connect_req, &h, (struct sockaddr*)&addr, connect_and_shutdown);
uv_unref((uv_handle_t*)&h);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(connect_cb_called == 1);
@@ -272,7 +272,7 @@ TEST_IMPL(tcp_ref4) {
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
uv_tcp_t h;
uv_tcp_init(uv_default_loop(), &h);
- uv_tcp_connect(&connect_req, &h, addr, connect_and_write);
+ uv_tcp_connect(&connect_req, &h, (struct sockaddr*)&addr, connect_and_write);
uv_unref((uv_handle_t*)&h);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(connect_cb_called == 1);
@@ -299,7 +299,7 @@ TEST_IMPL(udp_ref2) {
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
uv_udp_t h;
uv_udp_init(uv_default_loop(), &h);
- uv_udp_bind(&h, addr, 0);
+ uv_udp_bind(&h, (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
2 test/test-shutdown-close.c
@@ -72,7 +72,7 @@ TEST_IMPL(shutdown_close_tcp) {
r = uv_tcp_init(uv_default_loop(), &h);
ASSERT(r == 0);
- r = uv_tcp_connect(&connect_req, &h, addr, connect_cb);
+ r = uv_tcp_connect(&connect_req, &h, (struct sockaddr*)&addr, connect_cb);
ASSERT(r == 0);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);
View
2 test/test-shutdown-eof.c
@@ -165,7 +165,7 @@ TEST_IMPL(shutdown_eof) {
r = uv_tcp_init(uv_default_loop(), &tcp);
ASSERT(!r);
- r = uv_tcp_connect(&connect_req, &tcp, server_addr, connect_cb);
+ r = uv_tcp_connect(&connect_req, &tcp, (struct sockaddr*)&server_addr, connect_cb);
ASSERT(!r);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
View
16 test/test-tcp-bind-error.c
@@ -41,12 +41,12 @@ TEST_IMPL(tcp_bind_error_addrinuse) {
r = uv_tcp_init(uv_default_loop(), &server1);
ASSERT(r == 0);
- r = uv_tcp_bind(&server1, addr);
+ r = uv_tcp_bind(&server1, (struct sockaddr*)&addr);
ASSERT(r == 0);
r = uv_tcp_init(uv_default_loop(), &server2);
ASSERT(r == 0);
- r = uv_tcp_bind(&server2, addr);
+ r = uv_tcp_bind(&server2, (struct sockaddr*)&addr);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&server1, 128, NULL);
@@ -75,7 +75,7 @@ TEST_IMPL(tcp_bind_error_addrnotavail_1) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_bind(&server, addr);
+ r = uv_tcp_bind(&server, (struct sockaddr*)&addr);
/* It seems that Linux is broken here - bind succeeds. */
if (r == -1) {
@@ -100,7 +100,7 @@ TEST_IMPL(tcp_bind_error_addrnotavail_2) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_bind(&server, addr);
+ r = uv_tcp_bind(&server, (struct sockaddr*)&addr);
ASSERT(r == -1);
ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL);
@@ -125,7 +125,7 @@ TEST_IMPL(tcp_bind_error_fault) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_bind(&server, *garbage_addr);
+ r = uv_tcp_bind(&server, (struct sockaddr*)garbage_addr);
ASSERT(r == -1);
ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
@@ -150,9 +150,9 @@ TEST_IMPL(tcp_bind_error_inval) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_bind(&server, addr1);
+ r = uv_tcp_bind(&server, (struct sockaddr*)&addr1);
ASSERT(r == 0);
- r = uv_tcp_bind(&server, addr2);
+ r = uv_tcp_bind(&server, (struct sockaddr*)&addr2);
ASSERT(r == -1);
ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
@@ -176,7 +176,7 @@ TEST_IMPL(tcp_bind_localhost_ok) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_bind(&server, addr);
+ r = uv_tcp_bind(&server, (struct sockaddr*)&addr);
ASSERT(r == 0);
MAKE_VALGRIND_HAPPY();
View
16 test/test-tcp-bind6-error.c
@@ -41,12 +41,12 @@ TEST_IMPL(tcp_bind6_error_addrinuse) {
r = uv_tcp_init(uv_default_loop(), &server1);
ASSERT(r == 0);
- r = uv_tcp_bind6(&server1, addr);
+ r = uv_tcp_bind(&server1, (struct sockaddr *)&addr);
ASSERT(r == 0);
r = uv_tcp_init(uv_default_loop(), &server2);
ASSERT(r == 0);
- r = uv_tcp_bind6(&server2, addr);
+ r = uv_tcp_bind(&server2, (struct sockaddr *)&addr);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&server1, 128, NULL);
@@ -75,7 +75,7 @@ TEST_IMPL(tcp_bind6_error_addrnotavail) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_bind6(&server, addr);
+ r = uv_tcp_bind(&server, (struct sockaddr *)&addr);
ASSERT(r == -1);
ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL);
@@ -100,7 +100,7 @@ TEST_IMPL(tcp_bind6_error_fault) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_bind6(&server, *garbage_addr);
+ r = uv_tcp_bind(&server, (struct sockaddr *)garbage_addr);
ASSERT(r == -1);
ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
@@ -115,7 +115,7 @@ TEST_IMPL(tcp_bind6_error_fault) {
return 0;
}
-/* Notes: On Linux uv_bind6(server, NULL) will segfault the program. */
+/* Notes: On Linux uv_bind(server, sockaddr_in6, NULL) (notice IPv6) will segfault the program. */
TEST_IMPL(tcp_bind6_error_inval) {
struct sockaddr_in6 addr1 = uv_ip6_addr("::", TEST_PORT);
@@ -125,9 +125,9 @@ TEST_IMPL(tcp_bind6_error_inval) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_bind6(&server, addr1);
+ r = uv_tcp_bind(&server, (struct sockaddr *)&addr1);
ASSERT(r == 0);
- r = uv_tcp_bind6(&server, addr2);
+ r = uv_tcp_bind(&server, (struct sockaddr *)&addr2);
ASSERT(r == -1);
ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
@@ -151,7 +151,7 @@ TEST_IMPL(tcp_bind6_localhost_ok) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_bind6(&server, addr);
+ r = uv_tcp_bind(&server, (struct sockaddr *)&addr);
ASSERT(r == 0);
MAKE_VALGRIND_HAPPY();
View
2 test/test-tcp-close-while-connecting.c
@@ -65,7 +65,7 @@ TEST_IMPL(tcp_close_while_connecting) {
loop = uv_default_loop();
ASSERT(0 == uv_tcp_init(loop, &tcp_handle));
- ASSERT(0 == uv_tcp_connect(&connect_req, &tcp_handle, addr, connect_cb));
+ ASSERT(0 == uv_tcp_connect(&connect_req, &tcp_handle, (struct sockaddr*)&addr, connect_cb));
ASSERT(0 == uv_timer_init(loop, &timer1_handle));
ASSERT(0 == uv_timer_start(&timer1_handle, timer1_cb, 50, 0));
ASSERT(0 == uv_timer_init(loop, &timer2_handle));
View
6 test/test-tcp-close.c
@@ -77,12 +77,13 @@ static void connection_cb(uv_stream_t* server, int status) {
static void start_server(uv_loop_t* loop, uv_tcp_t* handle) {
+ struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
int r;
r = uv_tcp_init(loop, handle);
ASSERT(r == 0);
- r = uv_tcp_bind(handle, uv_ip4_addr("127.0.0.1", TEST_PORT));
+ r = uv_tcp_bind(handle, (struct sockaddr*)&addr);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)handle, 128, connection_cb);
@@ -98,6 +99,7 @@ static void start_server(uv_loop_t* loop, uv_tcp_t* handle) {
TEST_IMPL(tcp_close) {
uv_loop_t* loop;
uv_tcp_t tcp_server;
+ struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
int r;
loop = uv_default_loop();
@@ -110,7 +112,7 @@ TEST_IMPL(tcp_close) {
r = uv_tcp_connect(&connect_req,
&tcp_handle,
- uv_ip4_addr("127.0.0.1", TEST_PORT),
+ (struct sockaddr*)&addr,
connect_cb);
ASSERT(r == 0);
View
2 test/test-tcp-connect-error-after-write.c
@@ -78,7 +78,7 @@ TEST_IMPL(tcp_connect_error_after_write) {
ASSERT(r == -1);
ASSERT(uv_last_error(uv_default_loop()).code == UV_EBADF);
- r = uv_tcp_connect(&connect_req, &conn, addr, connect_cb);
+ r = uv_tcp_connect(&connect_req, &conn, (struct sockaddr*)&addr, connect_cb);
ASSERT(r == 0);
r = uv_write(&write_req, (uv_stream_t*)&conn, &buf, 1, write_cb);
View
2 test/test-tcp-connect-error.c
@@ -54,7 +54,7 @@ TEST_IMPL(tcp_connect_error_fault) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_connect(&req, &server, *garbage_addr, connect_cb);
+ r = uv_tcp_connect(&req, &server, (struct sockaddr*)garbage_addr, connect_cb);
ASSERT(r == -1);
ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
View
2 test/test-tcp-connect-timeout.c
@@ -75,7 +75,7 @@ TEST_IMPL(tcp_connect_timeout) {
r = uv_tcp_init(uv_default_loop(), &conn);
ASSERT(r == 0);
- r = uv_tcp_connect(&connect_req, &conn, addr, connect_cb);
+ r = uv_tcp_connect(&connect_req, &conn, (struct sockaddr*)&addr, connect_cb);
ASSERT(r == 0);
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
View
2 test/test-tcp-connect6-error.c
@@ -52,7 +52,7 @@ TEST_IMPL(tcp_connect6_error_fault) {
r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_tcp_connect6(&req, &server, *garbage_addr, connect_cb);
+ r = uv_tcp_connect(&req, &server, (struct sockaddr *)garbage_addr, connect_cb);
ASSERT(r == -1);
ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
View
2 test/test-tcp-open.c
@@ -160,7 +160,7 @@ TEST_IMPL(tcp_open) {
r = uv_tcp_open(&client, sock);
ASSERT(r == 0);
- r = uv_tcp_connect(&connect_req, &client, addr, connect_cb);
+ r = uv_tcp_connect(&connect_req, &client, (struct sockaddr*)&addr, connect_cb);
ASSERT(r == 0);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
View
2 test/test-tcp-read-stop.c
@@ -65,7 +65,7 @@ TEST_IMPL(tcp_read_stop) {
addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
ASSERT(0 == uv_timer_init(uv_default_loop(), &timer_handle));
ASSERT(0 == uv_tcp_init(uv_default_loop(), &tcp_handle));
- ASSERT(0 == uv_tcp_connect(&connect_req, &tcp_handle, addr, connect_cb));
+ ASSERT(0 == uv_tcp_connect(&connect_req, &tcp_handle, (struct sockaddr*)&addr, connect_cb));
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
MAKE_VALGRIND_HAPPY();
View
2 test/test-tcp-shutdown-after-write.c
@@ -115,7 +115,7 @@ TEST_IMPL(tcp_shutdown_after_write) {
r = uv_tcp_init(loop, &conn);
ASSERT(r == 0);
- r = uv_tcp_connect(&connect_req, &conn, addr, connect_cb);
+ r = uv_tcp_connect(&connect_req, &conn, (struct sockaddr*)&addr, connect_cb);
ASSERT(r == 0);
r = uv_run(loop, UV_RUN_DEFAULT);
View
4 test/test-tcp-unexpected-read.c
@@ -98,9 +98,9 @@ TEST_IMPL(tcp_unexpected_read) {
ASSERT(0 == uv_tcp_init(loop, &server_handle));
ASSERT(0 == uv_tcp_init(loop, &client_handle));
ASSERT(0 == uv_tcp_init(loop, &peer_handle));
- ASSERT(0 == uv_tcp_bind(&server_handle, addr));
+ ASSERT(0 == uv_tcp_bind(&server_handle, (struct sockaddr*)&addr));
ASSERT(0 == uv_listen((uv_stream_t*) &server_handle, 1, connection_cb));
- ASSERT(0 == uv_tcp_connect(&connect_req, &client_handle, addr, connect_cb));
+ ASSERT(0 == uv_tcp_connect(&connect_req, &client_handle, (struct sockaddr*)&addr, connect_cb));
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
/* This is somewhat inexact but the idea is that the event loop should not
View
5 test/test-tcp-write-to-half-open-connection.c
@@ -102,6 +102,7 @@ static void write_cb(uv_write_t* req, int status) {
TEST_IMPL(tcp_write_to_half_open_connection) {
uv_loop_t* loop;
+ struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
int r;
loop = uv_default_loop();
@@ -110,7 +111,7 @@ TEST_IMPL(tcp_write_to_half_open_connection) {
r = uv_tcp_init(loop, &tcp_server);
ASSERT(r == 0);
- r = uv_tcp_bind(&tcp_server, uv_ip4_addr("127.0.0.1", TEST_PORT));
+ r = uv_tcp_bind(&tcp_server, (struct sockaddr*)&addr);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&tcp_server, 1, connection_cb);
@@ -121,7 +122,7 @@ TEST_IMPL(tcp_write_to_half_open_connection) {
r = uv_tcp_connect(&connect_req,
&tcp_client,
- uv_ip4_addr("127.0.0.1", TEST_PORT),
+ (struct sockaddr*)&addr,
connect_cb);
ASSERT(r == 0);
View
2 test/test-tcp-writealot.c
@@ -151,7 +151,7 @@ TEST_IMPL(tcp_writealot) {
r = uv_tcp_init(uv_default_loop(), &client);
ASSERT(r == 0);
- r = uv_tcp_connect(&connect_req, &client, addr, connect_cb);
+ r = uv_tcp_connect(&connect_req, &client, (struct sockaddr*)&addr, connect_cb);
ASSERT(r == 0);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
View
2 test/test-udp-ipv6.c
@@ -105,7 +105,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, (struct sockaddr *)&addr6, bind_flags);
ASSERT(r == 0);
r = uv_udp_recv_start(&server, alloc_cb, recv_cb);
View
2 test/test-udp-multicast-join.c
@@ -108,7 +108,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, (struct sockaddr*)&addr, 0);
ASSERT(r == 0);
/* join the multicast channel */
View
6 test/test-udp-multicast-ttl.c
@@ -57,17 +57,19 @@ TEST_IMPL(udp_multicast_ttl) {
int r;
uv_udp_send_t req;
uv_buf_t buf;
- struct sockaddr_in addr = uv_ip4_addr("239.255.0.1", TEST_PORT);
+ struct sockaddr_in addr;
r = uv_udp_init(uv_default_loop(), &server);
ASSERT(r == 0);
- r = uv_udp_bind(&server, uv_ip4_addr("0.0.0.0", 0), 0);
+ addr = uv_ip4_addr("0.0.0.0", 0);
+ r = uv_udp_bind(&server, (struct sockaddr*)&addr, 0);
ASSERT(r == 0);
r = uv_udp_set_multicast_ttl(&server, 32);
ASSERT(r == 0);
+ addr = uv_ip4_addr("239.255.0.1", TEST_PORT);
/* server sends "PING" */
buf = uv_buf_init("PING", 4);
r = uv_udp_send(&req, &server, &buf, 1, addr, sv_send_cb);
View
2 test/test-udp-open.c
@@ -135,7 +135,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, (struct sockaddr*)&addr, 0);
ASSERT(r == 0);
r = uv_udp_recv_start(&client, alloc_cb, recv_cb);
View
4 test/test-udp-options.c
@@ -28,6 +28,7 @@
TEST_IMPL(udp_options) {
+ struct sockaddr_in addr;
static int invalid_ttls[] = { -1, 0, 256 };
uv_loop_t* loop;
uv_udp_t h;
@@ -40,7 +41,8 @@ TEST_IMPL(udp_options) {
uv_unref((uv_handle_t*)&h); /* don't keep the loop alive */
- r = uv_udp_bind(&h, uv_ip4_addr("0.0.0.0", TEST_PORT), 0);
+ addr = uv_ip4_addr("0.0.0.0", TEST_PORT);
+ r = uv_udp_bind(&h, (struct sockaddr*)&addr, 0);
ASSERT(r == 0);
r = uv_udp_set_broadcast(&h, 1);
View
2 test/test-udp-send-and-recv.c
@@ -173,7 +173,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, (struct sockaddr*)&addr, 0);
ASSERT(r == 0);
r = uv_udp_recv_start(&server, alloc_cb, sv_recv_cb);

0 comments on commit 1ca0eb5

Please sign in to comment.
Something went wrong with that request. Please try again.