diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 9df76699d2cbff77b09f248f3ba7fae4a20bf7ef..f18fb61b4c3a39bd311b0aa546c155fa1ac8c60f 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -118,6 +118,8 @@ class ClientContext { std::shared_ptr<const AuthContext> 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 14ab772e5032d8bfbcbbd39a83046bb7a02e89c3..c38d0c1df694849663e0c0a5b933d6bf4e7f36ec 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -34,6 +34,7 @@ #include <grpc++/client_context.h> #include <grpc/grpc.h> +#include <grpc/support/alloc.h> #include <grpc/support/string_util.h> #include <grpc++/credentials.h> #include <grpc++/time.h> @@ -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