aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
Diffstat (limited to 'test/core')
-rw-r--r--test/core/client_config/set_initial_connect_string_test.c13
-rw-r--r--test/core/end2end/fixtures/h2_full+trace.c1
-rw-r--r--test/core/end2end/fixtures/h2_sockpair+trace.c1
-rw-r--r--test/core/iomgr/sockaddr_utils_test.c155
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c32
-rw-r--r--test/core/iomgr/tcp_server_posix_test.c55
-rw-r--r--test/core/surface/concurrent_connectivity_test.c13
-rw-r--r--test/core/util/test_tcp_server.c15
8 files changed, 151 insertions, 134 deletions
diff --git a/test/core/client_config/set_initial_connect_string_test.c b/test/core/client_config/set_initial_connect_string_test.c
index 1b51424f7e..dcff859e4b 100644
--- a/test/core/client_config/set_initial_connect_string_test.c
+++ b/test/core/client_config/set_initial_connect_string_test.c
@@ -93,15 +93,14 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
grpc_endpoint_read(exec_ctx, tcp, &state.temp_incoming_buffer, &on_read);
}
-static void set_magic_initial_string(struct sockaddr **addr, size_t *addr_len,
+static void set_magic_initial_string(grpc_resolved_address **addr,
gpr_slice *connect_string) {
GPR_ASSERT(addr);
- GPR_ASSERT(addr_len);
+ GPR_ASSERT((*addr)->len);
*connect_string = gpr_slice_from_copied_string(magic_connect_string);
}
-static void reset_addr_and_set_magic_string(struct sockaddr **addr,
- size_t *addr_len,
+static void reset_addr_and_set_magic_string(grpc_resolved_address **addr,
gpr_slice *connect_string) {
struct sockaddr_in target;
*connect_string = gpr_slice_from_copied_string(magic_connect_string);
@@ -109,9 +108,9 @@ static void reset_addr_and_set_magic_string(struct sockaddr **addr,
target.sin_family = AF_INET;
target.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
target.sin_port = htons((uint16_t)server_port);
- *addr_len = sizeof(target);
- *addr = (struct sockaddr *)gpr_malloc(sizeof(target));
- memcpy(*addr, &target, sizeof(target));
+ (*addr)->len = sizeof(target);
+ *addr = (grpc_resolved_address *)gpr_malloc(sizeof(grpc_resolved_address));
+ memcpy((*addr)->addr, &target, sizeof(target));
}
static gpr_timespec n_sec_deadline(int seconds) {
diff --git a/test/core/end2end/fixtures/h2_full+trace.c b/test/core/end2end/fixtures/h2_full+trace.c
index e25b5e3347..46582e3190 100644
--- a/test/core/end2end/fixtures/h2_full+trace.c
+++ b/test/core/end2end/fixtures/h2_full+trace.c
@@ -34,6 +34,7 @@
#include "test/core/end2end/end2end_tests.h"
#include <string.h>
+#include <unistd.h>
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.c b/test/core/end2end/fixtures/h2_sockpair+trace.c
index d0925e5109..356a359784 100644
--- a/test/core/end2end/fixtures/h2_sockpair+trace.c
+++ b/test/core/end2end/fixtures/h2_sockpair+trace.c
@@ -34,6 +34,7 @@
#include "test/core/end2end/end2end_tests.h"
#include <string.h>
+#include <unistd.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
diff --git a/test/core/iomgr/sockaddr_utils_test.c b/test/core/iomgr/sockaddr_utils_test.c
index a330314443..1f89f59ef2 100644
--- a/test/core/iomgr/sockaddr_utils_test.c
+++ b/test/core/iomgr/sockaddr_utils_test.c
@@ -31,6 +31,7 @@
*
*/
+#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include <errno.h>
@@ -41,24 +42,28 @@
#include <grpc/support/port_platform.h>
#include "test/core/util/test_config.h"
-static struct sockaddr_in make_addr4(const uint8_t *data, size_t data_len) {
- struct sockaddr_in addr4;
- memset(&addr4, 0, sizeof(addr4));
- addr4.sin_family = AF_INET;
- GPR_ASSERT(data_len == sizeof(addr4.sin_addr.s_addr));
- memcpy(&addr4.sin_addr.s_addr, data, data_len);
- addr4.sin_port = htons(12345);
- return addr4;
+static grpc_resolved_address make_addr4(const uint8_t *data, size_t data_len) {
+ grpc_resolved_address resolved_addr4;
+ struct sockaddr_in *addr4 = (struct sockaddr_in *)resolved_addr4.addr;
+ memset(&resolved_addr4, 0, sizeof(resolved_addr4));
+ addr4->sin_family = AF_INET;
+ GPR_ASSERT(data_len == sizeof(addr4->sin_addr.s_addr));
+ memcpy(&addr4->sin_addr.s_addr, data, data_len);
+ addr4->sin_port = htons(12345);
+ resolved_addr4.len = sizeof(struct sockaddr_in);
+ return resolved_addr4;
}
-static struct sockaddr_in6 make_addr6(const uint8_t *data, size_t data_len) {
- struct sockaddr_in6 addr6;
- memset(&addr6, 0, sizeof(addr6));
- addr6.sin6_family = AF_INET6;
- GPR_ASSERT(data_len == sizeof(addr6.sin6_addr.s6_addr));
- memcpy(&addr6.sin6_addr.s6_addr, data, data_len);
- addr6.sin6_port = htons(12345);
- return addr6;
+static grpc_resolved_address make_addr6(const uint8_t *data, size_t data_len) {
+ grpc_resolved_address resolved_addr6;
+ struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)resolved_addr6.addr;
+ memset(&resolved_addr6, 0, sizeof(resolved_addr6));
+ addr6->sin6_family = AF_INET6;
+ GPR_ASSERT(data_len == sizeof(addr6->sin6_addr.s6_addr));
+ memcpy(&addr6->sin6_addr.s6_addr, data, data_len);
+ addr6->sin6_port = htons(12345);
+ resolved_addr6.len = sizeof(struct sockaddr_in6);
+ return resolved_addr6;
}
static const uint8_t kMapped[] = {0, 0, 0, 0, 0, 0, 0, 0,
@@ -72,102 +77,96 @@ static const uint8_t kIPv6[] = {0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1};
static void test_sockaddr_is_v4mapped(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr_in output4;
- struct sockaddr_in expect4;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address output4;
+ grpc_resolved_address expect4;
gpr_log(GPR_INFO, "%s", "test_sockaddr_is_v4mapped");
/* v4mapped input should succeed. */
input6 = make_addr6(kMapped, sizeof(kMapped));
- GPR_ASSERT(grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, NULL));
- GPR_ASSERT(
- grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, &output4));
+ GPR_ASSERT(grpc_sockaddr_is_v4mapped(&input6, NULL));
+ GPR_ASSERT(grpc_sockaddr_is_v4mapped(&input6, &output4));
expect4 = make_addr4(kIPv4, sizeof(kIPv4));
GPR_ASSERT(memcmp(&expect4, &output4, sizeof(expect4)) == 0);
/* Non-v4mapped input should fail. */
input6 = make_addr6(kNotQuiteMapped, sizeof(kNotQuiteMapped));
- GPR_ASSERT(
- !grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, NULL));
- GPR_ASSERT(
- !grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input6, &output4));
+ GPR_ASSERT(!grpc_sockaddr_is_v4mapped(&input6, NULL));
+ GPR_ASSERT(!grpc_sockaddr_is_v4mapped(&input6, &output4));
/* Output is unchanged. */
GPR_ASSERT(memcmp(&expect4, &output4, sizeof(expect4)) == 0);
/* Plain IPv4 input should also fail. */
input4 = make_addr4(kIPv4, sizeof(kIPv4));
- GPR_ASSERT(
- !grpc_sockaddr_is_v4mapped((const struct sockaddr *)&input4, NULL));
+ GPR_ASSERT(!grpc_sockaddr_is_v4mapped(&input4, NULL));
}
static void test_sockaddr_to_v4mapped(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr_in6 output6;
- struct sockaddr_in6 expect6;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address output6;
+ grpc_resolved_address expect6;
gpr_log(GPR_INFO, "%s", "test_sockaddr_to_v4mapped");
/* IPv4 input should succeed. */
input4 = make_addr4(kIPv4, sizeof(kIPv4));
- GPR_ASSERT(
- grpc_sockaddr_to_v4mapped((const struct sockaddr *)&input4, &output6));
+ GPR_ASSERT(grpc_sockaddr_to_v4mapped(&input4, &output6));
expect6 = make_addr6(kMapped, sizeof(kMapped));
GPR_ASSERT(memcmp(&expect6, &output6, sizeof(output6)) == 0);
/* IPv6 input should fail. */
input6 = make_addr6(kIPv6, sizeof(kIPv6));
- GPR_ASSERT(
- !grpc_sockaddr_to_v4mapped((const struct sockaddr *)&input6, &output6));
+ GPR_ASSERT(!grpc_sockaddr_to_v4mapped(&input6, &output6));
/* Output is unchanged. */
GPR_ASSERT(memcmp(&expect6, &output6, sizeof(output6)) == 0);
/* Already-v4mapped input should also fail. */
input6 = make_addr6(kMapped, sizeof(kMapped));
- GPR_ASSERT(
- !grpc_sockaddr_to_v4mapped((const struct sockaddr *)&input6, &output6));
+ GPR_ASSERT(!grpc_sockaddr_to_v4mapped(&input6, &output6));
}
static void test_sockaddr_is_wildcard(void) {
- struct sockaddr_in wild4;
- struct sockaddr_in6 wild6;
- struct sockaddr_in6 wild_mapped;
- struct sockaddr dummy;
+ grpc_resolved_address wild4;
+ grpc_resolved_address wild6;
+ grpc_resolved_address wild_mapped;
+ grpc_resolved_address dummy;
+ struct sockaddr_in *wild4_addr;
+ struct sockaddr_in6 *wild6_addr;
+ struct sockaddr_in6 *wild_mapped_addr;
int port;
gpr_log(GPR_INFO, "%s", "test_sockaddr_is_wildcard");
/* Generate wildcards. */
grpc_sockaddr_make_wildcards(555, &wild4, &wild6);
- GPR_ASSERT(
- grpc_sockaddr_to_v4mapped((const struct sockaddr *)&wild4, &wild_mapped));
+ GPR_ASSERT(grpc_sockaddr_to_v4mapped(&wild4, &wild_mapped));
/* Test 0.0.0.0:555 */
port = -1;
- GPR_ASSERT(grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild4, &port));
+ GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild4, &port));
GPR_ASSERT(port == 555);
- memset(&wild4.sin_addr.s_addr, 0xbd, 1);
- GPR_ASSERT(
- !grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild4, &port));
+ wild4_addr = (struct sockaddr_in *)&wild4.addr;
+ memset(&wild4_addr->sin_addr.s_addr, 0xbd, 1);
+ GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild4, &port));
/* Test [::]:555 */
port = -1;
- GPR_ASSERT(grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild6, &port));
+ GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild6, &port));
GPR_ASSERT(port == 555);
- memset(&wild6.sin6_addr.s6_addr, 0xbd, 1);
- GPR_ASSERT(
- !grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild6, &port));
+ wild6_addr = (struct sockaddr_in6 *)&wild6.addr;
+ memset(&wild6_addr->sin6_addr.s6_addr, 0xbd, 1);
+ GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild6, &port));
/* Test [::ffff:0.0.0.0]:555 */
port = -1;
- GPR_ASSERT(
- grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild_mapped, &port));
+ GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild_mapped, &port));
GPR_ASSERT(port == 555);
- memset(&wild_mapped.sin6_addr.s6_addr, 0xbd, 1);
- GPR_ASSERT(
- !grpc_sockaddr_is_wildcard((const struct sockaddr *)&wild_mapped, &port));
+ wild_mapped_addr = (struct sockaddr_in6 *)&wild_mapped.addr;
+ memset(&wild_mapped_addr->sin6_addr.s6_addr, 0xbd, 1);
+ GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild_mapped, &port));
/* Test AF_UNSPEC. */
port = -1;
@@ -176,12 +175,12 @@ static void test_sockaddr_is_wildcard(void) {
GPR_ASSERT(port == -1);
}
-static void expect_sockaddr_str(const char *expected, void *addr,
+static void expect_sockaddr_str(const char *expected, grpc_resolved_address *addr,
int normalize) {
int result;
char *str;
gpr_log(GPR_INFO, " expect_sockaddr_str(%s)", expected);
- result = grpc_sockaddr_to_string(&str, (struct sockaddr *)addr, normalize);
+ result = grpc_sockaddr_to_string(&str, addr, normalize);
GPR_ASSERT(str != NULL);
GPR_ASSERT(result >= 0);
GPR_ASSERT((size_t)result == strlen(str));
@@ -189,19 +188,20 @@ static void expect_sockaddr_str(const char *expected, void *addr,
gpr_free(str);
}
-static void expect_sockaddr_uri(const char *expected, void *addr) {
+static void expect_sockaddr_uri(const char *expected, grpc_resolved_address *addr) {
char *str;
gpr_log(GPR_INFO, " expect_sockaddr_uri(%s)", expected);
- str = grpc_sockaddr_to_uri((struct sockaddr *)addr);
+ str = grpc_sockaddr_to_uri(addr);
GPR_ASSERT(str != NULL);
GPR_ASSERT(strcmp(expected, str) == 0);
gpr_free(str);
}
static void test_sockaddr_to_string(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr dummy;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address dummy;
+ struct sockaddr *dummy_addr;
gpr_log(GPR_INFO, "%s", "test_sockaddr_to_string");
@@ -228,7 +228,8 @@ static void test_sockaddr_to_string(void) {
expect_sockaddr_uri("ipv6:[::fffe:c000:263]:12345", &input6);
memset(&dummy, 0, sizeof(dummy));
- dummy.sa_family = 123;
+ dummy_addr = (struct sockaddr *)dummy.addr;
+ dummy_addr->sa_family = 123;
expect_sockaddr_str("(sockaddr family=123)", &dummy, 0);
expect_sockaddr_str("(sockaddr family=123)", &dummy, 1);
GPR_ASSERT(grpc_sockaddr_to_uri(&dummy) == NULL);
@@ -237,24 +238,26 @@ static void test_sockaddr_to_string(void) {
}
static void test_sockaddr_set_get_port(void) {
- struct sockaddr_in input4;
- struct sockaddr_in6 input6;
- struct sockaddr dummy;
+ grpc_resolved_address input4;
+ grpc_resolved_address input6;
+ grpc_resolved_address dummy;
+ struct sockaddr *dummy_addr;
gpr_log(GPR_DEBUG, "test_sockaddr_set_get_port");
input4 = make_addr4(kIPv4, sizeof(kIPv4));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input4) == 12345);
- GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr *)&input4, 54321));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input4) == 54321);
+ GPR_ASSERT(grpc_sockaddr_get_port(&input4) == 12345);
+ GPR_ASSERT(grpc_sockaddr_set_port(&input4, 54321));
+ GPR_ASSERT(grpc_sockaddr_get_port(&input4) == 54321);
input6 = make_addr6(kIPv6, sizeof(kIPv6));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input6) == 12345);
- GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr *)&input6, 54321));
- GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input6) == 54321);
+ GPR_ASSERT(grpc_sockaddr_get_port(&input6) == 12345);
+ GPR_ASSERT(grpc_sockaddr_set_port(&input6, 54321));
+ GPR_ASSERT(grpc_sockaddr_get_port(&input6) == 54321);
memset(&dummy, 0, sizeof(dummy));
- dummy.sa_family = 123;
+ dummy_addr = (struct sockaddr *)dummy.addr;
+ dummy_addr->sa_family = 123;
GPR_ASSERT(grpc_sockaddr_get_port(&dummy) == 0);
GPR_ASSERT(grpc_sockaddr_set_port(&dummy, 1234) == 0);
}
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index d0c1047423..07aa55b145 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -85,8 +85,8 @@ static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
}
void test_succeeds(void) {
- struct sockaddr_in addr;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
int svr_fd;
int r;
int connections_complete_before;
@@ -95,13 +95,14 @@ void test_succeeds(void) {
gpr_log(GPR_DEBUG, "test_succeeds");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
/* create a dummy server */
svr_fd = socket(AF_INET, SOCK_STREAM, 0);
GPR_ASSERT(svr_fd >= 0);
- GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr *)&addr, addr_len));
+ GPR_ASSERT(0 == bind(svr_fd, (struct sockaddr *)addr, (socklen_t)resolved_addr.len));
GPR_ASSERT(0 == listen(svr_fd, 1));
gpr_mu_lock(g_mu);
@@ -109,16 +110,15 @@ void test_succeeds(void) {
gpr_mu_unlock(g_mu);
/* connect to it */
- GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)&addr, &addr_len) == 0);
+ GPR_ASSERT(getsockname(svr_fd, (struct sockaddr *)addr, (socklen_t *)&resolved_addr.len) == 0);
grpc_closure_init(&done, must_succeed, NULL);
grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set,
- (struct sockaddr *)&addr, addr_len,
- gpr_inf_future(GPR_CLOCK_REALTIME));
+ &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
/* await the connection */
do {
- addr_len = sizeof(addr);
- r = accept(svr_fd, (struct sockaddr *)&addr, &addr_len);
+ resolved_addr.len = sizeof(addr);
+ r = accept(svr_fd, addr, (socklen_t *)&resolved_addr.len);
} while (r == -1 && errno == EINTR);
GPR_ASSERT(r >= 0);
close(r);
@@ -143,16 +143,17 @@ void test_succeeds(void) {
}
void test_fails(void) {
- struct sockaddr_in addr;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
int connections_complete_before;
grpc_closure done;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_fails");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
gpr_mu_lock(g_mu);
connections_complete_before = g_connections_complete;
@@ -161,8 +162,7 @@ void test_fails(void) {
/* connect to a broken address */
grpc_closure_init(&done, must_fail, NULL);
grpc_tcp_client_connect(&exec_ctx, &done, &g_connecting, g_pollset_set,
- (struct sockaddr *)&addr, addr_len,
- gpr_inf_future(GPR_CLOCK_REALTIME));
+ &resolved_addr, gpr_inf_future(GPR_CLOCK_REALTIME));
gpr_mu_lock(g_mu);
diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c
index 6e2d1d0fc9..9e8dff61ff 100644
--- a/test/core/iomgr/tcp_server_posix_test.c
+++ b/test/core/iomgr/tcp_server_posix_test.c
@@ -46,6 +46,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/iomgr/iomgr.h"
+#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@@ -146,15 +147,17 @@ static void test_no_op_with_start(void) {
static void test_no_op_with_port(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
grpc_tcp_server *s;
GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
LOG_TEST("test_no_op_with_port");
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
int port;
- GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
+ GPR_ASSERT(grpc_tcp_server_add_port(s, &resolved_addr,
&port) == GRPC_ERROR_NONE &&
port > 0);
@@ -164,15 +167,17 @@ static void test_no_op_with_port(void) {
static void test_no_op_with_port_and_start(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
grpc_tcp_server *s;
GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s));
LOG_TEST("test_no_op_with_port_and_start");
int port;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
+ GPR_ASSERT(grpc_tcp_server_add_port(s, &resolved_addr,
&port) == GRPC_ERROR_NONE &&
port > 0);
@@ -218,9 +223,10 @@ static void tcp_connect(grpc_exec_ctx *exec_ctx, const struct sockaddr *remote,
the same port should be tested. */
static void test_connect(unsigned n) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_storage addr;
- struct sockaddr_storage addr1;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ grpc_resolved_address resolved_addr1;
+ struct sockaddr_storage *addr = (struct sockaddr_storage *)resolved_addr.addr;
+ struct sockaddr_storage *addr1 = (struct sockaddr_storage *)resolved_addr1.addr;
unsigned svr_fd_count;
int svr_port;
unsigned svr1_fd_count;
@@ -232,18 +238,19 @@ static void test_connect(unsigned n) {
server_weak_ref_init(&weak_ref);
LOG_TEST("test_connect");
gpr_log(GPR_INFO, "clients=%d", n);
- memset(&addr, 0, sizeof(addr));
- memset(&addr1, 0, sizeof(addr1));
- addr.ss_family = addr1.ss_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ memset(&resolved_addr1, 0, sizeof(resolved_addr1));
+ resolved_addr.len = sizeof(struct sockaddr_storage);
+ resolved_addr1.len = sizeof(struct sockaddr_storage);
+ addr->ss_family = addr1->ss_family = AF_INET;
GPR_ASSERT(GRPC_ERROR_NONE ==
- grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, addr_len,
- &svr_port));
+ grpc_tcp_server_add_port(s, &resolved_addr, &svr_port));
GPR_ASSERT(svr_port > 0);
/* Cannot use wildcard (port==0), because add_port() will try to reuse the
same port as a previous add_port(). */
svr1_port = grpc_pick_unused_port_or_die();
- grpc_sockaddr_set_port((struct sockaddr *)&addr1, svr1_port);
- GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr1, addr_len,
+ grpc_sockaddr_set_port(&resolved_addr1, svr1_port);
+ GPR_ASSERT(grpc_tcp_server_add_port(s, &resolved_addr1,
&svr_port) == GRPC_ERROR_NONE &&
svr_port == svr1_port);
@@ -265,16 +272,16 @@ static void test_connect(unsigned n) {
int fd = grpc_tcp_server_port_fd(s, 0, i);
GPR_ASSERT(fd >= 0);
if (i == 0) {
- GPR_ASSERT(getsockname(fd, (struct sockaddr *)&addr, &addr_len) == 0);
- GPR_ASSERT(addr_len <= sizeof(addr));
+ GPR_ASSERT(getsockname(fd, (struct sockaddr *)addr, (socklen_t *)&resolved_addr.len) == 0);
+ GPR_ASSERT(resolved_addr.len <= sizeof(*addr));
}
}
for (i = 0; i < svr1_fd_count; ++i) {
int fd = grpc_tcp_server_port_fd(s, 1, i);
GPR_ASSERT(fd >= 0);
if (i == 0) {
- GPR_ASSERT(getsockname(fd, (struct sockaddr *)&addr1, &addr_len) == 0);
- GPR_ASSERT(addr_len <= sizeof(addr1));
+ GPR_ASSERT(getsockname(fd, (struct sockaddr *)addr1, (socklen_t *)&resolved_addr1.len) == 0);
+ GPR_ASSERT(resolved_addr1.len <= sizeof(*addr1));
}
}
@@ -284,7 +291,7 @@ static void test_connect(unsigned n) {
on_connect_result result;
int svr_fd;
on_connect_result_init(&result);
- tcp_connect(&exec_ctx, (struct sockaddr *)&addr, addr_len, &result);
+ tcp_connect(&exec_ctx, (struct sockaddr *)addr, (socklen_t)resolved_addr.len, &result);
GPR_ASSERT(result.server_fd >= 0);
svr_fd = result.server_fd;
GPR_ASSERT(grpc_tcp_server_port_fd(s, result.port_index, result.fd_index) ==
@@ -298,7 +305,7 @@ static void test_connect(unsigned n) {
grpc_tcp_server_unref(&exec_ctx, result.server);
on_connect_result_init(&result);
- tcp_connect(&exec_ctx, (struct sockaddr *)&addr1, addr_len, &result);
+ tcp_connect(&exec_ctx, (struct sockaddr *)addr1, (socklen_t)resolved_addr1.len, &result);
GPR_ASSERT(result.server_fd >= 0);
GPR_ASSERT(result.server_fd != svr_fd);
GPR_ASSERT(grpc_tcp_server_port_fd(s, result.port_index, result.fd_index) ==
diff --git a/test/core/surface/concurrent_connectivity_test.c b/test/core/surface/concurrent_connectivity_test.c
index f7567f350d..537fdf71a1 100644
--- a/test/core/surface/concurrent_connectivity_test.c
+++ b/test/core/surface/concurrent_connectivity_test.c
@@ -31,6 +31,8 @@
*
*/
+#include "src/core/lib/iomgr/sockaddr.h"
+
#include <memory.h>
#include <stdio.h>
@@ -42,6 +44,7 @@
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr.h"
+#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
#include "src/core/lib/iomgr/tcp_server.h"
@@ -109,16 +112,16 @@ void bad_server_thread(void *vargs) {
struct server_thread_args *args = (struct server_thread_args *)vargs;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- struct sockaddr_storage addr;
- socklen_t addr_len = sizeof(addr);
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_storage *addr = (struct sockaddr_storage *)resolved_addr.addr;
int port;
grpc_tcp_server *s;
grpc_error *error = grpc_tcp_server_create(NULL, NULL, &s);
GPR_ASSERT(error == GRPC_ERROR_NONE);
- memset(&addr, 0, sizeof(addr));
- addr.ss_family = AF_INET;
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ addr->ss_family = AF_INET;
error =
- grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, addr_len, &port);
+ grpc_tcp_server_add_port(s, &resolved_addr, &port);
GPR_ASSERT(GRPC_LOG_IF_ERROR("grpc_tcp_server_add_port", error));
GPR_ASSERT(port > 0);
gpr_asprintf(&args->addr, "localhost:%d", port);
diff --git a/test/core/util/test_tcp_server.c b/test/core/util/test_tcp_server.c
index 8a0b3932d8..ee2de563e8 100644
--- a/test/core/util/test_tcp_server.c
+++ b/test/core/util/test_tcp_server.c
@@ -31,6 +31,8 @@
*
*/
+#include "src/core/lib/iomgr/sockaddr.h"
+
#include "test/core/util/test_tcp_server.h"
#include <grpc/grpc.h>
@@ -41,7 +43,7 @@
#include <grpc/support/time.h>
#include <string.h>
#include "src/core/lib/iomgr/endpoint.h"
-#include "src/core/lib/iomgr/sockaddr.h"
+#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/tcp_server.h"
#include "test/core/util/port.h"
@@ -64,18 +66,19 @@ void test_tcp_server_init(test_tcp_server *server,
}
void test_tcp_server_start(test_tcp_server *server, int port) {
- struct sockaddr_in addr;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
int port_added;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- addr.sin_family = AF_INET;
- addr.sin_port = htons((uint16_t)port);
- memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
+ addr->sin_family = AF_INET;
+ addr->sin_port = htons((uint16_t)port);
+ memset(&addr->sin_addr, 0, sizeof(addr->sin_addr));
grpc_error *error = grpc_tcp_server_create(&server->shutdown_complete, NULL,
&server->tcp_server);
GPR_ASSERT(error == GRPC_ERROR_NONE);
- error = grpc_tcp_server_add_port(server->tcp_server, &addr, sizeof(addr),
+ error = grpc_tcp_server_add_port(server->tcp_server, &resolved_addr,
&port_added);
GPR_ASSERT(error == GRPC_ERROR_NONE);
GPR_ASSERT(port_added == port);