diff options
Diffstat (limited to 'src/cpp')
-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 | ||||
-rw-r--r-- | src/cpp/common/channel_filter.cc | 8 | ||||
-rw-r--r-- | src/cpp/common/channel_filter.h | 6 | ||||
-rw-r--r-- | src/cpp/common/core_codegen.cc | 17 | ||||
-rw-r--r-- | src/cpp/server/dynamic_thread_pool.cc | 5 | ||||
-rw-r--r-- | src/cpp/server/secure_server_credentials.cc | 19 | ||||
-rw-r--r-- | src/cpp/server/server_cc.cc | 26 | ||||
-rw-r--r-- | src/cpp/server/server_context.cc | 7 | ||||
-rw-r--r-- | src/cpp/test/server_context_test_spouse.cc | 7 | ||||
-rw-r--r-- | src/cpp/util/slice_cc.cc | 2 |
12 files changed, 50 insertions, 76 deletions
diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc index c985183ae7..357d8317ad 100644 --- a/src/cpp/client/channel_cc.cc +++ b/src/cpp/client/channel_cc.cc @@ -107,20 +107,10 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, } else if (!host_.empty()) { host_str = host_.c_str(); } - 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); - } + 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_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 25f6bab7f2..269c523bba 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -206,18 +206,15 @@ void MetadataCredentialsPluginWrapper::InvokePlugin( std::vector<grpc_metadata> md; for (auto it = metadata.begin(); it != metadata.end(); ++it) { grpc_metadata md_entry; - md_entry.key = SliceFromCopiedString(it->first); - md_entry.value = SliceFromCopiedString(it->second); + md_entry.key = it->first.c_str(); + md_entry.value = it->second.data(); + md_entry.value_length = it->second.size(); 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 713654ad5b..281db17e98 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 : private GrpcLibraryCodegen { +class MetadataCredentialsPluginWrapper final { public: static void Destroy(void* wrapper); static void GetMetadata(void* wrapper, grpc_auth_metadata_context context, diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc index 253614ca9b..c0dc9dd63e 100644 --- a/src/cpp/common/channel_filter.cc +++ b/src/cpp/common/channel_filter.cc @@ -36,8 +36,6 @@ #include "src/core/lib/channel/channel_stack.h" #include "src/cpp/common/channel_filter.h" -#include <grpc++/impl/codegen/slice.h> - namespace grpc { // MetadataBatch @@ -47,10 +45,8 @@ grpc_linked_mdelem *MetadataBatch::AddMetadata(grpc_exec_ctx *exec_ctx, const string &value) { grpc_linked_mdelem *storage = new grpc_linked_mdelem; memset(storage, 0, sizeof(grpc_linked_mdelem)); - storage->md = grpc_mdelem_from_slices(exec_ctx, SliceFromCopiedString(key), - SliceFromCopiedString(value)); - GRPC_LOG_IF_ERROR("MetadataBatch::AddMetadata", - grpc_metadata_batch_link_head(exec_ctx, batch_, storage)); + storage->md = grpc_mdelem_from_strings(exec_ctx, key.c_str(), value.c_str()); + grpc_metadata_batch_link_head(batch_, storage); return storage; } diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index 5f9fd8790b..5de8f5e463 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -76,8 +76,8 @@ class MetadataBatch { class const_iterator : public std::iterator<std::bidirectional_iterator_tag, const grpc_mdelem> { public: - const grpc_mdelem &operator*() const { return elem_->md; } - const grpc_mdelem operator->() const { return elem_->md; } + const grpc_mdelem &operator*() const { return *elem_->md; } + const grpc_mdelem *operator->() const { return elem_->md; } const_iterator &operator++() { elem_ = elem_->next; @@ -133,7 +133,7 @@ class TransportOp { grpc_error *disconnect_with_error() const { return op_->disconnect_with_error; } - bool send_goaway() const { return op_->goaway_error != GRPC_ERROR_NONE; } + bool send_goaway() const { return op_->send_goaway; } // TODO(roth): Add methods for additional fields as needed. diff --git a/src/cpp/common/core_codegen.cc b/src/cpp/common/core_codegen.cc index 36e4c89354..a07ad54376 100644 --- a/src/cpp/common/core_codegen.cc +++ b/src/cpp/common/core_codegen.cc @@ -123,17 +123,6 @@ 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(static_cast<const char*>(buffer), - length); -} - void CoreCodegen::grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice slice) { ::grpc_slice_buffer_add(sb, slice); @@ -163,10 +152,8 @@ gpr_timespec CoreCodegen::gpr_time_0(gpr_clock_type type) { return ::gpr_time_0(type); } -void CoreCodegen::assert_fail(const char* failed_assertion, const char* file, - int line) { - gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "assertion failed: %s", - failed_assertion); +void CoreCodegen::assert_fail(const char* failed_assertion) { + gpr_log(GPR_ERROR, "assertion failed: %s", failed_assertion); abort(); } diff --git a/src/cpp/server/dynamic_thread_pool.cc b/src/cpp/server/dynamic_thread_pool.cc index afb5beaade..1fdc2edb25 100644 --- a/src/cpp/server/dynamic_thread_pool.cc +++ b/src/cpp/server/dynamic_thread_pool.cc @@ -31,15 +31,12 @@ * */ -#include "src/cpp/server/dynamic_thread_pool.h" - #include <mutex> #include <thread> -#include <grpc/support/log.h> +#include "src/cpp/server/dynamic_thread_pool.h" namespace grpc { - DynamicThreadPool::DynamicThread::DynamicThread(DynamicThreadPool* pool) : pool_(pool), thd_(new std::thread(&DynamicThreadPool::DynamicThread::ThreadFunc, diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc index 10f662c77d..33bdc2a1f4 100644 --- a/src/cpp/server/secure_server_credentials.cc +++ b/src/cpp/server/secure_server_credentials.cc @@ -35,12 +35,11 @@ #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) { @@ -72,8 +71,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(StringRefFromSlice(&md[i].key), - StringRefFromSlice(&md[i].value))); + metadata.insert(std::make_pair( + md[i].key, grpc::string_ref(md[i].value, md[i].value_length))); } SecureAuthContext context(ctx, false); AuthMetadataProcessor::OutputMetadata consumed_metadata; @@ -86,8 +85,9 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( for (auto it = consumed_metadata.begin(); it != consumed_metadata.end(); ++it) { grpc_metadata md_entry; - md_entry.key = SliceReferencingString(it->first); - md_entry.value = SliceReferencingString(it->second); + md_entry.key = it->first.c_str(); + md_entry.value = it->second.data(); + md_entry.value_length = it->second.size(); md_entry.flags = 0; consumed_md.push_back(md_entry); } @@ -95,8 +95,9 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( for (auto it = response_metadata.begin(); it != response_metadata.end(); ++it) { grpc_metadata md_entry; - md_entry.key = SliceReferencingString(it->first); - md_entry.value = SliceReferencingString(it->second); + md_entry.key = it->first.c_str(); + md_entry.value = it->second.data(); + md_entry.value_length = it->second.size(); md_entry.flags = 0; response_md.push_back(md_entry); } diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index dcc56eecbc..817d85a81c 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -576,6 +576,7 @@ ServerInterface::BaseAsyncRequest::BaseAsyncRequest( delete_on_finalize_(delete_on_finalize), call_(nullptr) { call_cq_->RegisterAvalanching(); // This op will trigger more ops + memset(&initial_metadata_array_, 0, sizeof(initial_metadata_array_)); } ServerInterface::BaseAsyncRequest::~BaseAsyncRequest() { @@ -585,8 +586,16 @@ ServerInterface::BaseAsyncRequest::~BaseAsyncRequest() { bool ServerInterface::BaseAsyncRequest::FinalizeResult(void** tag, bool* status) { if (*status) { - context_->client_metadata_.FillMap(); + for (size_t i = 0; i < initial_metadata_array_.count; i++) { + context_->client_metadata_.insert( + std::pair<grpc::string_ref, grpc::string_ref>( + initial_metadata_array_.metadata[i].key, + grpc::string_ref( + initial_metadata_array_.metadata[i].value, + initial_metadata_array_.metadata[i].value_length))); + } } + grpc_metadata_array_destroy(&initial_metadata_array_); context_->set_call(call_); context_->cq_ = call_cq_; Call call(call_, server_, call_cq_, server_->max_receive_message_size()); @@ -612,8 +621,8 @@ void ServerInterface::RegisteredAsyncRequest::IssueRequest( ServerCompletionQueue* notification_cq) { grpc_server_request_registered_call( server_->server(), registered_method, &call_, &context_->deadline_, - context_->client_metadata_.arr(), payload, call_cq_->cq(), - notification_cq->cq(), this); + &initial_metadata_array_, payload, call_cq_->cq(), notification_cq->cq(), + this); } ServerInterface::GenericAsyncRequest::GenericAsyncRequest( @@ -626,7 +635,7 @@ ServerInterface::GenericAsyncRequest::GenericAsyncRequest( GPR_ASSERT(notification_cq); GPR_ASSERT(call_cq); grpc_server_request_call(server->server(), &call_, &call_details_, - context->client_metadata_.arr(), call_cq->cq(), + &initial_metadata_array_, call_cq->cq(), notification_cq->cq(), this); } @@ -635,12 +644,11 @@ bool ServerInterface::GenericAsyncRequest::FinalizeResult(void** tag, // TODO(yangg) remove the copy here. if (*status) { static_cast<GenericServerContext*>(context_)->method_ = - StringFromCopiedSlice(call_details_.method); - static_cast<GenericServerContext*>(context_)->host_ = - StringFromCopiedSlice(call_details_.host); + call_details_.method; + static_cast<GenericServerContext*>(context_)->host_ = call_details_.host; } - grpc_slice_unref(call_details_.method); - grpc_slice_unref(call_details_.host); + gpr_free(call_details_.method); + gpr_free(call_details_.host); return BaseAsyncRequest::FinalizeResult(tag, status); } diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index a7aaa25572..a66ec4ac84 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -144,10 +144,9 @@ ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, sent_initial_metadata_(false), compression_level_set_(false) { for (size_t i = 0; i < metadata_count; i++) { - client_metadata_.map()->insert( - std::pair<grpc::string_ref, grpc::string_ref>( - StringRefFromSlice(&metadata[i].key), - StringRefFromSlice(&metadata[i].value))); + client_metadata_.insert(std::pair<grpc::string_ref, grpc::string_ref>( + metadata[i].key, + grpc::string_ref(metadata[i].value, metadata[i].value_length))); } } diff --git a/src/cpp/test/server_context_test_spouse.cc b/src/cpp/test/server_context_test_spouse.cc index b812d169a5..b93152eea0 100644 --- a/src/cpp/test/server_context_test_spouse.cc +++ b/src/cpp/test/server_context_test_spouse.cc @@ -40,12 +40,11 @@ void ServerContextTestSpouse::AddClientMetadata(const grpc::string& key, const grpc::string& value) { client_metadata_storage_.insert( std::pair<grpc::string, grpc::string>(key, value)); - ctx_->client_metadata_.map()->clear(); + ctx_->client_metadata_.clear(); for (auto iter = client_metadata_storage_.begin(); iter != client_metadata_storage_.end(); ++iter) { - ctx_->client_metadata_.map()->insert( - std::pair<grpc::string_ref, grpc::string_ref>(iter->first.c_str(), - iter->second.c_str())); + ctx_->client_metadata_.insert(std::pair<grpc::string_ref, grpc::string_ref>( + iter->first.c_str(), iter->second.c_str())); } } diff --git a/src/cpp/util/slice_cc.cc b/src/cpp/util/slice_cc.cc index 6efb68e123..c05f1cf124 100644 --- a/src/cpp/util/slice_cc.cc +++ b/src/cpp/util/slice_cc.cc @@ -35,7 +35,7 @@ namespace grpc { -Slice::Slice() : slice_(grpc_empty_slice()) {} +Slice::Slice() : slice_(gpr_empty_slice()) {} Slice::~Slice() { grpc_slice_unref(slice_); } |