From bb5227fc39fb44ae27d33d934470acd81f2ae57f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 11 Feb 2015 13:34:48 -0800 Subject: Allow server to hook calls also, fix crash --- src/cpp/common/call.cc | 6 +++--- src/cpp/server/server.cc | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src') 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 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_); -- cgit v1.2.3