From c07d9bf668934b21ef0c11b72678e049ce5a6333 Mon Sep 17 00:00:00 2001 From: yang-g Date: Tue, 28 Jul 2015 09:19:22 -0700 Subject: [PATCH] client api --- include/grpc++/client_context.h | 2 ++ src/cpp/client/client_context.cc | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 9df76699d2c..f18fb61b4c3 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -118,6 +118,8 @@ class ClientContext { std::shared_ptr auth_context() const; + grpc::string peer() const; + // Get and set census context void set_census_context(census_context* ccp) { census_context_ = ccp; } census_context* get_census_context() const { return census_context_; } diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc index 14ab772e503..c38d0c1df69 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -104,4 +105,14 @@ void ClientContext::TryCancel() { } } +grpc::string ClientContext::peer() const { + grpc::string peer; + if (call_) { + char* c_peer = grpc_call_get_peer(call_); + peer = c_peer; + gpr_free(c_peer); + } + return peer; +} + } // namespace grpc