diff options
author | Yang Gao <yangg@google.com> | 2017-02-23 14:30:25 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-23 14:30:25 -0800 |
commit | 1556aa1a48ed5a997c3bdc1b634a2e4389346f1b (patch) | |
tree | 5c8b767ff144efdba611a3e929aa67f5d5cb7932 | |
parent | 0ceb94928f57e7c5a5e7e7b19e73a23573ca0e7a (diff) | |
parent | c42d844d27bc76c817c53802b3e1cf09a2360d04 (diff) |
Merge pull request #9718 from yang-g/metadata
Let ServerContext own the initial_metadata array for sync calls
-rw-r--r-- | include/grpc++/impl/codegen/server_context.h | 3 | ||||
-rw-r--r-- | src/cpp/server/server_cc.cc | 3 | ||||
-rw-r--r-- | src/cpp/server/server_context.cc | 13 |
3 files changed, 7 insertions, 12 deletions
diff --git a/include/grpc++/impl/codegen/server_context.h b/include/grpc++/impl/codegen/server_context.h index 43bbff6ce9..bf9a9b6f1a 100644 --- a/include/grpc++/impl/codegen/server_context.h +++ b/include/grpc++/impl/codegen/server_context.h @@ -213,8 +213,7 @@ class ServerContext { void BeginCompletionOp(Call* call); - ServerContext(gpr_timespec deadline, grpc_metadata* metadata, - size_t metadata_count); + ServerContext(gpr_timespec deadline, grpc_metadata_array* arr); void set_call(grpc_call* call) { call_ = call; } diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index 150c5a5faf..9e11a8a9e0 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -189,8 +189,7 @@ class Server::SyncRequest final : public CompletionQueueTag { explicit CallData(Server* server, SyncRequest* mrd) : cq_(mrd->cq_), call_(mrd->call_, server, &cq_, server->max_receive_message_size()), - ctx_(mrd->deadline_, mrd->request_metadata_.metadata, - mrd->request_metadata_.count), + ctx_(mrd->deadline_, &mrd->request_metadata_), has_request_payload_(mrd->has_request_payload_), request_payload_(mrd->request_payload_), method_(mrd->method_) { diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index 6edbc90927..05c05c8695 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -33,7 +33,9 @@ #include <grpc++/server_context.h> +#include <algorithm> #include <mutex> +#include <utility> #include <grpc++/completion_queue.h> #include <grpc++/impl/call.h> @@ -133,8 +135,7 @@ ServerContext::ServerContext() sent_initial_metadata_(false), compression_level_set_(false) {} -ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, - size_t metadata_count) +ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata_array* arr) : completion_op_(nullptr), has_notify_when_done_tag_(false), async_notify_when_done_tag_(nullptr), @@ -143,12 +144,8 @@ ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, cq_(nullptr), 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))); - } + std::swap(*client_metadata_.arr(), *arr); + client_metadata_.FillMap(); } ServerContext::~ServerContext() { |