Adding 10 client test, fiddling with pollsets

pull/2376/head
Robbie Shade 10 years ago
parent 4cde25cd01
commit 1cef6dccde
  1. 6
      src/core/iomgr/udp_server.c
  2. 9
      test/core/iomgr/udp_server_test.c

@ -84,6 +84,11 @@ struct grpc_udp_server {
/* shutdown callback */
void (*shutdown_complete)(void *);
void *shutdown_complete_arg;
/* all pollsets interested in new connections */
grpc_pollset **pollsets;
/* number of pollsets in the pollsets array */
size_t pollset_count;
};
grpc_udp_server *grpc_udp_server_create(void) {
@ -368,6 +373,7 @@ void grpc_udp_server_start(grpc_udp_server *s, grpc_pollset **pollsets,
GPR_ASSERT(s->active_ports == 0);
s->cb = new_transport_cb;
s->cb_arg = cb_arg;
s->pollsets = pollsets;
for (i = 0; i < s->nports; i++) {
for (j = 0; j < pollset_count; j++) {
grpc_pollset_add_fd(pollsets[j], s->ports[i].emfd);

@ -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();

Loading…
Cancel
Save