aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Nicolas Noble <nicolasnoble@users.noreply.github.com>2015-02-19 10:17:03 -0800
committerGravatar Nicolas Noble <nicolasnoble@users.noreply.github.com>2015-02-19 10:17:03 -0800
commit980a630e7f5c7694e7a6483d77ee82bc6766c3ab (patch)
tree738c9f1e320515f9f8726389ce6e0c4fae30a63a /src
parentf42c2ca9ef168306cc754912048405928bf91989 (diff)
parentd5577aac67b5bdf7603730b3238ece76003589f7 (diff)
Merge pull request #605 from vjpai/mac
Mac build is now ready
Diffstat (limited to 'src')
-rw-r--r--src/core/support/cpu_posix.c2
-rw-r--r--src/cpp/server/server.cc156
2 files changed, 78 insertions, 80 deletions
diff --git a/src/core/support/cpu_posix.c b/src/core/support/cpu_posix.c
index 91f722530c..91ce80c364 100644
--- a/src/core/support/cpu_posix.c
+++ b/src/core/support/cpu_posix.c
@@ -35,8 +35,6 @@
#ifdef GPR_CPU_POSIX
-#include "src/core/support/cpu.h"
-
#include <errno.h>
#include <unistd.h>
#include <string.h>
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index 7cccc58afd..f565d3aa5d 100644
--- a/src/cpp/server/server.cc
+++ b/src/cpp/server/server.cc
@@ -49,84 +49,6 @@
namespace grpc {
-Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
- ServerCredentials* creds)
- : started_(false),
- shutdown_(false),
- num_running_cb_(0),
- thread_pool_(thread_pool),
- thread_pool_owned_(thread_pool_owned),
- secure_(creds != nullptr) {
- if (creds) {
- server_ =
- grpc_secure_server_create(creds->GetRawCreds(), cq_.cq(), nullptr);
- } else {
- server_ = grpc_server_create(cq_.cq(), nullptr);
- }
-}
-
-Server::Server() {
- // Should not be called.
- GPR_ASSERT(false);
-}
-
-Server::~Server() {
- std::unique_lock<std::mutex> lock(mu_);
- if (started_ && !shutdown_) {
- lock.unlock();
- Shutdown();
- } else {
- lock.unlock();
- }
- grpc_server_destroy(server_);
- if (thread_pool_owned_) {
- delete thread_pool_;
- }
-}
-
-bool Server::RegisterService(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, cq_.cq());
- if (!tag) {
- gpr_log(GPR_DEBUG, "Attempt to register %s multiple times",
- method->name());
- return false;
- }
- sync_methods_.emplace_back(method, tag);
- }
- return true;
-}
-
-bool Server::RegisterAsyncService(AsynchronousService* service) {
- GPR_ASSERT(service->dispatch_impl_ == nullptr &&
- "Can only register an asynchronous service against one server.");
- service->dispatch_impl_ = 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,
- service->completion_queue()->cq());
- if (!tag) {
- gpr_log(GPR_DEBUG, "Attempt to register %s multiple times",
- service->method_names_[i]);
- return false;
- }
- service->request_args_[i] = tag;
- }
- return true;
-}
-
-int Server::AddPort(const grpc::string& addr) {
- GPR_ASSERT(!started_);
- if (secure_) {
- return grpc_server_add_secure_http2_port(server_, addr.c_str());
- } else {
- return grpc_server_add_http2_port(server_, addr.c_str());
- }
-}
-
class Server::SyncRequest final : public CompletionQueueTag {
public:
SyncRequest(RpcServiceMethod* method, void* tag)
@@ -247,6 +169,84 @@ class Server::SyncRequest final : public CompletionQueueTag {
grpc_completion_queue* cq_;
};
+Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
+ ServerCredentials* creds)
+ : started_(false),
+ shutdown_(false),
+ num_running_cb_(0),
+ thread_pool_(thread_pool),
+ thread_pool_owned_(thread_pool_owned),
+ secure_(creds != nullptr) {
+ if (creds) {
+ server_ =
+ grpc_secure_server_create(creds->GetRawCreds(), cq_.cq(), nullptr);
+ } else {
+ server_ = grpc_server_create(cq_.cq(), nullptr);
+ }
+}
+
+Server::Server() {
+ // Should not be called.
+ GPR_ASSERT(false);
+}
+
+Server::~Server() {
+ std::unique_lock<std::mutex> lock(mu_);
+ if (started_ && !shutdown_) {
+ lock.unlock();
+ Shutdown();
+ } else {
+ lock.unlock();
+ }
+ grpc_server_destroy(server_);
+ if (thread_pool_owned_) {
+ delete thread_pool_;
+ }
+}
+
+bool Server::RegisterService(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, cq_.cq());
+ if (!tag) {
+ gpr_log(GPR_DEBUG, "Attempt to register %s multiple times",
+ method->name());
+ return false;
+ }
+ sync_methods_.emplace_back(method, tag);
+ }
+ return true;
+}
+
+bool Server::RegisterAsyncService(AsynchronousService* service) {
+ GPR_ASSERT(service->dispatch_impl_ == nullptr &&
+ "Can only register an asynchronous service against one server.");
+ service->dispatch_impl_ = 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,
+ service->completion_queue()->cq());
+ if (!tag) {
+ gpr_log(GPR_DEBUG, "Attempt to register %s multiple times",
+ service->method_names_[i]);
+ return false;
+ }
+ service->request_args_[i] = tag;
+ }
+ return true;
+}
+
+int Server::AddPort(const grpc::string& addr) {
+ GPR_ASSERT(!started_);
+ if (secure_) {
+ return grpc_server_add_secure_http2_port(server_, addr.c_str());
+ } else {
+ return grpc_server_add_http2_port(server_, addr.c_str());
+ }
+}
+
bool Server::Start() {
GPR_ASSERT(!started_);
started_ = true;