diff options
-rw-r--r-- | include/grpc++/server_context.h | 2 | ||||
-rw-r--r-- | src/cpp/server/server_context.cc | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index 3bfa48fbb6..393822c4fd 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -116,6 +116,8 @@ class ServerContext { std::shared_ptr<const AuthContext> auth_context() const; + grpc::string peer() const; + private: friend class ::grpc::testing::InteropContextInspector; friend class ::grpc::Server; diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index bf7a4ba5ec..16a09a12a1 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -34,6 +34,7 @@ #include <grpc++/server_context.h> #include <grpc/grpc.h> +#include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc++/impl/call.h> #include <grpc++/impl/sync.h> @@ -179,4 +180,14 @@ std::shared_ptr<const AuthContext> ServerContext::auth_context() const { return auth_context_; } +grpc::string ServerContext::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 |