aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext/transport/chttp2/transport/flow_control.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ext/transport/chttp2/transport/flow_control.cc')
-rw-r--r--src/core/ext/transport/chttp2/transport/flow_control.cc30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc
index 581241d392..45b6f97b05 100644
--- a/src/core/ext/transport/chttp2/transport/flow_control.cc
+++ b/src/core/ext/transport/chttp2/transport/flow_control.cc
@@ -26,7 +26,6 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-#include <grpc/support/useful.h>
#include "src/core/ext/transport/chttp2/transport/internal.h"
#include "src/core/lib/gpr/string.h"
@@ -185,10 +184,11 @@ TransportFlowControl::TransportFlowControl(const grpc_chttp2_transport* t,
uint32_t TransportFlowControl::MaybeSendUpdate(bool writing_anyway) {
FlowControlTrace trace("t updt sent", this, nullptr);
- const uint32_t target_announced_window = (const uint32_t)target_window();
+ const uint32_t target_announced_window =
+ static_cast<const uint32_t>(target_window());
if ((writing_anyway || announced_window_ <= target_announced_window / 2) &&
announced_window_ != target_announced_window) {
- const uint32_t announce = (uint32_t)GPR_CLAMP(
+ const uint32_t announce = static_cast<uint32_t> GPR_CLAMP(
target_announced_window - announced_window_, 0, UINT32_MAX);
announced_window_ += announce;
return announce;
@@ -262,7 +262,7 @@ grpc_error* StreamFlowControl::RecvData(int64_t incoming_frame_size) {
uint32_t StreamFlowControl::MaybeSendUpdate() {
FlowControlTrace trace("s updt sent", tfc_, this);
if (local_window_delta_ > announced_window_delta_) {
- uint32_t announce = (uint32_t)GPR_CLAMP(
+ uint32_t announce = static_cast<uint32_t> GPR_CLAMP(
local_window_delta_ - announced_window_delta_, 0, UINT32_MAX);
UpdateAnnouncedWindowDelta(tfc_, announce);
return announce;
@@ -282,12 +282,12 @@ void StreamFlowControl::IncomingByteStreamUpdate(size_t max_size_hint,
if (max_size_hint >= UINT32_MAX - sent_init_window) {
max_recv_bytes = UINT32_MAX - sent_init_window;
} else {
- max_recv_bytes = (uint32_t)max_size_hint;
+ max_recv_bytes = static_cast<uint32_t>(max_size_hint);
}
/* account for bytes already received but unknown to higher layers */
if (max_recv_bytes >= have_already) {
- max_recv_bytes -= (uint32_t)have_already;
+ max_recv_bytes -= static_cast<uint32_t>(have_already);
} else {
max_recv_bytes = 0;
}
@@ -296,7 +296,7 @@ void StreamFlowControl::IncomingByteStreamUpdate(size_t max_size_hint,
GPR_ASSERT(max_recv_bytes <= UINT32_MAX - sent_init_window);
if (local_window_delta_ < max_recv_bytes) {
uint32_t add_max_recv_bytes =
- (uint32_t)(max_recv_bytes - local_window_delta_);
+ static_cast<uint32_t>(max_recv_bytes - local_window_delta_);
local_window_delta_ += add_max_recv_bytes;
}
}
@@ -329,7 +329,7 @@ double TransportFlowControl::TargetLogBdp() {
double TransportFlowControl::SmoothLogBdp(double value) {
grpc_millis now = grpc_core::ExecCtx::Get()->Now();
double bdp_error = value - pid_controller_.last_control_value();
- const double dt = (double)(now - last_pid_update_) * 1e-3;
+ const double dt = static_cast<double>(now - last_pid_update_) * 1e-3;
last_pid_update_ = now;
// Limit dt to 100ms
const double kMaxDt = 0.1;
@@ -338,8 +338,8 @@ double TransportFlowControl::SmoothLogBdp(double value) {
FlowControlAction::Urgency TransportFlowControl::DeltaUrgency(
int64_t value, grpc_chttp2_setting_id setting_id) {
- int64_t delta =
- (int64_t)value - (int64_t)t_->settings[GRPC_LOCAL_SETTINGS][setting_id];
+ int64_t delta = value - static_cast<int64_t>(
+ t_->settings[GRPC_LOCAL_SETTINGS][setting_id]);
// TODO(ncteisen): tune this
if (delta != 0 && (delta <= -value / 5 || delta >= value / 5)) {
return FlowControlAction::Urgency::QUEUE_UPDATE;
@@ -358,22 +358,24 @@ FlowControlAction TransportFlowControl::PeriodicUpdate() {
const double target = pow(2, SmoothLogBdp(TargetLogBdp()));
// Though initial window 'could' drop to 0, we keep the floor at 128
- target_initial_window_size_ = (int32_t)GPR_CLAMP(target, 128, INT32_MAX);
+ target_initial_window_size_ =
+ static_cast<int32_t> GPR_CLAMP(target, 128, INT32_MAX);
action.set_send_initial_window_update(
DeltaUrgency(target_initial_window_size_,
GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE),
- (uint32_t)target_initial_window_size_);
+ static_cast<uint32_t>(target_initial_window_size_));
// get bandwidth estimate and update max_frame accordingly.
double bw_dbl = bdp_estimator_.EstimateBandwidth();
// we target the max of BDP or bandwidth in microseconds.
- int32_t frame_size = (int32_t)GPR_CLAMP(
+ int32_t frame_size = static_cast<int32_t> GPR_CLAMP(
GPR_MAX((int32_t)GPR_CLAMP(bw_dbl, 0, INT_MAX) / 1000,
target_initial_window_size_),
16384, 16777215);
action.set_send_max_frame_size_update(
- DeltaUrgency((int64_t)frame_size, GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE),
+ DeltaUrgency(static_cast<int64_t>(frame_size),
+ GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE),
frame_size);
}
return UpdateAction(action);