From 1ada6ad8e57e9033f9cc9a6b0082e27a413e9584 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 16 Jul 2015 16:19:14 -0700 Subject: Added connectivity tests, fixed bugs --- src/core/surface/channel_connectivity.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/core/surface/channel_connectivity.c') diff --git a/src/core/surface/channel_connectivity.c b/src/core/surface/channel_connectivity.c index bdd9678d66..dd12ff5611 100644 --- a/src/core/surface/channel_connectivity.c +++ b/src/core/surface/channel_connectivity.c @@ -73,10 +73,15 @@ typedef struct { grpc_connectivity_state *optional_new_state; grpc_completion_queue *cq; grpc_cq_completion completion_storage; + grpc_channel *channel; void *tag; } state_watcher; static void delete_state_watcher(state_watcher *w) { + grpc_channel_element *client_channel_elem = + grpc_channel_stack_last_element(grpc_channel_get_channel_stack(w->channel)); + grpc_client_channel_del_interested_party(client_channel_elem, grpc_cq_pollset(w->cq)); + GRPC_CHANNEL_INTERNAL_UNREF(w->channel, "watch_connectivity"); gpr_mu_destroy(&w->mu); gpr_free(w); } @@ -143,9 +148,9 @@ static void partly_done(state_watcher *w, int due_to_completion) { } } -static void watch_complete(void *pw, int success) { partly_done(pw, 0); } +static void watch_complete(void *pw, int success) { partly_done(pw, 1); } -static void timeout_complete(void *pw, int success) { partly_done(pw, 1); } +static void timeout_complete(void *pw, int success) { partly_done(pw, 0); } void grpc_channel_watch_connectivity_state( grpc_channel *channel, grpc_connectivity_state last_observed_state, @@ -165,6 +170,7 @@ void grpc_channel_watch_connectivity_state( w->optional_new_state = optional_new_state; w->cq = cq; w->tag = tag; + w->channel = channel; grpc_alarm_init(&w->alarm, deadline, timeout_complete, w, gpr_now(GPR_CLOCK_REALTIME)); @@ -176,6 +182,8 @@ void grpc_channel_watch_connectivity_state( client_channel_elem->filter->name); grpc_iomgr_add_delayed_callback(&w->on_complete, 1); } else { + GRPC_CHANNEL_INTERNAL_REF(channel, "watch_connectivity"); + grpc_client_channel_add_interested_party(client_channel_elem, grpc_cq_pollset(cq)); grpc_client_channel_watch_connectivity_state(client_channel_elem, &w->state, &w->on_complete); } -- cgit v1.2.3