Make server.cc compile again

pull/501/head
Craig Tiller 10 years ago
parent 20781ccf54
commit 7c72adcdc7
  1. 40
      src/cpp/server/server.cc
  2. 4
      src/cpp/server/thread_pool.h

@ -87,6 +87,7 @@ bool Server::RegisterService(RpcService *service) {
}
method_map_.insert(std::make_pair(method->name(), method));
}
return true;
}
int Server::AddPort(const grpc::string &addr) {
@ -104,7 +105,9 @@ bool Server::Start() {
grpc_server_start(server_);
// Start processing rpcs.
ScheduleCallback();
if (thread_pool_) {
ScheduleCallback();
}
return true;
}
@ -132,8 +135,8 @@ void Server::Shutdown() {
// Shutdown the completion queue.
cq_.Shutdown();
void *tag = nullptr;
CompletionQueue::CompletionType t = cq_.Next(&tag);
GPR_ASSERT(t == CompletionQueue::QUEUE_CLOSED);
bool ok = false;
GPR_ASSERT(false == cq_.Next(&tag, &ok));
}
void Server::ScheduleCallback() {
@ -148,22 +151,23 @@ void Server::RunRpc() {
// Wait for one more incoming rpc.
void *tag = nullptr;
AllowOneRpc();
CompletionQueue::CompletionType t = cq_.Next(&tag);
GPR_ASSERT(t == CompletionQueue::SERVER_RPC_NEW);
AsyncServerContext *server_context = static_cast<AsyncServerContext *>(tag);
// server_context could be nullptr during server shutdown.
if (server_context != nullptr) {
// Schedule a new callback to handle more rpcs.
ScheduleCallback();
RpcServiceMethod *method = nullptr;
auto iter = method_map_.find(server_context->method());
if (iter != method_map_.end()) {
method = iter->second;
bool ok = false;
GPR_ASSERT(cq_.Next(&tag, &ok));
if (ok) {
AsyncServerContext *server_context = static_cast<AsyncServerContext *>(tag);
// server_context could be nullptr during server shutdown.
if (server_context != nullptr) {
// Schedule a new callback to handle more rpcs.
ScheduleCallback();
RpcServiceMethod *method = nullptr;
auto iter = method_map_.find(server_context->method());
if (iter != method_map_.end()) {
method = iter->second;
}
ServerRpcHandler rpc_handler(server_context, method);
rpc_handler.StartRpc();
}
ServerRpcHandler rpc_handler(server_context, method);
rpc_handler.StartRpc();
}
{

@ -44,12 +44,12 @@
namespace grpc {
class ThreadPool : public ThreadPoolInterface {
class ThreadPool final : public ThreadPoolInterface {
public:
explicit ThreadPool(int num_threads);
~ThreadPool();
void ScheduleCallback(const std::function<void()> &callback) final;
void ScheduleCallback(const std::function<void()> &callback) override;
private:
std::mutex mu_;

Loading…
Cancel
Save