diff options
author | Yang Gao <yangg@google.com> | 2015-07-08 21:47:37 -0700 |
---|---|---|
committer | Yang Gao <yangg@google.com> | 2015-07-08 21:47:37 -0700 |
commit | 19512b1febcdd7d4a947dfcafeb58e51e64ee609 (patch) | |
tree | d94dad96954755c6ca8c29d467b8d80b7ac66203 /src | |
parent | d130bdd176810c49f4e1d584f648cdbc46801d7b (diff) | |
parent | b09caa967d82c34d90ecb1109c816f7399b34df3 (diff) |
Merge pull request #2320 from ctiller/hosts-need-names-too
Support registering services against specific hosts
Diffstat (limited to 'src')
-rw-r--r-- | src/cpp/client/channel.cc | 2 | ||||
-rw-r--r-- | src/cpp/server/server.cc | 9 | ||||
-rw-r--r-- | src/cpp/server/server_builder.cc | 18 |
3 files changed, 20 insertions, 9 deletions
diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index 5bc6f6fd91..da31d000b3 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -60,7 +60,7 @@ Channel::~Channel() { grpc_channel_destroy(c_channel_); } Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, CompletionQueue* cq) { auto c_call = - method.channel_tag() + method.channel_tag() && context->authority().empty() ? grpc_channel_create_registered_call(c_channel_, cq->cq(), method.channel_tag(), context->raw_deadline()) diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 1437b2dea7..f9d20ff579 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -207,10 +207,11 @@ Server::~Server() { delete sync_methods_; } -bool Server::RegisterService(RpcService* service) { +bool Server::RegisterService(const grpc::string *host, RpcService* service) { for (int i = 0; i < service->GetMethodCount(); ++i) { RpcServiceMethod* method = service->GetMethod(i); - void* tag = grpc_server_register_method(server_, method->name(), nullptr); + void* tag = grpc_server_register_method( + server_, method->name(), host ? host->c_str() : nullptr); if (!tag) { gpr_log(GPR_DEBUG, "Attempt to register %s multiple times", method->name()); @@ -222,14 +223,14 @@ bool Server::RegisterService(RpcService* service) { return true; } -bool Server::RegisterAsyncService(AsynchronousService* service) { +bool Server::RegisterAsyncService(const grpc::string *host, AsynchronousService* service) { GPR_ASSERT(service->server_ == nullptr && "Can only register an asynchronous service against one server."); service->server_ = this; service->request_args_ = new void*[service->method_count_]; for (size_t i = 0; i < service->method_count_; ++i) { void* tag = grpc_server_register_method(server_, service->method_names_[i], - nullptr); + host ? host->c_str() : nullptr); if (!tag) { gpr_log(GPR_DEBUG, "Attempt to register %s multiple times", service->method_names_[i]); diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index 3ee1d54e76..86c78f05ff 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -51,11 +51,21 @@ std::unique_ptr<ServerCompletionQueue> ServerBuilder::AddCompletionQueue() { } void ServerBuilder::RegisterService(SynchronousService* service) { - services_.push_back(service->service()); + services_.emplace_back(new NamedService<RpcService>(service->service())); } void ServerBuilder::RegisterAsyncService(AsynchronousService* service) { - async_services_.push_back(service); + async_services_.emplace_back(new NamedService<AsynchronousService>(service)); +} + +void ServerBuilder::RegisterService( + const grpc::string& addr, SynchronousService* service) { + services_.emplace_back(new NamedService<RpcService>(addr, service->service())); +} + +void ServerBuilder::RegisterAsyncService( + const grpc::string& addr, AsynchronousService* service) { + async_services_.emplace_back(new NamedService<AsynchronousService>(addr, service)); } void ServerBuilder::RegisterAsyncGenericService(AsyncGenericService* service) { @@ -97,13 +107,13 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() { } for (auto service = services_.begin(); service != services_.end(); service++) { - if (!server->RegisterService(*service)) { + if (!server->RegisterService((*service)->host.get(), (*service)->service)) { return nullptr; } } for (auto service = async_services_.begin(); service != async_services_.end(); service++) { - if (!server->RegisterAsyncService(*service)) { + if (!server->RegisterAsyncService((*service)->host.get(), (*service)->service)) { return nullptr; } } |