aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-11-21 08:45:38 -0800
committerGravatar Craig Tiller <ctiller@google.com>2016-11-21 08:45:38 -0800
commitcca758933384feb49fb981ff224bddc5eeff6f22 (patch)
tree2ac33df60d79e967822b7af99afb010422ac653c /src/cpp
parentcf1c821ae6565c7ab1c1cf8b34660c4f69949171 (diff)
Start moving C++ to slice interfaces
Diffstat (limited to 'src/cpp')
-rw-r--r--src/cpp/client/channel_cc.cc18
-rw-r--r--src/cpp/client/secure_credentials.cc5
-rw-r--r--src/cpp/common/core_codegen.cc10
-rw-r--r--src/cpp/server/secure_server_credentials.cc19
4 files changed, 35 insertions, 17 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..21445c91fd 100644
--- a/src/cpp/client/secure_credentials.cc
+++ b/src/cpp/client/secure_credentials.cc
@@ -206,9 +206,8 @@ 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 = SliceReferencingString(it->first);
+ md_entry.value = SliceReferencingString(it->second);
md_entry.flags = 0;
md.push_back(md_entry);
}
diff --git a/src/cpp/common/core_codegen.cc b/src/cpp/common/core_codegen.cc
index a07ad54376..36c8938c95 100644
--- a/src/cpp/common/core_codegen.cc
+++ b/src/cpp/common/core_codegen.cc
@@ -123,6 +123,16 @@ grpc_slice CoreCodegen::grpc_slice_split_tail(grpc_slice* s, size_t split) {
return ::grpc_slice_split_tail(s, split);
}
+grpc_slice CoreCodegen::grpc_slice_from_static_buffer(const void* buffer,
+ size_t length) {
+ return ::grpc_slice_from_static_buffer(buffer, length);
+}
+
+grpc_slice CoreCodegen::grpc_slice_from_copied_buffer(const void* buffer,
+ size_t length) {
+ return ::grpc_slice_from_copied_buffer(buffer, length);
+}
+
void CoreCodegen::grpc_slice_buffer_add(grpc_slice_buffer* sb,
grpc_slice slice) {
::grpc_slice_buffer_add(sb, slice);
diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc
index 33bdc2a1f4..3c90986cd0 100644
--- a/src/cpp/server/secure_server_credentials.cc
+++ b/src/cpp/server/secure_server_credentials.cc
@@ -35,11 +35,12 @@
#include <map>
#include <memory>
+#include <grpc++/impl/codegen/slice.h>
+#include <grpc++/security/auth_metadata_processor.h>
+
#include "src/cpp/common/secure_auth_context.h"
#include "src/cpp/server/secure_server_credentials.h"
-#include <grpc++/security/auth_metadata_processor.h>
-
namespace grpc {
void AuthMetadataProcessorAyncWrapper::Destroy(void* wrapper) {
@@ -71,8 +72,8 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor(
grpc_process_auth_metadata_done_cb cb, void* user_data) {
AuthMetadataProcessor::InputMetadata metadata;
for (size_t i = 0; i < num_md; i++) {
- metadata.insert(std::make_pair(
- md[i].key, grpc::string_ref(md[i].value, md[i].value_length)));
+ metadata.insert(std::make_pair(StringRefFromSlice(md[i].key),
+ StringRefFromSlice(md[i].value)));
}
SecureAuthContext context(ctx, false);
AuthMetadataProcessor::OutputMetadata consumed_metadata;
@@ -85,9 +86,8 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor(
for (auto it = consumed_metadata.begin(); it != consumed_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 = SliceReferencingString(it->first);
+ md_entry.value = SliceReferencingString(it->second);
md_entry.flags = 0;
consumed_md.push_back(md_entry);
}
@@ -95,9 +95,8 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor(
for (auto it = response_metadata.begin(); it != response_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 = SliceReferencingString(it->first);
+ md_entry.value = SliceReferencingString(it->second);
md_entry.flags = 0;
response_md.push_back(md_entry);
}