diff --git a/include/grpcpp/impl/codegen/byte_buffer.h b/include/grpcpp/impl/codegen/byte_buffer.h index 8d6a169db99..e637efeb857 100644 --- a/include/grpcpp/impl/codegen/byte_buffer.h +++ b/include/grpcpp/impl/codegen/byte_buffer.h @@ -31,6 +31,8 @@ namespace grpc { +class ServerInterface; + namespace internal { class CallOpSendMessage; template @@ -98,6 +100,7 @@ class ByteBuffer final { private: friend class SerializationTraits; + friend class ServerInterface; friend class internal::CallOpSendMessage; template friend class internal::CallOpRecvMessage; diff --git a/include/grpcpp/impl/codegen/server_interface.h b/include/grpcpp/impl/codegen/server_interface.h index 4700763ed25..cf330ac3524 100644 --- a/include/grpcpp/impl/codegen/server_interface.h +++ b/include/grpcpp/impl/codegen/server_interface.h @@ -20,6 +20,7 @@ #define GRPCPP_IMPL_CODEGEN_SERVER_INTERFACE_H #include +#include #include #include #include @@ -185,14 +186,18 @@ class ServerInterface : public internal::CallHook { notification_cq_(notification_cq), tag_(tag), request_(request) { - IssueRequest(registered_method, &payload_, notification_cq); + IssueRequest(registered_method, payload_.bbuf_ptr(), notification_cq); + } + + ~PayloadAsyncRequest() { + payload_.Release(); // We do not own the payload_ } bool FinalizeResult(void** tag, bool* status) override { if (*status) { - if (payload_ == nullptr || - !SerializationTraits::Deserialize(payload_, request_) - .ok()) { + if (!payload_.Valid() || !SerializationTraits::Deserialize( + payload_.bbuf_ptr(), request_) + .ok()) { // If deserialization fails, we cancel the call and instantiate // a new instance of ourselves to request another call. We then // return false, which prevents the call from being returned to @@ -219,7 +224,7 @@ class ServerInterface : public internal::CallHook { ServerCompletionQueue* const notification_cq_; void* const tag_; Message* const request_; - grpc_byte_buffer* payload_; + ByteBuffer payload_; }; class GenericAsyncRequest : public BaseAsyncRequest {