Added connectivity tests, fixed bugs
diff --git a/src/core/surface/channel_connectivity.c b/src/core/surface/channel_connectivity.c
index bdd9678..dd12ff5 100644
--- a/src/core/surface/channel_connectivity.c
+++ b/src/core/surface/channel_connectivity.c
@@ -73,10 +73,15 @@
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 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 @@
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 @@
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);
}