diff options
author | Craig Tiller <ctiller@google.com> | 2015-02-11 13:34:48 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-02-11 13:34:48 -0800 |
commit | bb5227fc39fb44ae27d33d934470acd81f2ae57f (patch) | |
tree | 22c6db8f37aec542414273e30916da86cc25986b /src | |
parent | 7c2f3f7af1ebf6ca88780271e0d6f0f8147c3a33 (diff) |
Allow server to hook calls also, fix crash
Diffstat (limited to 'src')
-rw-r--r-- | src/cpp/common/call.cc | 6 | ||||
-rw-r--r-- | src/cpp/server/server.cc | 16 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/cpp/common/call.cc b/src/cpp/common/call.cc index f97240d067..4d465e0a6f 100644 --- a/src/cpp/common/call.cc +++ b/src/cpp/common/call.cc @@ -184,11 +184,11 @@ void CCallDeleter::operator()(grpc_call* c) { grpc_call_destroy(c); } -Call::Call(grpc_call* call, ChannelInterface* channel, CompletionQueue* cq) - : channel_(channel), cq_(cq), call_(call) {} +Call::Call(grpc_call* call, CallHook *call_hook, CompletionQueue* cq) + : call_hook_(call_hook), cq_(cq), call_(call) {} void Call::PerformOps(CallOpBuffer* buffer) { - channel_->PerformOpsOnCall(buffer, this); + call_hook_->PerformOpsOnCall(buffer, this); } } // namespace grpc diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 049c3e36b2..8974850b8c 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -143,9 +143,9 @@ class Server::MethodRequestData final : public CompletionQueueTag { class CallData { public: - explicit CallData(MethodRequestData *mrd) + explicit CallData(Server *server, MethodRequestData *mrd) : cq_(mrd->cq_), - call_(mrd->call_, nullptr, &cq_), + call_(mrd->call_, server, &cq_), ctx_(mrd->deadline_, mrd->request_metadata_.metadata, mrd->request_metadata_.count), has_request_payload_(mrd->has_request_payload_), @@ -235,6 +235,16 @@ void Server::Shutdown() { } } +void Server::PerformOpsOnCall(CallOpBuffer *buf, Call *call) { + static const size_t MAX_OPS = 8; + size_t nops = MAX_OPS; + grpc_op ops[MAX_OPS]; + buf->FillOps(ops, &nops); + GPR_ASSERT(GRPC_CALL_OK == + grpc_call_start_batch(call->call(), ops, nops, + buf)); +} + void Server::ScheduleCallback() { { std::unique_lock<std::mutex> lock(mu_); @@ -248,7 +258,7 @@ void Server::RunRpc() { bool ok; auto *mrd = MethodRequestData::Wait(&cq_, &ok); if (mrd) { - MethodRequestData::CallData cd(mrd); + MethodRequestData::CallData cd(this, mrd); if (ok) { mrd->Request(server_); |