diff options
-rw-r--r-- | include/grpc++/impl/codegen/slice.h | 5 | ||||
-rw-r--r-- | include/grpc/impl/codegen/compression_types.h | 5 | ||||
-rw-r--r-- | src/cpp/common/channel_filter.cc | 5 | ||||
-rw-r--r-- | src/cpp/common/channel_filter.h | 2 | ||||
-rw-r--r-- | src/cpp/common/core_codegen.cc | 3 | ||||
-rw-r--r-- | src/cpp/server/server_cc.cc | 15 | ||||
-rw-r--r-- | src/cpp/server/server_context.cc | 4 | ||||
-rw-r--r-- | test/cpp/common/channel_arguments_test.cc | 2 |
8 files changed, 27 insertions, 14 deletions
diff --git a/include/grpc++/impl/codegen/slice.h b/include/grpc++/impl/codegen/slice.h index 7280698978..e79754f943 100644 --- a/include/grpc++/impl/codegen/slice.h +++ b/include/grpc++/impl/codegen/slice.h @@ -44,6 +44,11 @@ inline grpc::string_ref StringRefFromSlice(grpc_slice slice) { GRPC_SLICE_LENGTH(slice)); } +inline grpc::string StringFromCopiedSlice(grpc_slice slice) { + return grpc::string(reinterpret_cast<char*>(GRPC_SLICE_START_PTR(slice)), + GRPC_SLICE_LENGTH(slice)); +} + inline grpc_slice SliceReferencingString(const grpc::string& str) { return g_core_codegen_interface->grpc_slice_from_static_buffer(str.data(), str.length()); diff --git a/include/grpc/impl/codegen/compression_types.h b/include/grpc/impl/codegen/compression_types.h index 8810943137..170d99f431 100644 --- a/include/grpc/impl/codegen/compression_types.h +++ b/include/grpc/impl/codegen/compression_types.h @@ -41,6 +41,11 @@ extern "C" { #endif +/** To be used as initial metadata key for the request of a concrete compression + * algorithm */ +#define GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY \ + "grpc-internal-encoding-request" + /** To be used in channel arguments. * * \addtogroup grpc_arg_keys diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc index c0dc9dd63e..9aeb942f59 100644 --- a/src/cpp/common/channel_filter.cc +++ b/src/cpp/common/channel_filter.cc @@ -36,6 +36,8 @@ #include "src/core/lib/channel/channel_stack.h" #include "src/cpp/common/channel_filter.h" +#include <grpc++/impl/codegen/slice.h> + namespace grpc { // MetadataBatch @@ -45,7 +47,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_strings(exec_ctx, key.c_str(), value.c_str()); + storage->md = grpc_mdelem_from_slices(exec_ctx, SliceFromCopiedString(key), + SliceFromCopiedString(value)); 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 cac0a19e5e..bc8e625fb3 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -76,7 +76,7 @@ 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_iterator &operator++() { diff --git a/src/cpp/common/core_codegen.cc b/src/cpp/common/core_codegen.cc index 36c8938c95..a09e08ef4c 100644 --- a/src/cpp/common/core_codegen.cc +++ b/src/cpp/common/core_codegen.cc @@ -130,7 +130,8 @@ grpc_slice CoreCodegen::grpc_slice_from_static_buffer(const void* buffer, grpc_slice CoreCodegen::grpc_slice_from_copied_buffer(const void* buffer, size_t length) { - return ::grpc_slice_from_copied_buffer(buffer, length); + return ::grpc_slice_from_copied_buffer(static_cast<const char*>(buffer), + length); } void CoreCodegen::grpc_slice_buffer_add(grpc_slice_buffer* sb, diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index b7cfd6dbf1..364257a71c 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -584,10 +584,8 @@ bool ServerInterface::BaseAsyncRequest::FinalizeResult(void** tag, 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))); + StringRefFromSlice(initial_metadata_array_.metadata[i].key), + StringRefFromSlice(initial_metadata_array_.metadata[i].value))); } } grpc_metadata_array_destroy(&initial_metadata_array_); @@ -639,11 +637,12 @@ bool ServerInterface::GenericAsyncRequest::FinalizeResult(void** tag, // TODO(yangg) remove the copy here. if (*status) { static_cast<GenericServerContext*>(context_)->method_ = - call_details_.method; - static_cast<GenericServerContext*>(context_)->host_ = call_details_.host; + StringFromCopiedSlice(call_details_.method); + static_cast<GenericServerContext*>(context_)->host_ = + StringFromCopiedSlice(call_details_.host); } - gpr_free(call_details_.method); - gpr_free(call_details_.host); + grpc_slice_unref(call_details_.method); + grpc_slice_unref(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 a66ec4ac84..9fc8d752eb 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -145,8 +145,8 @@ ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, compression_level_set_(false) { for (size_t i = 0; i < metadata_count; i++) { client_metadata_.insert(std::pair<grpc::string_ref, grpc::string_ref>( - metadata[i].key, - grpc::string_ref(metadata[i].value, metadata[i].value_length))); + StringRefFromSlice(metadata[i].key), + StringRefFromSlice(metadata[i].value))); } } diff --git a/test/cpp/common/channel_arguments_test.cc b/test/cpp/common/channel_arguments_test.cc index 60d3215265..0cbe6f9636 100644 --- a/test/cpp/common/channel_arguments_test.cc +++ b/test/cpp/common/channel_arguments_test.cc @@ -228,7 +228,7 @@ TEST_F(ChannelArgumentsTest, SetSocketMutator) { EXPECT_FALSE(HasArg(arg0)); // arg0 is destroyed by grpc_socket_mutator_to_arg(mutator1) - arg1.value.pointer.vtable->destroy(arg1.value.pointer.p); + arg1.value.pointer.vtable->destroy(nullptr, arg1.value.pointer.p); } TEST_F(ChannelArgumentsTest, SetUserAgentPrefix) { |