[chaotic-good] Clean up unused requested_read_args in PromiseEndpoint::ReadCallback. (#33848)

This is a clean up PR for discussion in #33257. 
<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
pull/33856/head
nanahpang 2 years ago committed by GitHub
parent 8bdbd96ba8
commit 44864c1589
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      src/core/lib/transport/promise_endpoint.cc
  2. 26
      src/core/lib/transport/promise_endpoint.h

@ -68,11 +68,8 @@ void PromiseEndpoint::WriteCallback(absl::Status status) {
write_waker_.Wakeup(); write_waker_.Wakeup();
} }
void PromiseEndpoint::ReadCallback( void PromiseEndpoint::ReadCallback(absl::Status status,
absl::Status status, size_t num_bytes_requested, size_t num_bytes_requested) {
absl::optional<
struct grpc_event_engine::experimental::EventEngine::Endpoint::ReadArgs>
requested_read_args) {
if (!status.ok()) { if (!status.ok()) {
// Invalidates all previous reads. // Invalidates all previous reads.
pending_read_buffer_.Clear(); pending_read_buffer_.Clear();
@ -88,18 +85,16 @@ void PromiseEndpoint::ReadCallback(
if (read_buffer_.Length() < num_bytes_requested) { if (read_buffer_.Length() < num_bytes_requested) {
// A further read is needed. // A further read is needed.
// Set read args with number of bytes needed as hint. // Set read args with number of bytes needed as hint.
requested_read_args = { grpc_event_engine::experimental::EventEngine::Endpoint::ReadArgs
static_cast<int64_t>(num_bytes_requested - read_buffer_.Length())}; read_args = {static_cast<int64_t>(num_bytes_requested -
read_buffer_.Length())};
// If `Read()` returns true immediately, the callback will not be // If `Read()` returns true immediately, the callback will not be
// called. We still need to call our callback to pick up the result and // called. We still need to call our callback to pick up the result and
// maybe do further reads. // maybe do further reads.
if (endpoint_->Read(std::bind(&PromiseEndpoint::ReadCallback, this, if (endpoint_->Read(std::bind(&PromiseEndpoint::ReadCallback, this,
std::placeholders::_1, num_bytes_requested, std::placeholders::_1, num_bytes_requested),
requested_read_args), &pending_read_buffer_, &read_args)) {
&pending_read_buffer_, ReadCallback(absl::OkStatus(), num_bytes_requested);
&(requested_read_args.value()))) {
ReadCallback(absl::OkStatus(), num_bytes_requested,
requested_read_args);
} }
} else { } else {
MutexLock lock(&read_mutex_); MutexLock lock(&read_mutex_);

@ -107,16 +107,14 @@ class PromiseEndpoint {
lock.Release(); lock.Release();
// Set read args with hinted bytes. // Set read args with hinted bytes.
grpc_event_engine::experimental::EventEngine::Endpoint::ReadArgs grpc_event_engine::experimental::EventEngine::Endpoint::ReadArgs
read_args; read_args = {static_cast<int64_t>(num_bytes)};
read_args.read_hint_bytes = num_bytes;
// If `Read()` returns true immediately, the callback will not be // If `Read()` returns true immediately, the callback will not be
// called. We still need to call our callback to pick up the result and // called. We still need to call our callback to pick up the result and
// maybe do further reads. // maybe do further reads.
if (endpoint_->Read(std::bind(&PromiseEndpoint::ReadCallback, this, if (endpoint_->Read(std::bind(&PromiseEndpoint::ReadCallback, this,
std::placeholders::_1, num_bytes, std::placeholders::_1, num_bytes),
absl::nullopt /* uses default arguments */),
&pending_read_buffer_, &read_args)) { &pending_read_buffer_, &read_args)) {
ReadCallback(absl::OkStatus(), num_bytes, read_args); ReadCallback(absl::OkStatus(), num_bytes);
} }
} else { } else {
read_result_ = absl::OkStatus(); read_result_ = absl::OkStatus();
@ -158,16 +156,15 @@ class PromiseEndpoint {
if (read_buffer_.Length() < num_bytes) { if (read_buffer_.Length() < num_bytes) {
lock.Release(); lock.Release();
// Set read args with num_bytes as hint. // Set read args with num_bytes as hint.
const struct grpc_event_engine::experimental::EventEngine::Endpoint:: grpc_event_engine::experimental::EventEngine::Endpoint::ReadArgs
ReadArgs read_args = {static_cast<int64_t>(num_bytes)}; read_args = {static_cast<int64_t>(num_bytes)};
// If `Read()` returns true immediately, the callback will not be // If `Read()` returns true immediately, the callback will not be
// called. We still need to call our callback to pick up the result // called. We still need to call our callback to pick up the result
// and maybe do further reads. // and maybe do further reads.
if (endpoint_->Read( if (endpoint_->Read(std::bind(&PromiseEndpoint::ReadCallback, this,
std::bind(&PromiseEndpoint::ReadCallback, this, std::placeholders::_1, num_bytes),
std::placeholders::_1, num_bytes, read_args), &pending_read_buffer_, &read_args)) {
&pending_read_buffer_, &read_args)) { ReadCallback(absl::OkStatus(), num_bytes);
ReadCallback(absl::OkStatus(), num_bytes, read_args);
} }
} else { } else {
read_result_ = absl::OkStatus(); read_result_ = absl::OkStatus();
@ -284,10 +281,7 @@ class PromiseEndpoint {
// Callback function used for `EventEngine::Endpoint::Read()` shared between // Callback function used for `EventEngine::Endpoint::Read()` shared between
// `Read()` and `ReadSlice()`. // `Read()` and `ReadSlice()`.
void ReadCallback(absl::Status status, size_t num_bytes_requested, void ReadCallback(absl::Status status, size_t num_bytes_requested);
absl::optional<struct grpc_event_engine::experimental::
EventEngine::Endpoint::ReadArgs>
requested_read_arg = absl::nullopt);
// Callback function used for `EventEngine::Endpoint::Read()` in `ReadByte()`. // Callback function used for `EventEngine::Endpoint::Read()` in `ReadByte()`.
void ReadByteCallback(absl::Status status); void ReadByteCallback(absl::Status status);
}; };

Loading…
Cancel
Save