diff options
author | Craig Tiller <ctiller@google.com> | 2017-01-23 07:48:42 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-01-23 07:48:42 -0800 |
commit | 7c70b6c144a20782b6be4751da68c6aa7b35648d (patch) | |
tree | f8ca929338d9f73cd9eec35001ecf52e3b1f6c1b /src/cpp/client | |
parent | c7342a01bb069fcff6df0e22f6c2a403010998a1 (diff) |
Revert "Revert "Metadata handling rewrite""
This reverts commit 5e01e2ac977655aa074faf7fde0a74298f5e4c55.
Diffstat (limited to 'src/cpp/client')
-rw-r--r-- | src/cpp/client/channel_cc.cc | 18 | ||||
-rw-r--r-- | src/cpp/client/secure_credentials.cc | 9 | ||||
-rw-r--r-- | src/cpp/client/secure_credentials.h | 2 |
3 files changed, 21 insertions, 8 deletions
diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc index 357d8317ad..c985183ae7 100644 --- a/src/cpp/client/channel_cc.cc +++ b/src/cpp/client/channel_cc.cc @@ -107,10 +107,20 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, } else if (!host_.empty()) { host_str = host_.c_str(); } - c_call = grpc_channel_create_call(c_channel_, context->propagate_from_call_, - context->propagation_options_.c_bitmask(), - cq->cq(), method.name(), host_str, - context->raw_deadline(), nullptr); + grpc_slice method_slice = SliceFromCopiedString(method.name()); + grpc_slice host_slice; + if (host_str != nullptr) { + host_slice = SliceFromCopiedString(host_str); + } + c_call = grpc_channel_create_call( + c_channel_, context->propagate_from_call_, + context->propagation_options_.c_bitmask(), cq->cq(), method_slice, + host_str == nullptr ? nullptr : &host_slice, context->raw_deadline(), + nullptr); + grpc_slice_unref(method_slice); + if (host_str != nullptr) { + grpc_slice_unref(host_slice); + } } grpc_census_call_set_context(c_call, context->census_context()); context->set_call(c_call, shared_from_this()); diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 269c523bba..25f6bab7f2 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -206,15 +206,18 @@ void MetadataCredentialsPluginWrapper::InvokePlugin( std::vector<grpc_metadata> md; for (auto it = metadata.begin(); it != metadata.end(); ++it) { grpc_metadata md_entry; - md_entry.key = it->first.c_str(); - md_entry.value = it->second.data(); - md_entry.value_length = it->second.size(); + md_entry.key = SliceFromCopiedString(it->first); + md_entry.value = SliceFromCopiedString(it->second); md_entry.flags = 0; md.push_back(md_entry); } cb(user_data, md.empty() ? nullptr : &md[0], md.size(), static_cast<grpc_status_code>(status.error_code()), status.error_message().c_str()); + for (auto it = md.begin(); it != md.end(); ++it) { + grpc_slice_unref(it->key); + grpc_slice_unref(it->value); + } } MetadataCredentialsPluginWrapper::MetadataCredentialsPluginWrapper( diff --git a/src/cpp/client/secure_credentials.h b/src/cpp/client/secure_credentials.h index 281db17e98..713654ad5b 100644 --- a/src/cpp/client/secure_credentials.h +++ b/src/cpp/client/secure_credentials.h @@ -70,7 +70,7 @@ class SecureCallCredentials final : public CallCredentials { grpc_call_credentials* const c_creds_; }; -class MetadataCredentialsPluginWrapper final { +class MetadataCredentialsPluginWrapper final : private GrpcLibraryCodegen { public: static void Destroy(void* wrapper); static void GetMetadata(void* wrapper, grpc_auth_metadata_context context, |