|
|
|
@ -52,7 +52,10 @@ static void on_connect(void *arg, grpc_endpoint *udp) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void on_read(int fd, grpc_udp_server_cb new_transport_cb, void *cb_arg) { |
|
|
|
|
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); |
|
|
|
|
g_number_of_reads++; |
|
|
|
|
grpc_pollset_kick(&g_pollset); |
|
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void test_no_op(void) { |
|
|
|
@ -110,9 +113,12 @@ static void test_receive(int n) { |
|
|
|
|
memset(&addr, 0, sizeof(addr)); |
|
|
|
|
addr.ss_family = AF_INET; |
|
|
|
|
GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, addr_len, on_read)); |
|
|
|
|
|
|
|
|
|
pollsets[0] = &g_pollset; |
|
|
|
|
grpc_udp_server_start(s, pollsets, 1, on_connect, NULL); |
|
|
|
|
|
|
|
|
|
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); |
|
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) { |
|
|
|
|
deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(4000); |
|
|
|
|
|
|
|
|
@ -130,6 +136,8 @@ static void test_receive(int n) { |
|
|
|
|
close(clifd); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); |
|
|
|
|
|
|
|
|
|
grpc_udp_server_destroy(s, NULL, NULL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -145,6 +153,7 @@ int main(int argc, char **argv) { |
|
|
|
|
test_no_op_with_port(); |
|
|
|
|
test_no_op_with_port_and_start(); |
|
|
|
|
test_receive(1); |
|
|
|
|
test_receive(10); |
|
|
|
|
|
|
|
|
|
grpc_pollset_shutdown(&g_pollset, destroy_pollset, &g_pollset); |
|
|
|
|
grpc_iomgr_shutdown(); |
|
|
|
|