aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpcpp
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2018-10-29 02:10:00 -0700
committerGravatar Vijay Pai <vpai@google.com>2018-10-29 02:10:00 -0700
commit371b1d99d580ffe9fe6ac3c3898b26dc7f59b7e4 (patch)
tree2d9467c28e6da1a36aba14637c564e3b06f2d701 /include/grpcpp
parent01313976e1a44b5c9625d3a349fffa55471beff4 (diff)
Add call as param to MethodHandler::Deserialize to allow arena use
Diffstat (limited to 'include/grpcpp')
-rw-r--r--include/grpcpp/impl/codegen/method_handler_impl.h23
-rw-r--r--include/grpcpp/impl/codegen/rpc_service_method.h3
2 files changed, 16 insertions, 10 deletions
diff --git a/include/grpcpp/impl/codegen/method_handler_impl.h b/include/grpcpp/impl/codegen/method_handler_impl.h
index 4f02e3e39b..dd53f975f6 100644
--- a/include/grpcpp/impl/codegen/method_handler_impl.h
+++ b/include/grpcpp/impl/codegen/method_handler_impl.h
@@ -66,7 +66,7 @@ class RpcMethodHandler : public MethodHandler {
return func_(service_, param.server_context,
static_cast<RequestType*>(param.request), &rsp);
});
- delete static_cast<RequestType*>(param.request);
+ static_cast<RequestType*>(param.request)->~RequestType();
}
GPR_CODEGEN_ASSERT(!param.server_context->sent_initial_metadata_);
@@ -86,16 +86,18 @@ class RpcMethodHandler : public MethodHandler {
param.call->cq()->Pluck(&ops);
}
- void* Deserialize(grpc_byte_buffer* req, Status* status) final {
+ void* Deserialize(grpc_call* call, grpc_byte_buffer* req,
+ Status* status) final {
ByteBuffer buf;
buf.set_buffer(req);
- auto* request = new RequestType();
+ auto* request = new (g_core_codegen_interface->grpc_call_arena_alloc(
+ call, sizeof(RequestType))) RequestType();
*status = SerializationTraits<RequestType>::Deserialize(&buf, request);
buf.Release();
if (status->ok()) {
return request;
}
- delete request;
+ request->~RequestType();
return nullptr;
}
@@ -170,7 +172,7 @@ class ServerStreamingHandler : public MethodHandler {
return func_(service_, param.server_context,
static_cast<RequestType*>(param.request), &writer);
});
- delete static_cast<RequestType*>(param.request);
+ static_cast<RequestType*>(param.request)->~RequestType();
}
CallOpSet<CallOpSendInitialMetadata, CallOpServerSendStatus> ops;
@@ -189,16 +191,18 @@ class ServerStreamingHandler : public MethodHandler {
param.call->cq()->Pluck(&ops);
}
- void* Deserialize(grpc_byte_buffer* req, Status* status) final {
+ void* Deserialize(grpc_call* call, grpc_byte_buffer* req,
+ Status* status) final {
ByteBuffer buf;
buf.set_buffer(req);
- auto* request = new RequestType();
+ auto* request = new (g_core_codegen_interface->grpc_call_arena_alloc(
+ call, sizeof(RequestType))) RequestType();
*status = SerializationTraits<RequestType>::Deserialize(&buf, request);
buf.Release();
if (status->ok()) {
return request;
}
- delete request;
+ request->~RequestType();
return nullptr;
}
@@ -323,7 +327,8 @@ class ErrorMethodHandler : public MethodHandler {
param.call->cq()->Pluck(&ops);
}
- void* Deserialize(grpc_byte_buffer* req, Status* status) final {
+ void* Deserialize(grpc_call* call, grpc_byte_buffer* req,
+ Status* status) final {
// We have to destroy any request payload
if (req != nullptr) {
g_core_codegen_interface->grpc_byte_buffer_destroy(req);
diff --git a/include/grpcpp/impl/codegen/rpc_service_method.h b/include/grpcpp/impl/codegen/rpc_service_method.h
index 44da2bd768..e77f4046a3 100644
--- a/include/grpcpp/impl/codegen/rpc_service_method.h
+++ b/include/grpcpp/impl/codegen/rpc_service_method.h
@@ -56,7 +56,8 @@ class MethodHandler {
a HandlerParameter and passed to RunHandler. It is illegal to access the
pointer after calling RunHandler. Ownership of the deserialized request is
retained by the handler. Returns nullptr if deserialization failed. */
- virtual void* Deserialize(grpc_byte_buffer* req, Status* status) {
+ virtual void* Deserialize(grpc_call* call, grpc_byte_buffer* req,
+ Status* status) {
GPR_CODEGEN_ASSERT(req == nullptr);
return nullptr;
}