CallbackRequest is no longer reused, so remove relics to support reuse

pull/24184/head
Vijay Pai 4 years ago
parent b56b321943
commit d0bf9cedcc
  1. 57
      src/cpp/server/server_cc.cc

@ -547,11 +547,7 @@ class Server::CallbackRequest final
grpc::internal::RpcMethod::SERVER_STREAMING), grpc::internal::RpcMethod::SERVER_STREAMING),
cq_(cq), cq_(cq),
tag_(this) { tag_(this) {
server->Ref(); CommonSetup(server, data);
Setup();
data->tag = &tag_;
data->call = &call_;
data->initial_metadata = &request_metadata_;
data->deadline = &deadline_; data->deadline = &deadline_;
data->optional_payload = has_request_payload_ ? &request_payload_ : nullptr; data->optional_payload = has_request_payload_ ? &request_payload_ : nullptr;
} }
@ -563,22 +559,20 @@ class Server::CallbackRequest final
: server_(server), : server_(server),
method_(nullptr), method_(nullptr),
has_request_payload_(false), has_request_payload_(false),
call_details_(new grpc_call_details),
cq_(cq), cq_(cq),
tag_(this) { tag_(this) {
server->Ref(); CommonSetup(server, data);
Setup();
data->tag = &tag_;
data->call = &call_;
data->initial_metadata = &request_metadata_;
if (!call_details_) {
call_details_ = new grpc_call_details;
grpc_call_details_init(call_details_); grpc_call_details_init(call_details_);
}
data->details = call_details_; data->details = call_details_;
} }
~CallbackRequest() { ~CallbackRequest() {
Clear(); delete call_details_;
grpc_metadata_array_destroy(&request_metadata_);
if (has_request_payload_ && request_payload_) {
grpc_byte_buffer_destroy(request_payload_);
}
server_->UnrefWithPossibleNotify(); server_->UnrefWithPossibleNotify();
} }
@ -688,40 +682,27 @@ class Server::CallbackRequest final
} }
}; };
void Clear() { template <class CallAllocation>
if (call_details_) { void CommonSetup(Server* server, CallAllocation* data) {
delete call_details_; server->Ref();
call_details_ = nullptr;
}
grpc_metadata_array_destroy(&request_metadata_);
if (has_request_payload_ && request_payload_) {
grpc_byte_buffer_destroy(request_payload_);
}
ctx_.Clear();
interceptor_methods_.ClearState();
}
void Setup() {
grpc_metadata_array_init(&request_metadata_); grpc_metadata_array_init(&request_metadata_);
ctx_.Setup(gpr_inf_future(GPR_CLOCK_REALTIME)); data->tag = &tag_;
request_payload_ = nullptr; data->call = &call_;
request_ = nullptr; data->initial_metadata = &request_metadata_;
handler_data_ = nullptr;
request_status_ = grpc::Status();
} }
Server* const server_; Server* const server_;
grpc::internal::RpcServiceMethod* const method_; grpc::internal::RpcServiceMethod* const method_;
const bool has_request_payload_; const bool has_request_payload_;
grpc_byte_buffer* request_payload_; grpc_byte_buffer* request_payload_ = nullptr;
void* request_; void* request_ = nullptr;
void* handler_data_; void* handler_data_ = nullptr;
grpc::Status request_status_; grpc::Status request_status_;
grpc_call_details* call_details_ = nullptr; grpc_call_details* const call_details_ = nullptr;
grpc_call* call_; grpc_call* call_;
gpr_timespec deadline_; gpr_timespec deadline_;
grpc_metadata_array request_metadata_; grpc_metadata_array request_metadata_;
grpc::CompletionQueue* cq_; grpc::CompletionQueue* const cq_;
CallbackCallTag tag_; CallbackCallTag tag_;
ServerContextType ctx_; ServerContextType ctx_;
grpc::internal::InterceptorBatchMethodsImpl interceptor_methods_; grpc::internal::InterceptorBatchMethodsImpl interceptor_methods_;

Loading…
Cancel
Save