aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yuchen Zeng <zyc@google.com>2017-08-22 13:43:38 -0700
committerGravatar Yuchen Zeng <zyc@google.com>2017-08-22 18:56:25 -0700
commit6a6d618034fe01b00aa192f2fb44bc9f305f0519 (patch)
treed89aea9e2d051dcd2f4f316020a4b3263f0162bb
parent2411bacd048227a68336082067950933920ba1c1 (diff)
Prevent watching unsuppoted channels
-rw-r--r--include/grpc/grpc.h3
-rw-r--r--src/core/ext/filters/client_channel/channel_connectivity.c6
-rw-r--r--src/cpp/client/channel_cc.cc2
3 files changed, 10 insertions, 1 deletions
diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h
index 943d6e4891..5b1406b4ab 100644
--- a/include/grpc/grpc.h
+++ b/include/grpc/grpc.h
@@ -178,6 +178,9 @@ GRPCAPI void grpc_channel_watch_connectivity_state(
grpc_channel *channel, grpc_connectivity_state last_observed_state,
gpr_timespec deadline, grpc_completion_queue *cq, void *tag);
+/** Check whether a grpc channel support connectivity watcher */
+GRPCAPI int grpc_channel_support_connectivity_watcher(grpc_channel *channel);
+
/** Create a call given a grpc_channel, in order to call 'method'. All
completions are sent to 'completion_queue'. 'method' and 'host' need only
live through the invocation of this function.
diff --git a/src/core/ext/filters/client_channel/channel_connectivity.c b/src/core/ext/filters/client_channel/channel_connectivity.c
index b83c95275f..0a9e90d12e 100644
--- a/src/core/ext/filters/client_channel/channel_connectivity.c
+++ b/src/core/ext/filters/client_channel/channel_connectivity.c
@@ -191,6 +191,12 @@ static void watcher_timer_init(grpc_exec_ctx *exec_ctx, void *arg,
gpr_free(wa);
}
+int grpc_channel_support_connectivity_watcher(grpc_channel *channel) {
+ grpc_channel_element *client_channel_elem =
+ grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel));
+ return client_channel_elem->filter != &grpc_client_channel_filter ? 0 : 1;
+}
+
void grpc_channel_watch_connectivity_state(
grpc_channel *channel, grpc_connectivity_state last_observed_state,
gpr_timespec deadline, grpc_completion_queue *cq, void *tag) {
diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc
index 78f5de0d04..7c52752bd9 100644
--- a/src/cpp/client/channel_cc.cc
+++ b/src/cpp/client/channel_cc.cc
@@ -101,7 +101,7 @@ Channel::Channel(const grpc::string& host, grpc_channel* channel)
host_(host),
c_channel_(channel) {
g_gli_initializer.summon();
- if (host != "inproc") {
+ if (grpc_channel_support_connectivity_watcher(channel)) {
connectivity_watcher_->StartWatching();
}
}