diff options
author | Sree Kuchibhotla <sreek@google.com> | 2017-03-21 10:28:40 -0700 |
---|---|---|
committer | Sree Kuchibhotla <sreek@google.com> | 2017-03-21 10:28:40 -0700 |
commit | 36c370793ba250fc423dcd0947fc8a07759c4d08 (patch) | |
tree | a82d809fb9ae41011e5f47c11df208d7d1db5736 /src/cpp | |
parent | 89da88c7b44cb0f1765f6216faf2d5ec3d16f403 (diff) | |
parent | e50c7bdcc83638544eed01f20c19b89648d78fe9 (diff) |
Merge branch 'master' into cq_create_api_changes
Diffstat (limited to 'src/cpp')
-rw-r--r-- | src/cpp/common/channel_arguments.cc | 14 | ||||
-rw-r--r-- | src/cpp/common/channel_filter.h | 3 | ||||
-rw-r--r-- | src/cpp/common/version_cc.cc | 2 | ||||
-rw-r--r-- | src/cpp/server/channel_argument_option.cc | 78 | ||||
-rw-r--r-- | src/cpp/server/server_builder.cc | 8 | ||||
-rw-r--r-- | src/cpp/server/server_cc.cc | 2 |
6 files changed, 102 insertions, 5 deletions
diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index 65f3277499..eddcacc332 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -81,6 +81,16 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other) } } +ChannelArguments::~ChannelArguments() { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + for (auto it = args_.begin(); it != args_.end(); ++it) { + if (it->type == GRPC_ARG_POINTER) { + it->value.pointer.vtable->destroy(&exec_ctx, it->value.pointer.p); + } + } + grpc_exec_ctx_finish(&exec_ctx); +} + void ChannelArguments::Swap(ChannelArguments& other) { args_.swap(other.args_); strings_.swap(other.strings_); @@ -101,8 +111,10 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { for (auto it = args_.begin(); it != args_.end(); ++it) { if (it->type == mutator_arg.type && grpc::string(it->key) == grpc::string(mutator_arg.key)) { + GPR_ASSERT(!replaced); it->value.pointer.vtable->destroy(&exec_ctx, it->value.pointer.p); it->value.pointer = mutator_arg.value.pointer; + replaced = true; } } grpc_exec_ctx_finish(&exec_ctx); @@ -185,7 +197,7 @@ void ChannelArguments::SetPointerWithVtable( arg.type = GRPC_ARG_POINTER; strings_.push_back(key); arg.key = const_cast<char*>(strings_.back().c_str()); - arg.value.pointer.p = value; + arg.value.pointer.p = vtable->copy(value); arg.value.pointer.vtable = vtable; args_.push_back(arg); } diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index 79c4bab985..494d5d64d7 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -318,7 +318,8 @@ class ChannelFilter final { static void DestroyCallElement(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, const grpc_call_final_info *final_info, - void *and_free_memory) { + grpc_closure *then_call_closure) { + GPR_ASSERT(then_call_closure == NULL); reinterpret_cast<CallDataType *>(elem->call_data)->~CallDataType(); } diff --git a/src/cpp/common/version_cc.cc b/src/cpp/common/version_cc.cc index 039c530cdc..f5a0e4131d 100644 --- a/src/cpp/common/version_cc.cc +++ b/src/cpp/common/version_cc.cc @@ -37,5 +37,5 @@ #include <grpc++/grpc++.h> namespace grpc { -grpc::string Version() { return "1.2.0-dev"; } +grpc::string Version() { return "1.3.0-dev"; } } diff --git a/src/cpp/server/channel_argument_option.cc b/src/cpp/server/channel_argument_option.cc new file mode 100644 index 0000000000..723f968ff8 --- /dev/null +++ b/src/cpp/server/channel_argument_option.cc @@ -0,0 +1,78 @@ +/* + * + * Copyright 2017, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <grpc++/impl/channel_argument_option.h> + +namespace grpc { + +std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption( + const grpc::string &name, const grpc::string &value) { + class StringOption final : public ServerBuilderOption { + public: + StringOption(const grpc::string &name, const grpc::string &value) + : name_(name), value_(value) {} + + virtual void UpdateArguments(ChannelArguments *args) override { + args->SetString(name_, value_); + } + virtual void UpdatePlugins( + std::vector<std::unique_ptr<ServerBuilderPlugin>> *plugins) override {} + + private: + const grpc::string name_; + const grpc::string value_; + }; + return std::unique_ptr<ServerBuilderOption>(new StringOption(name, value)); +} + +std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption( + const grpc::string &name, int value) { + class IntOption final : public ServerBuilderOption { + public: + IntOption(const grpc::string &name, int value) + : name_(name), value_(value) {} + + virtual void UpdateArguments(ChannelArguments *args) override { + args->SetInt(name_, value_); + } + virtual void UpdatePlugins( + std::vector<std::unique_ptr<ServerBuilderPlugin>> *plugins) override {} + + private: + const grpc::string name_; + const int value_; + }; + return std::unique_ptr<ServerBuilderOption>(new IntOption(name, value)); +} + +} // namespace grpc diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index 00a90bb184..4eb4b5a1b2 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -323,9 +323,14 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() { } } + bool added_port = false; for (auto port = ports_.begin(); port != ports_.end(); port++) { int r = server->AddListeningPort(port->addr, port->creds.get()); - if (!r) return nullptr; + if (!r) { + if (added_port) server->Shutdown(); + return nullptr; + } + added_port = true; if (port->selected_port != nullptr) { *port->selected_port = r; } @@ -333,6 +338,7 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() { auto cqs_data = cqs_.empty() ? nullptr : &cqs_[0]; if (!server->Start(cqs_data, cqs_.size())) { + if (added_port) server->Shutdown(); return nullptr; } diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index 50c4cafa7a..b11ea725e1 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -545,7 +545,7 @@ bool Server::Start(ServerCompletionQueue** cqs, size_t num_cqs) { void Server::ShutdownInternal(gpr_timespec deadline) { std::unique_lock<std::mutex> lock(mu_); - if (started_ && !shutdown_) { + if (!shutdown_) { shutdown_ = true; /// The completion queue to use for server shutdown completion notification |