aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-08-05 15:18:19 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-08-05 15:18:19 -0700
commitbb5361453f0d0517675bc369ef6e6a5d2f516b90 (patch)
tree2f596976ee498449153f9f3661354ebc64665496 /src/cpp
parent64f32dc7efe18a6fe75c71b31a36ce523290e70c (diff)
C++ context propagation
Diffstat (limited to 'src/cpp')
-rw-r--r--src/cpp/client/channel.cc6
-rw-r--r--src/cpp/client/client_context.cc12
2 files changed, 15 insertions, 3 deletions
diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc
index 1912e5e4c8..5f54e7fcc1 100644
--- a/src/cpp/client/channel.cc
+++ b/src/cpp/client/channel.cc
@@ -63,10 +63,12 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context,
const char* host_str = host_.empty() ? NULL : host_.c_str();
auto c_call = method.channel_tag() && context->authority().empty()
? grpc_channel_create_registered_call(
- c_channel_, NULL, GRPC_PROPAGATE_DEFAULTS, cq->cq(),
+ c_channel_, context->propagate_from_call_,
+ context->propagation_options_.c_bitmask(), cq->cq(),
method.channel_tag(), context->raw_deadline())
: grpc_channel_create_call(
- c_channel_, NULL, GRPC_PROPAGATE_DEFAULTS, cq->cq(),
+ c_channel_, context->propagate_from_call_,
+ context->propagation_options_.c_bitmask(), cq->cq(),
method.name(), context->authority().empty()
? host_str
: context->authority().c_str(),
diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc
index c38d0c1df6..80b6393f01 100644
--- a/src/cpp/client/client_context.cc
+++ b/src/cpp/client/client_context.cc
@@ -37,6 +37,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
#include <grpc++/credentials.h>
+#include <grpc++/server_context.h>
#include <grpc++/time.h>
#include "src/core/channel/compress_filter.h"
@@ -48,7 +49,8 @@ ClientContext::ClientContext()
: initial_metadata_received_(false),
call_(nullptr),
cq_(nullptr),
- deadline_(gpr_inf_future(GPR_CLOCK_REALTIME)) {}
+ deadline_(gpr_inf_future(GPR_CLOCK_REALTIME)),
+ propagate_from_call_(nullptr) {}
ClientContext::~ClientContext() {
if (call_) {
@@ -64,6 +66,14 @@ ClientContext::~ClientContext() {
}
}
+ClientContext ClientContext::FromServerContext(const ServerContext& context,
+ PropagationOptions options) {
+ ClientContext ctx;
+ ctx.propagate_from_call_ = context.call_;
+ ctx.propagation_options_ = options;
+ return ctx;
+}
+
void ClientContext::AddMetadata(const grpc::string& meta_key,
const grpc::string& meta_value) {
send_initial_metadata_.insert(std::make_pair(meta_key, meta_value));