aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/server
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2015-07-09 12:32:48 -0700
committerGravatar yang-g <yangg@google.com>2015-07-09 12:32:48 -0700
commit3315a845efaf2116cce6184b459f8bb4e642bdde (patch)
tree47ca40731d6f9ba689a060f1734738769ed4d35e /src/cpp/server
parentf9e8e59b1c113b614736b89cb2cb4e543ba82d9f (diff)
parent494886a1be23865af7eb223b1a190fb9d2e2cc30 (diff)
Merge remote-tracking branch 'upstream/master' into security_context2
Diffstat (limited to 'src/cpp/server')
-rw-r--r--src/cpp/server/server.cc9
-rw-r--r--src/cpp/server/server_builder.cc18
2 files changed, 19 insertions, 8 deletions
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index 033c18490b..e6761d6244 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;
}
}