diff options
Diffstat (limited to 'src/core/ext/transport/chttp2')
25 files changed, 481 insertions, 473 deletions
diff --git a/src/core/ext/transport/chttp2/alpn/alpn.cc b/src/core/ext/transport/chttp2/alpn/alpn.cc index 89892457d6..5c4bfd03fa 100644 --- a/src/core/ext/transport/chttp2/alpn/alpn.cc +++ b/src/core/ext/transport/chttp2/alpn/alpn.cc @@ -18,7 +18,8 @@ #include "src/core/ext/transport/chttp2/alpn/alpn.h" #include <grpc/support/log.h> -#include <grpc/support/useful.h> + +#include "src/core/lib/gpr/useful.h" /* in order of preference */ static const char* const supported_versions[] = {"grpc-exp", "h2"}; diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.cc b/src/core/ext/transport/chttp2/client/chttp2_connector.cc index db5962e7fd..7eb9ebc27e 100644 --- a/src/core/ext/transport/chttp2/client/chttp2_connector.cc +++ b/src/core/ext/transport/chttp2/client/chttp2_connector.cc @@ -57,12 +57,12 @@ typedef struct { } chttp2_connector; static void chttp2_connector_ref(grpc_connector* con) { - chttp2_connector* c = (chttp2_connector*)con; + chttp2_connector* c = reinterpret_cast<chttp2_connector*>(con); gpr_ref(&c->refs); } static void chttp2_connector_unref(grpc_connector* con) { - chttp2_connector* c = (chttp2_connector*)con; + chttp2_connector* c = reinterpret_cast<chttp2_connector*>(con); if (gpr_unref(&c->refs)) { gpr_mu_destroy(&c->mu); // If handshaking is not yet in progress, destroy the endpoint. @@ -73,7 +73,7 @@ static void chttp2_connector_unref(grpc_connector* con) { } static void chttp2_connector_shutdown(grpc_connector* con, grpc_error* why) { - chttp2_connector* c = (chttp2_connector*)con; + chttp2_connector* c = reinterpret_cast<chttp2_connector*>(con); gpr_mu_lock(&c->mu); c->shutdown = true; if (c->handshake_mgr != nullptr) { @@ -89,8 +89,8 @@ static void chttp2_connector_shutdown(grpc_connector* con, grpc_error* why) { } static void on_handshake_done(void* arg, grpc_error* error) { - grpc_handshaker_args* args = (grpc_handshaker_args*)arg; - chttp2_connector* c = (chttp2_connector*)args->user_data; + grpc_handshaker_args* args = static_cast<grpc_handshaker_args*>(arg); + chttp2_connector* c = static_cast<chttp2_connector*>(args->user_data); gpr_mu_lock(&c->mu); if (error != GRPC_ERROR_NONE || c->shutdown) { if (error == GRPC_ERROR_NONE) { @@ -150,7 +150,7 @@ static void on_handshake_done(void* arg, grpc_error* error) { grpc_handshake_manager_destroy(c->handshake_mgr); c->handshake_mgr = nullptr; gpr_mu_unlock(&c->mu); - chttp2_connector_unref((grpc_connector*)c); + chttp2_connector_unref(reinterpret_cast<grpc_connector*>(c)); } static void start_handshake_locked(chttp2_connector* c) { @@ -166,7 +166,7 @@ static void start_handshake_locked(chttp2_connector* c) { } static void connected(void* arg, grpc_error* error) { - chttp2_connector* c = (chttp2_connector*)arg; + chttp2_connector* c = static_cast<chttp2_connector*>(arg); gpr_mu_lock(&c->mu); GPR_ASSERT(c->connecting); c->connecting = false; @@ -184,7 +184,7 @@ static void connected(void* arg, grpc_error* error) { grpc_endpoint_shutdown(c->endpoint, GRPC_ERROR_REF(error)); } gpr_mu_unlock(&c->mu); - chttp2_connector_unref((grpc_connector*)arg); + chttp2_connector_unref(static_cast<grpc_connector*>(arg)); } else { GPR_ASSERT(c->endpoint != nullptr); start_handshake_locked(c); @@ -196,7 +196,7 @@ static void chttp2_connector_connect(grpc_connector* con, const grpc_connect_in_args* args, grpc_connect_out_args* result, grpc_closure* notify) { - chttp2_connector* c = (chttp2_connector*)con; + chttp2_connector* c = reinterpret_cast<chttp2_connector*>(con); grpc_resolved_address addr; grpc_get_subchannel_address_arg(args->channel_args, &addr); gpr_mu_lock(&c->mu); @@ -219,7 +219,7 @@ static const grpc_connector_vtable chttp2_connector_vtable = { chttp2_connector_connect}; grpc_connector* grpc_chttp2_connector_create() { - chttp2_connector* c = (chttp2_connector*)gpr_zalloc(sizeof(*c)); + chttp2_connector* c = static_cast<chttp2_connector*>(gpr_zalloc(sizeof(*c))); c->base.vtable = &chttp2_connector_vtable; gpr_mu_init(&c->mu); gpr_ref_init(&c->refs, 1); diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index 6a1b70964d..ef1d3fb53b 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -52,13 +52,13 @@ static grpc_channel* client_channel_factory_create_channel( return nullptr; } // Add channel arg containing the server URI. - grpc_arg arg = grpc_channel_arg_string_create( - (char*)GRPC_ARG_SERVER_URI, - grpc_resolver_factory_add_default_prefix_if_needed(target)); + grpc_core::UniquePtr<char> canonical_target = + grpc_core::ResolverRegistry::AddDefaultPrefixIfNeeded(target); + grpc_arg arg = grpc_channel_arg_string_create((char*)GRPC_ARG_SERVER_URI, + canonical_target.get()); const char* to_remove[] = {GRPC_ARG_SERVER_URI}; grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1); - gpr_free(arg.value.string); grpc_channel* channel = grpc_channel_create(target, new_args, GRPC_CLIENT_CHANNEL, nullptr); grpc_channel_args_destroy(new_args); diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index 27c5b96a4c..8c4025ed13 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -86,8 +86,8 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( if (target_uri->path[0] != '\0') { // "path" may be empty const grpc_slice key = grpc_slice_from_static_string( target_uri->path[0] == '/' ? target_uri->path + 1 : target_uri->path); - const char* value = - (const char*)grpc_slice_hash_table_get(targets_info, key); + const char* value = static_cast<const char*>( + grpc_slice_hash_table_get(targets_info, key)); if (value != nullptr) target_name_to_check = gpr_strdup(value); grpc_slice_unref_internal(key); } @@ -129,7 +129,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( grpc_channel_args_destroy(new_args_from_connector); } grpc_subchannel_args* final_sc_args = - (grpc_subchannel_args*)gpr_malloc(sizeof(*final_sc_args)); + static_cast<grpc_subchannel_args*>(gpr_malloc(sizeof(*final_sc_args))); memcpy(final_sc_args, args, sizeof(*args)); final_sc_args->args = new_args; return final_sc_args; @@ -148,7 +148,8 @@ static grpc_subchannel* client_channel_factory_create_subchannel( grpc_connector* connector = grpc_chttp2_connector_create(); grpc_subchannel* s = grpc_subchannel_create(connector, subchannel_args); grpc_connector_unref(connector); - grpc_channel_args_destroy((grpc_channel_args*)subchannel_args->args); + grpc_channel_args_destroy( + const_cast<grpc_channel_args*>(subchannel_args->args)); gpr_free(subchannel_args); return s; } @@ -161,13 +162,13 @@ static grpc_channel* client_channel_factory_create_channel( return nullptr; } // Add channel arg containing the server URI. - grpc_arg arg = grpc_channel_arg_string_create( - (char*)GRPC_ARG_SERVER_URI, - grpc_resolver_factory_add_default_prefix_if_needed(target)); + grpc_core::UniquePtr<char> canonical_target = + grpc_core::ResolverRegistry::AddDefaultPrefixIfNeeded(target); + grpc_arg arg = grpc_channel_arg_string_create((char*)GRPC_ARG_SERVER_URI, + canonical_target.get()); const char* to_remove[] = {GRPC_ARG_SERVER_URI}; grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1); - gpr_free(arg.value.string); grpc_channel* channel = grpc_channel_create(target, new_args, GRPC_CLIENT_CHANNEL, nullptr); grpc_channel_args_destroy(new_args); diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index 5669fa4090..90b2ee1af9 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -28,7 +28,6 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include <grpc/support/sync.h> -#include <grpc/support/useful.h> #include "src/core/ext/filters/http/server/http_server_filter.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" @@ -80,7 +79,8 @@ static void server_connection_state_unref( } static void on_timeout(void* arg, grpc_error* error) { - server_connection_state* connection_state = (server_connection_state*)arg; + server_connection_state* connection_state = + static_cast<server_connection_state*>(arg); // Note that we may be called with GRPC_ERROR_NONE when the timer fires // or with an error indicating that the timer system is being shut down. if (error != GRPC_ERROR_CANCELLED) { @@ -93,7 +93,8 @@ static void on_timeout(void* arg, grpc_error* error) { } static void on_receive_settings(void* arg, grpc_error* error) { - server_connection_state* connection_state = (server_connection_state*)arg; + server_connection_state* connection_state = + static_cast<server_connection_state*>(arg); if (error == GRPC_ERROR_NONE) { grpc_timer_cancel(&connection_state->timer); } @@ -101,9 +102,9 @@ static void on_receive_settings(void* arg, grpc_error* error) { } static void on_handshake_done(void* arg, grpc_error* error) { - grpc_handshaker_args* args = (grpc_handshaker_args*)arg; + grpc_handshaker_args* args = static_cast<grpc_handshaker_args*>(arg); server_connection_state* connection_state = - (server_connection_state*)args->user_data; + static_cast<server_connection_state*>(args->user_data); gpr_mu_lock(&connection_state->svr_state->mu); if (error != GRPC_ERROR_NONE || connection_state->svr_state->shutdown) { const char* error_str = grpc_error_string(error); @@ -133,7 +134,8 @@ static void on_handshake_done(void* arg, grpc_error* error) { connection_state->accepting_pollset, args->args); // Use notify_on_receive_settings callback to enforce the // handshake deadline. - connection_state->transport = (grpc_chttp2_transport*)transport; + connection_state->transport = + reinterpret_cast<grpc_chttp2_transport*>(transport); gpr_ref(&connection_state->refs); GRPC_CLOSURE_INIT(&connection_state->on_receive_settings, on_receive_settings, connection_state, @@ -163,7 +165,7 @@ static void on_handshake_done(void* arg, grpc_error* error) { static void on_accept(void* arg, grpc_endpoint* tcp, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor) { - server_state* state = (server_state*)arg; + server_state* state = static_cast<server_state*>(arg); gpr_mu_lock(&state->mu); if (state->shutdown) { gpr_mu_unlock(&state->mu); @@ -178,7 +180,8 @@ static void on_accept(void* arg, grpc_endpoint* tcp, gpr_mu_unlock(&state->mu); grpc_tcp_server_ref(state->tcp_server); server_connection_state* connection_state = - (server_connection_state*)gpr_zalloc(sizeof(*connection_state)); + static_cast<server_connection_state*>( + gpr_zalloc(sizeof(*connection_state))); gpr_ref_init(&connection_state->refs, 1); connection_state->svr_state = state; connection_state->accepting_pollset = accepting_pollset; @@ -202,7 +205,7 @@ static void on_accept(void* arg, grpc_endpoint* tcp, static void server_start_listener(grpc_server* server, void* arg, grpc_pollset** pollsets, size_t pollset_count) { - server_state* state = (server_state*)arg; + server_state* state = static_cast<server_state*>(arg); gpr_mu_lock(&state->mu); state->shutdown = false; gpr_mu_unlock(&state->mu); @@ -211,7 +214,7 @@ static void server_start_listener(grpc_server* server, void* arg, } static void tcp_server_shutdown_complete(void* arg, grpc_error* error) { - server_state* state = (server_state*)arg; + server_state* state = static_cast<server_state*>(arg); /* ensure all threads have unlocked */ gpr_mu_lock(&state->mu); grpc_closure* destroy_done = state->server_destroy_listener_done; @@ -235,7 +238,7 @@ static void tcp_server_shutdown_complete(void* arg, grpc_error* error) { callbacks) */ static void server_destroy_listener(grpc_server* server, void* arg, grpc_closure* destroy_done) { - server_state* state = (server_state*)arg; + server_state* state = static_cast<server_state*>(arg); gpr_mu_lock(&state->mu); state->shutdown = true; state->server_destroy_listener_done = destroy_done; @@ -265,7 +268,7 @@ grpc_error* grpc_chttp2_server_add_port(grpc_server* server, const char* addr, if (err != GRPC_ERROR_NONE) { goto error; } - state = (server_state*)gpr_zalloc(sizeof(*state)); + state = static_cast<server_state*>(gpr_zalloc(sizeof(*state))); GRPC_CLOSURE_INIT(&state->tcp_server_shutdown_complete, tcp_server_shutdown_complete, state, grpc_schedule_on_exec_ctx); @@ -282,7 +285,7 @@ grpc_error* grpc_chttp2_server_add_port(grpc_server* server, const char* addr, gpr_mu_init(&state->mu); naddrs = resolved->naddrs; - errors = (grpc_error**)gpr_malloc(sizeof(*errors) * naddrs); + errors = static_cast<grpc_error**>(gpr_malloc(sizeof(*errors) * naddrs)); for (i = 0; i < naddrs; i++) { errors[i] = grpc_tcp_server_add_port(tcp_server, &resolved->addrs[i], &port_temp); diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.cc b/src/core/ext/transport/chttp2/transport/bin_decoder.cc index 74778ac046..91980e6974 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.cc @@ -57,7 +57,7 @@ static bool input_is_valid(uint8_t* input_ptr, size_t length) { gpr_log(GPR_ERROR, "Base64 decoding failed, invalid character '%c' in base64 " "input.\n", - (char)(*input_ptr)); + static_cast<char>(*input_ptr)); return false; } } @@ -94,7 +94,7 @@ bool grpc_base64_decode_partial(struct grpc_base64_decode_context* ctx) { } // Process the tail of input data - input_tail = (size_t)(ctx->input_end - ctx->input_cur); + input_tail = static_cast<size_t>(ctx->input_end - ctx->input_cur); if (input_tail == 4) { // Process the input data with pad chars if (ctx->input_cur[3] == '=') { @@ -141,7 +141,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_slice input) { "Base64 decoding failed, input of " "grpc_chttp2_base64_decode has a length of %d, which is not a " "multiple of 4.\n", - (int)input_length); + static_cast<int>(input_length)); return grpc_empty_slice(); } @@ -186,17 +186,18 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, "Base64 decoding failed, input of " "grpc_chttp2_base64_decode_with_length has a length of %d, which " "has a tail of 1 byte.\n", - (int)input_length); + static_cast<int>(input_length)); grpc_slice_unref_internal(output); return grpc_empty_slice(); } if (output_length > input_length / 4 * 3 + tail_xtra[input_length % 4]) { - gpr_log(GPR_ERROR, - "Base64 decoding failed, output_length %d is longer " - "than the max possible output length %d.\n", - (int)output_length, - (int)(input_length / 4 * 3 + tail_xtra[input_length % 4])); + gpr_log( + GPR_ERROR, + "Base64 decoding failed, output_length %d is longer " + "than the max possible output length %d.\n", + static_cast<int>(output_length), + static_cast<int>(input_length / 4 * 3 + tail_xtra[input_length % 4])); grpc_slice_unref_internal(output); return grpc_empty_slice(); } diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.cc b/src/core/ext/transport/chttp2/transport/bin_encoder.cc index 09f984d7b2..e3b8adbe73 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.cc @@ -53,7 +53,7 @@ grpc_slice grpc_chttp2_base64_encode(grpc_slice input) { size_t output_length = input_triplets * 4 + tail_xtra[tail_case]; grpc_slice output = GRPC_SLICE_MALLOC(output_length); uint8_t* in = GRPC_SLICE_START_PTR(input); - char* out = (char*)GRPC_SLICE_START_PTR(output); + char* out = reinterpret_cast<char*> GRPC_SLICE_START_PTR(output); size_t i; /* encode full triplets */ @@ -115,7 +115,7 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input) { while (temp_length > 8) { temp_length -= 8; - *out++ = (uint8_t)(temp >> temp_length); + *out++ = static_cast<uint8_t>(temp >> temp_length); } } @@ -124,8 +124,9 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input) { * expanded form due to the "integral promotion" performed (see section * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type * is then required to avoid the compiler warning */ - *out++ = (uint8_t)((uint8_t)(temp << (8u - temp_length)) | - (uint8_t)(0xffu >> temp_length)); + *out++ = + static_cast<uint8_t>(static_cast<uint8_t>(temp << (8u - temp_length)) | + static_cast<uint8_t>(0xffu >> temp_length)); } GPR_ASSERT(out == GRPC_SLICE_END_PTR(output)); @@ -142,7 +143,7 @@ typedef struct { static void enc_flush_some(huff_out* out) { while (out->temp_length > 8) { out->temp_length -= 8; - *out->out++ = (uint8_t)(out->temp >> out->temp_length); + *out->out++ = static_cast<uint8_t>(out->temp >> out->temp_length); } } @@ -150,8 +151,9 @@ static void enc_add2(huff_out* out, uint8_t a, uint8_t b) { b64_huff_sym sa = huff_alphabet[a]; b64_huff_sym sb = huff_alphabet[b]; out->temp = (out->temp << (sa.length + sb.length)) | - ((uint32_t)sa.bits << sb.length) | sb.bits; - out->temp_length += (uint32_t)sa.length + (uint32_t)sb.length; + (static_cast<uint32_t>(sa.bits) << sb.length) | sb.bits; + out->temp_length += + static_cast<uint32_t>(sa.length) + static_cast<uint32_t>(sb.length); enc_flush_some(out); } @@ -181,11 +183,11 @@ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) { /* encode full triplets */ for (i = 0; i < input_triplets; i++) { - const uint8_t low_to_high = (uint8_t)((in[0] & 0x3) << 4); + const uint8_t low_to_high = static_cast<uint8_t>((in[0] & 0x3) << 4); const uint8_t high_to_low = in[1] >> 4; enc_add2(&out, in[0] >> 2, low_to_high | high_to_low); - const uint8_t a = (uint8_t)((in[1] & 0xf) << 2); + const uint8_t a = static_cast<uint8_t>((in[1] & 0xf) << 2); const uint8_t b = (in[2] >> 6); enc_add2(&out, a | b, in[2] & 0x3f); in += 3; @@ -196,14 +198,14 @@ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) { case 0: break; case 1: - enc_add2(&out, in[0] >> 2, (uint8_t)((in[0] & 0x3) << 4)); + enc_add2(&out, in[0] >> 2, static_cast<uint8_t>((in[0] & 0x3) << 4)); in += 1; break; case 2: { - const uint8_t low_to_high = (uint8_t)((in[0] & 0x3) << 4); + const uint8_t low_to_high = static_cast<uint8_t>((in[0] & 0x3) << 4); const uint8_t high_to_low = in[1] >> 4; enc_add2(&out, in[0] >> 2, low_to_high | high_to_low); - enc_add1(&out, (uint8_t)((in[1] & 0xf) << 2)); + enc_add1(&out, static_cast<uint8_t>((in[1] & 0xf) << 2)); in += 2; break; } @@ -214,8 +216,9 @@ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) { * expanded form due to the "integral promotion" performed (see section * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type * is then required to avoid the compiler warning */ - *out.out++ = (uint8_t)((uint8_t)(out.temp << (8u - out.temp_length)) | - (uint8_t)(0xffu >> out.temp_length)); + *out.out++ = static_cast<uint8_t>( + static_cast<uint8_t>(out.temp << (8u - out.temp_length)) | + static_cast<uint8_t>(0xffu >> out.temp_length)); } GPR_ASSERT(out.out <= GRPC_SLICE_END_PTR(output)); diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 530ab17bc7..ad8da94cb3 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -30,7 +30,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/frame_data.h" #include "src/core/ext/transport/chttp2/transport/internal.h" @@ -379,7 +378,7 @@ static void init_transport(grpc_chttp2_transport* t, GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER, t->next_stream_id & 1, is_client ? "client" : "server"); } else { - t->next_stream_id = (uint32_t)value; + t->next_stream_id = static_cast<uint32_t>(value); } } } else if (0 == strcmp(channel_args->args[i].key, @@ -388,8 +387,8 @@ static void init_transport(grpc_chttp2_transport* t, const int value = grpc_channel_arg_get_integer(&channel_args->args[i], options); if (value >= 0) { - grpc_chttp2_hpack_compressor_set_max_usable_size(&t->hpack_compressor, - (uint32_t)value); + grpc_chttp2_hpack_compressor_set_max_usable_size( + &t->hpack_compressor, static_cast<uint32_t>(value)); } } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA)) { @@ -422,8 +421,9 @@ static void init_transport(grpc_chttp2_transport* t, INT_MAX}); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)) { - t->write_buffer_size = (uint32_t)grpc_channel_arg_get_integer( - &channel_args->args[i], {0, 0, MAX_WRITE_BUFFER_SIZE}); + t->write_buffer_size = + static_cast<uint32_t>(grpc_channel_arg_get_integer( + &channel_args->args[i], {0, 0, MAX_WRITE_BUFFER_SIZE})); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_BDP_PROBE)) { enable_bdp = grpc_channel_arg_get_bool(&channel_args->args[i], true); @@ -448,9 +448,8 @@ static void init_transport(grpc_chttp2_transport* t, value == INT_MAX ? GRPC_MILLIS_INF_FUTURE : value; } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)) { - t->keepalive_permit_without_calls = - (uint32_t)grpc_channel_arg_get_integer(&channel_args->args[i], - {0, 0, 1}); + t->keepalive_permit_without_calls = static_cast<uint32_t>( + grpc_channel_arg_get_integer(&channel_args->args[i], {0, 0, 1})); } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_OPTIMIZATION_TARGET)) { if (channel_args->args[i].type != GRPC_ARG_STRING) { @@ -499,7 +498,7 @@ static void init_transport(grpc_chttp2_transport* t, GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, {-1, 5, INT32_MAX}, {true, true}}}; - for (j = 0; j < (int)GPR_ARRAY_SIZE(settings_map); j++) { + for (j = 0; j < static_cast<int> GPR_ARRAY_SIZE(settings_map); j++) { if (0 == strcmp(channel_args->args[i].key, settings_map[j].channel_arg_name)) { if (!settings_map[j].availability[is_client]) { @@ -511,7 +510,7 @@ static void init_transport(grpc_chttp2_transport* t, &channel_args->args[i], settings_map[j].integer_options); if (value >= 0) { queue_setting_update(t, settings_map[j].setting_id, - (uint32_t)value); + static_cast<uint32_t>(value)); } } break; @@ -563,7 +562,7 @@ static void init_transport(grpc_chttp2_transport* t, } static void destroy_transport_locked(void* tp, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); t->destroying = 1; close_transport_locked( t, grpc_error_set_int( @@ -573,7 +572,7 @@ static void destroy_transport_locked(void* tp, grpc_error* error) { } static void destroy_transport(grpc_transport* gt) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt); GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(destroy_transport_locked, t, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); @@ -656,9 +655,9 @@ void grpc_chttp2_stream_unref(grpc_chttp2_stream* s) { static int init_stream(grpc_transport* gt, grpc_stream* gs, grpc_stream_refcount* refcount, const void* server_data, gpr_arena* arena) { - GPR_TIMER_BEGIN("init_stream", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; + GPR_TIMER_SCOPE("init_stream", 0); + grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt); + grpc_chttp2_stream* s = reinterpret_cast<grpc_chttp2_stream*>(gs); s->t = t; s->refcount = refcount; @@ -686,7 +685,7 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, GRPC_CHTTP2_REF_TRANSPORT(t, "stream"); if (server_data) { - s->id = (uint32_t)(uintptr_t)server_data; + s->id = static_cast<uint32_t>((uintptr_t)server_data); *t->accepting_stream = s; grpc_chttp2_stream_map_add(&t->stream_map, s->id, s); post_destructive_reclaimer(t); @@ -700,17 +699,15 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, } else { s->flow_control.Init<grpc_core::chttp2::StreamFlowControlDisabled>(); } - GPR_TIMER_END("init_stream", 0); return 0; } static void destroy_stream_locked(void* sp, grpc_error* error) { - grpc_chttp2_stream* s = (grpc_chttp2_stream*)sp; + GPR_TIMER_SCOPE("destroy_stream", 0); + grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(sp); grpc_chttp2_transport* t = s->t; - GPR_TIMER_BEGIN("destroy_stream", 0); - GPR_ASSERT((s->write_closed && s->read_closed) || s->id == 0); if (s->id != 0) { GPR_ASSERT(grpc_chttp2_stream_map_find(&t->stream_map, s->id) == nullptr); @@ -750,16 +747,14 @@ static void destroy_stream_locked(void* sp, grpc_error* error) { GRPC_CHTTP2_UNREF_TRANSPORT(t, "stream"); - GPR_TIMER_END("destroy_stream", 0); - GRPC_CLOSURE_SCHED(s->destroy_stream_arg, GRPC_ERROR_NONE); } static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_closure* then_schedule_closure) { - GPR_TIMER_BEGIN("destroy_stream", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; + GPR_TIMER_SCOPE("destroy_stream", 0); + grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt); + grpc_chttp2_stream* s = reinterpret_cast<grpc_chttp2_stream*>(gs); if (s->stream_compression_ctx != nullptr) { grpc_stream_compression_context_destroy(s->stream_compression_ctx); @@ -775,12 +770,12 @@ static void destroy_stream(grpc_transport* gt, grpc_stream* gs, GRPC_CLOSURE_INIT(&s->destroy_stream, destroy_stream_locked, s, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); - GPR_TIMER_END("destroy_stream", 0); } grpc_chttp2_stream* grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport* t, uint32_t id) { - return (grpc_chttp2_stream*)grpc_chttp2_stream_map_find(&t->stream_map, id); + return static_cast<grpc_chttp2_stream*>( + grpc_chttp2_stream_map_find(&t->stream_map, id)); } grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, @@ -792,7 +787,8 @@ grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, GPR_ASSERT(t->accepting_stream == nullptr); t->accepting_stream = &accepting; t->channel_callback.accept_stream(t->channel_callback.accept_stream_user_data, - &t->base, (void*)(uintptr_t)id); + &t->base, + (void*)static_cast<uintptr_t>(id)); t->accepting_stream = nullptr; return accepting; } @@ -898,7 +894,7 @@ static void inc_initiate_write_reason( void grpc_chttp2_initiate_write(grpc_chttp2_transport* t, grpc_chttp2_initiate_write_reason reason) { - GPR_TIMER_BEGIN("grpc_chttp2_initiate_write", 0); + GPR_TIMER_SCOPE("grpc_chttp2_initiate_write", 0); switch (t->write_state) { case GRPC_CHTTP2_WRITE_STATE_IDLE: @@ -920,7 +916,6 @@ void grpc_chttp2_initiate_write(grpc_chttp2_transport* t, case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE: break; } - GPR_TIMER_END("grpc_chttp2_initiate_write", 0); } void grpc_chttp2_mark_stream_writable(grpc_chttp2_transport* t, @@ -974,8 +969,8 @@ static const char* begin_writing_desc(bool partial, bool inlined) { } static void write_action_begin_locked(void* gt, grpc_error* error_ignored) { - GPR_TIMER_BEGIN("write_action_begin_locked", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + GPR_TIMER_SCOPE("write_action_begin_locked", 0); + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(gt); GPR_ASSERT(t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE); grpc_chttp2_begin_write_result r; if (t->closed_with_error != GRPC_ERROR_NONE) { @@ -1008,22 +1003,20 @@ static void write_action_begin_locked(void* gt, grpc_error* error_ignored) { set_write_state(t, GRPC_CHTTP2_WRITE_STATE_IDLE, "begin writing nothing"); GRPC_CHTTP2_UNREF_TRANSPORT(t, "writing"); } - GPR_TIMER_END("write_action_begin_locked", 0); } static void write_action(void* gt, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - GPR_TIMER_BEGIN("write_action", 0); + GPR_TIMER_SCOPE("write_action", 0); + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(gt); grpc_endpoint_write( t->ep, &t->outbuf, GRPC_CLOSURE_INIT(&t->write_action_end_locked, write_action_end_locked, t, grpc_combiner_scheduler(t->combiner))); - GPR_TIMER_END("write_action", 0); } static void write_action_end_locked(void* tp, grpc_error* error) { - GPR_TIMER_BEGIN("terminate_writing_with_lock", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + GPR_TIMER_SCOPE("terminate_writing_with_lock", 0); + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); if (error != GRPC_ERROR_NONE) { close_transport_locked(t, GRPC_ERROR_REF(error)); @@ -1060,7 +1053,6 @@ static void write_action_end_locked(void* tp, grpc_error* error) { grpc_chttp2_end_write(t, GRPC_ERROR_REF(error)); GRPC_CHTTP2_UNREF_TRANSPORT(t, "writing"); - GPR_TIMER_END("terminate_writing_with_lock", 0); } // Dirties an HTTP2 setting to be sent out next time a writing path occurs. @@ -1093,7 +1085,7 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, t->goaway_error = grpc_error_set_str( grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("GOAWAY received"), - GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)goaway_error), + GRPC_ERROR_INT_HTTP2_ERROR, static_cast<intptr_t>(goaway_error)), GRPC_ERROR_STR_RAW_BYTES, goaway_text); /* When a client receives a GOAWAY with error code ENHANCE_YOUR_CALM and debug @@ -1105,12 +1097,12 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, gpr_log(GPR_ERROR, "Received a GOAWAY with error code ENHANCE_YOUR_CALM and debug " "data equal to \"too_many_pings\""); - double current_keepalive_time_ms = (double)t->keepalive_time; + double current_keepalive_time_ms = static_cast<double>(t->keepalive_time); t->keepalive_time = current_keepalive_time_ms > INT_MAX / KEEPALIVE_TIME_BACKOFF_MULTIPLIER ? GRPC_MILLIS_INF_FUTURE - : (grpc_millis)(current_keepalive_time_ms * - KEEPALIVE_TIME_BACKOFF_MULTIPLIER); + : static_cast<grpc_millis>(current_keepalive_time_ms * + KEEPALIVE_TIME_BACKOFF_MULTIPLIER); } /* lie: use transient failure from the transport to indicate goaway has been @@ -1199,9 +1191,11 @@ void grpc_chttp2_complete_closure_step(grpc_chttp2_transport* t, "complete_closure_step: t=%p %p refs=%d flags=0x%04x desc=%s err=%s " "write_state=%s", t, closure, - (int)(closure->next_data.scratch / CLOSURE_BARRIER_FIRST_REF_BIT), - (int)(closure->next_data.scratch % CLOSURE_BARRIER_FIRST_REF_BIT), desc, - errstr, write_state_name(t->write_state)); + static_cast<int>(closure->next_data.scratch / + CLOSURE_BARRIER_FIRST_REF_BIT), + static_cast<int>(closure->next_data.scratch % + CLOSURE_BARRIER_FIRST_REF_BIT), + desc, errstr, write_state_name(t->write_state)); } if (error != GRPC_ERROR_NONE) { if (closure->error_data.error == GRPC_ERROR_NONE) { @@ -1249,7 +1243,7 @@ static void maybe_become_writable_due_to_send_msg(grpc_chttp2_transport* t, static void add_fetched_slice_locked(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { s->fetched_send_message_length += - (uint32_t)GRPC_SLICE_LENGTH(s->fetching_slice); + static_cast<uint32_t> GRPC_SLICE_LENGTH(s->fetching_slice); grpc_slice_buffer_add(&s->flow_controlled_buffer, s->fetching_slice); maybe_become_writable_due_to_send_msg(t, s); } @@ -1272,7 +1266,7 @@ static void continue_fetching_send_locked(grpc_chttp2_transport* t, } else { grpc_chttp2_write_cb* cb = t->write_cb_pool; if (cb == nullptr) { - cb = (grpc_chttp2_write_cb*)gpr_malloc(sizeof(*cb)); + cb = static_cast<grpc_chttp2_write_cb*>(gpr_malloc(sizeof(*cb))); } else { t->write_cb_pool = cb->next; } @@ -1303,7 +1297,7 @@ static void continue_fetching_send_locked(grpc_chttp2_transport* t, } static void complete_fetch_locked(void* gs, grpc_error* error) { - grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; + grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(gs); grpc_chttp2_transport* t = s->t; if (error == GRPC_ERROR_NONE) { error = grpc_byte_stream_pull(s->fetching_send_message, &s->fetching_slice); @@ -1335,11 +1329,12 @@ static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id, static void perform_stream_op_locked(void* stream_op, grpc_error* error_ignored) { - GPR_TIMER_BEGIN("perform_stream_op_locked", 0); + GPR_TIMER_SCOPE("perform_stream_op_locked", 0); grpc_transport_stream_op_batch* op = - (grpc_transport_stream_op_batch*)stream_op; - grpc_chttp2_stream* s = (grpc_chttp2_stream*)op->handler_private.extra_arg; + static_cast<grpc_transport_stream_op_batch*>(stream_op); + grpc_chttp2_stream* s = + static_cast<grpc_chttp2_stream*>(op->handler_private.extra_arg); grpc_transport_stream_op_batch_payload* op_payload = op->payload; grpc_chttp2_transport* t = s->t; @@ -1418,8 +1413,9 @@ static void perform_stream_op_locked(void* stream_op, "to-be-sent initial metadata size " "exceeds peer limit"), GRPC_ERROR_INT_SIZE, - (intptr_t)metadata_size), - GRPC_ERROR_INT_LIMIT, (intptr_t)metadata_peer_limit), + static_cast<intptr_t>(metadata_size)), + GRPC_ERROR_INT_LIMIT, + static_cast<intptr_t>(metadata_peer_limit)), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); } else { if (contains_non_ok_status(s->send_initial_metadata)) { @@ -1492,15 +1488,16 @@ static void perform_stream_op_locked(void* stream_op, uint32_t flags = op_payload->send_message.send_message->flags; frame_hdr[0] = (flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0; size_t len = op_payload->send_message.send_message->length; - frame_hdr[1] = (uint8_t)(len >> 24); - frame_hdr[2] = (uint8_t)(len >> 16); - frame_hdr[3] = (uint8_t)(len >> 8); - frame_hdr[4] = (uint8_t)(len); + frame_hdr[1] = static_cast<uint8_t>(len >> 24); + frame_hdr[2] = static_cast<uint8_t>(len >> 16); + frame_hdr[3] = static_cast<uint8_t>(len >> 8); + frame_hdr[4] = static_cast<uint8_t>(len); s->fetching_send_message = op_payload->send_message.send_message; s->fetched_send_message_length = 0; - s->next_message_end_offset = s->flow_controlled_bytes_written + - (int64_t)s->flow_controlled_buffer.length + - (int64_t)len; + s->next_message_end_offset = + s->flow_controlled_bytes_written + + static_cast<int64_t>(s->flow_controlled_buffer.length) + + static_cast<int64_t>(len); if (flags & GRPC_WRITE_BUFFER_HINT) { s->next_message_end_offset -= t->write_buffer_size; s->write_buffering = true; @@ -1534,8 +1531,9 @@ static void perform_stream_op_locked(void* stream_op, "to-be-sent trailing metadata size " "exceeds peer limit"), GRPC_ERROR_INT_SIZE, - (intptr_t)metadata_size), - GRPC_ERROR_INT_LIMIT, (intptr_t)metadata_peer_limit), + static_cast<intptr_t>(metadata_size)), + GRPC_ERROR_INT_LIMIT, + static_cast<intptr_t>(metadata_peer_limit)), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); } else { if (contains_non_ok_status(s->send_trailing_metadata)) { @@ -1609,15 +1607,14 @@ static void perform_stream_op_locked(void* stream_op, grpc_chttp2_complete_closure_step(t, s, &on_complete, GRPC_ERROR_NONE, "op->on_complete"); - GPR_TIMER_END("perform_stream_op_locked", 0); GRPC_CHTTP2_STREAM_UNREF(s, "perform_stream_op"); } static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, grpc_transport_stream_op_batch* op) { - GPR_TIMER_BEGIN("perform_stream_op", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; - grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; + GPR_TIMER_SCOPE("perform_stream_op", 0); + grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt); + grpc_chttp2_stream* s = reinterpret_cast<grpc_chttp2_stream*>(gs); if (!t->is_client) { if (op->send_initial_metadata) { @@ -1644,7 +1641,6 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, GRPC_CLOSURE_INIT(&op->handler_private.closure, perform_stream_op_locked, op, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); - GPR_TIMER_END("perform_stream_op", 0); } static void cancel_pings(grpc_chttp2_transport* t, grpc_error* error) { @@ -1674,11 +1670,12 @@ static void send_ping_locked(grpc_chttp2_transport* t, } static void retry_initiate_ping_locked(void* tp, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); t->ping_state.is_delayed_ping_timer_set = false; if (error == GRPC_ERROR_NONE) { grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING); } + GRPC_CHTTP2_UNREF_TRANSPORT(t, "retry_initiate_ping_locked"); } void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id) { @@ -1701,7 +1698,8 @@ static void send_goaway(grpc_chttp2_transport* t, grpc_error* error) { grpc_slice slice; grpc_error_get_status(error, GRPC_MILLIS_INF_FUTURE, nullptr, &slice, &http_error, nullptr); - grpc_chttp2_goaway_append(t->last_new_stream_id, (uint32_t)http_error, + grpc_chttp2_goaway_append(t->last_new_stream_id, + static_cast<uint32_t>(http_error), grpc_slice_ref_internal(slice), &t->qbuf); grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_GOAWAY_SENT); GRPC_ERROR_UNREF(error); @@ -1725,9 +1723,9 @@ void grpc_chttp2_add_ping_strike(grpc_chttp2_transport* t) { static void perform_transport_op_locked(void* stream_op, grpc_error* error_ignored) { - grpc_transport_op* op = (grpc_transport_op*)stream_op; + grpc_transport_op* op = static_cast<grpc_transport_op*>(stream_op); grpc_chttp2_transport* t = - (grpc_chttp2_transport*)op->handler_private.extra_arg; + static_cast<grpc_chttp2_transport*>(op->handler_private.extra_arg); if (op->goaway_error) { send_goaway(t, op->goaway_error); @@ -1768,7 +1766,7 @@ static void perform_transport_op_locked(void* stream_op, } static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt); char* msg = grpc_transport_op_string(op); gpr_free(msg); op->handler_private.extra_arg = gt; @@ -1936,8 +1934,8 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, static void remove_stream(grpc_chttp2_transport* t, uint32_t id, grpc_error* error) { - grpc_chttp2_stream* s = - (grpc_chttp2_stream*)grpc_chttp2_stream_map_delete(&t->stream_map, id); + grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>( + grpc_chttp2_stream_map_delete(&t->stream_map, id)); GPR_ASSERT(s); if (t->incoming_stream == s) { t->incoming_stream = nullptr; @@ -1989,8 +1987,9 @@ void grpc_chttp2_cancel_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error_get_status(due_to_error, s->deadline, nullptr, nullptr, &http_error, nullptr); grpc_slice_buffer_add( - &t->qbuf, grpc_chttp2_rst_stream_create(s->id, (uint32_t)http_error, - &s->stats.outgoing)); + &t->qbuf, + grpc_chttp2_rst_stream_create( + s->id, static_cast<uint32_t>(http_error), &s->stats.outgoing)); grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RST_STREAM); } } @@ -2191,7 +2190,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = '0'; *p++ = '0'; GPR_ASSERT(p == GRPC_SLICE_END_PTR(http_status_hdr)); - len += (uint32_t)GRPC_SLICE_LENGTH(http_status_hdr); + len += static_cast<uint32_t> GRPC_SLICE_LENGTH(http_status_hdr); content_type_hdr = GRPC_SLICE_MALLOC(31); p = GRPC_SLICE_START_PTR(content_type_hdr); @@ -2227,7 +2226,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = 'p'; *p++ = 'c'; GPR_ASSERT(p == GRPC_SLICE_END_PTR(content_type_hdr)); - len += (uint32_t)GRPC_SLICE_LENGTH(content_type_hdr); + len += static_cast<uint32_t> GRPC_SLICE_LENGTH(content_type_hdr); } status_hdr = GRPC_SLICE_MALLOC(15 + (grpc_status >= 10)); @@ -2247,14 +2246,14 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = 's'; if (grpc_status < 10) { *p++ = 1; - *p++ = (uint8_t)('0' + grpc_status); + *p++ = static_cast<uint8_t>('0' + grpc_status); } else { *p++ = 2; - *p++ = (uint8_t)('0' + (grpc_status / 10)); - *p++ = (uint8_t)('0' + (grpc_status % 10)); + *p++ = static_cast<uint8_t>('0' + (grpc_status / 10)); + *p++ = static_cast<uint8_t>('0' + (grpc_status % 10)); } GPR_ASSERT(p == GRPC_SLICE_END_PTR(status_hdr)); - len += (uint32_t)GRPC_SLICE_LENGTH(status_hdr); + len += static_cast<uint32_t> GRPC_SLICE_LENGTH(status_hdr); size_t msg_len = GRPC_SLICE_LENGTH(slice); GPR_ASSERT(msg_len <= UINT32_MAX); @@ -2278,20 +2277,20 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, GRPC_CHTTP2_WRITE_VARINT((uint32_t)msg_len, 1, 0, p, (uint32_t)msg_len_len); p += msg_len_len; GPR_ASSERT(p == GRPC_SLICE_END_PTR(message_pfx)); - len += (uint32_t)GRPC_SLICE_LENGTH(message_pfx); - len += (uint32_t)msg_len; + len += static_cast<uint32_t> GRPC_SLICE_LENGTH(message_pfx); + len += static_cast<uint32_t>(msg_len); hdr = GRPC_SLICE_MALLOC(9); p = GRPC_SLICE_START_PTR(hdr); - *p++ = (uint8_t)(len >> 16); - *p++ = (uint8_t)(len >> 8); - *p++ = (uint8_t)(len); + *p++ = static_cast<uint8_t>(len >> 16); + *p++ = static_cast<uint8_t>(len >> 8); + *p++ = static_cast<uint8_t>(len); *p++ = GRPC_CHTTP2_FRAME_HEADER; *p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS; - *p++ = (uint8_t)(s->id >> 24); - *p++ = (uint8_t)(s->id >> 16); - *p++ = (uint8_t)(s->id >> 8); - *p++ = (uint8_t)(s->id); + *p++ = static_cast<uint8_t>(s->id >> 24); + *p++ = static_cast<uint8_t>(s->id >> 16); + *p++ = static_cast<uint8_t>(s->id >> 8); + *p++ = static_cast<uint8_t>(s->id); GPR_ASSERT(p == GRPC_SLICE_END_PTR(hdr)); grpc_slice_buffer_add(&t->qbuf, hdr); @@ -2316,8 +2315,8 @@ typedef struct { } cancel_stream_cb_args; static void cancel_stream_cb(void* user_data, uint32_t key, void* stream) { - cancel_stream_cb_args* args = (cancel_stream_cb_args*)user_data; - grpc_chttp2_stream* s = (grpc_chttp2_stream*)stream; + cancel_stream_cb_args* args = static_cast<cancel_stream_cb_args*>(user_data); + grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(stream); grpc_chttp2_cancel_stream(args->t, s, GRPC_ERROR_REF(args->error)); } @@ -2398,9 +2397,9 @@ static grpc_error* try_http_parsing(grpc_chttp2_transport* t) { } static void read_action_locked(void* tp, grpc_error* error) { - GPR_TIMER_BEGIN("reading_action_locked", 0); + GPR_TIMER_SCOPE("reading_action_locked", 0); - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); GRPC_ERROR_REF(error); @@ -2414,7 +2413,7 @@ static void read_action_locked(void* tp, grpc_error* error) { GPR_SWAP(grpc_error*, err, error); GRPC_ERROR_UNREF(err); if (t->closed_with_error == GRPC_ERROR_NONE) { - GPR_TIMER_BEGIN("reading_action.parse", 0); + GPR_TIMER_SCOPE("reading_action.parse", 0); size_t i = 0; grpc_error* errors[3] = {GRPC_ERROR_REF(error), GRPC_ERROR_NONE, GRPC_ERROR_NONE}; @@ -2422,7 +2421,7 @@ static void read_action_locked(void* tp, grpc_error* error) { grpc_core::BdpEstimator* bdp_est = t->flow_control->bdp_estimator(); if (bdp_est) { bdp_est->AddIncomingBytes( - (int64_t)GRPC_SLICE_LENGTH(t->read_buffer.slices[i])); + static_cast<int64_t> GRPC_SLICE_LENGTH(t->read_buffer.slices[i])); } errors[1] = grpc_chttp2_perform_read(t, t->read_buffer.slices[i]); } @@ -2435,9 +2434,8 @@ static void read_action_locked(void* tp, grpc_error* error) { for (i = 0; i < GPR_ARRAY_SIZE(errors); i++) { GRPC_ERROR_UNREF(errors[i]); } - GPR_TIMER_END("reading_action.parse", 0); - GPR_TIMER_BEGIN("post_parse_locked", 0); + GPR_TIMER_SCOPE("post_parse_locked", 0); if (t->initial_window_update != 0) { if (t->initial_window_update > 0) { grpc_chttp2_stream* s; @@ -2449,10 +2447,9 @@ static void read_action_locked(void* tp, grpc_error* error) { } t->initial_window_update = 0; } - GPR_TIMER_END("post_parse_locked", 0); } - GPR_TIMER_BEGIN("post_reading_action_locked", 0); + GPR_TIMER_SCOPE("post_reading_action_locked", 0); bool keep_reading = false; if (error == GRPC_ERROR_NONE && t->closed_with_error != GRPC_ERROR_NONE) { error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( @@ -2482,11 +2479,7 @@ static void read_action_locked(void* tp, grpc_error* error) { GRPC_CHTTP2_UNREF_TRANSPORT(t, "reading_action"); } - GPR_TIMER_END("post_reading_action_locked", 0); - GRPC_ERROR_UNREF(error); - - GPR_TIMER_END("reading_action_locked", 0); } // t is reffed prior to calling the first time, and once the callback chain @@ -2497,7 +2490,7 @@ static void schedule_bdp_ping_locked(grpc_chttp2_transport* t) { } static void start_bdp_ping_locked(void* tp, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); if (grpc_http_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Start BDP ping err=%s", t->peer_string, grpc_error_string(error)); @@ -2510,7 +2503,7 @@ static void start_bdp_ping_locked(void* tp, grpc_error* error) { } static void finish_bdp_ping_locked(void* tp, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); if (grpc_http_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Complete BDP ping err=%s", t->peer_string, grpc_error_string(error)); @@ -2529,7 +2522,7 @@ static void finish_bdp_ping_locked(void* tp, grpc_error* error) { } static void next_bdp_ping_timer_expired_locked(void* tp, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); GPR_ASSERT(t->have_next_bdp_ping_timer); t->have_next_bdp_ping_timer = false; if (error != GRPC_ERROR_NONE) { @@ -2567,11 +2560,11 @@ void grpc_chttp2_config_default_keepalive_args(grpc_channel_args* args, } } else if (0 == strcmp(args->args[i].key, GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)) { - const bool value = (uint32_t)grpc_channel_arg_get_integer( + const bool value = static_cast<uint32_t>(grpc_channel_arg_get_integer( &args->args[i], {is_client ? g_default_client_keepalive_permit_without_calls : g_default_server_keepalive_timeout_ms, - 0, 1}); + 0, 1})); if (is_client) { g_default_client_keepalive_permit_without_calls = value; } else { @@ -2607,7 +2600,7 @@ void grpc_chttp2_config_default_keepalive_args(grpc_channel_args* args, } static void init_keepalive_ping_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg); GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING); if (t->destroying || t->closed_with_error != GRPC_ERROR_NONE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; @@ -2636,7 +2629,7 @@ static void init_keepalive_ping_locked(void* arg, grpc_error* error) { } static void start_keepalive_ping_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg); GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog"); grpc_timer_init(&t->keepalive_watchdog_timer, grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, @@ -2644,7 +2637,7 @@ static void start_keepalive_ping_locked(void* arg, grpc_error* error) { } static void finish_keepalive_ping_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg); if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { if (error == GRPC_ERROR_NONE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; @@ -2659,7 +2652,7 @@ static void finish_keepalive_ping_locked(void* arg, grpc_error* error) { } static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg); if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { if (error == GRPC_ERROR_NONE) { t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; @@ -2699,13 +2692,13 @@ static void connectivity_state_set(grpc_chttp2_transport* t, static void set_pollset(grpc_transport* gt, grpc_stream* gs, grpc_pollset* pollset) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt); grpc_endpoint_add_to_pollset(t->ep, pollset); } static void set_pollset_set(grpc_transport* gt, grpc_stream* gs, grpc_pollset_set* pollset_set) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_transport* t = reinterpret_cast<grpc_chttp2_transport*>(gt); grpc_endpoint_add_to_pollset_set(t->ep, pollset_set); } @@ -2714,7 +2707,7 @@ static void set_pollset_set(grpc_transport* gt, grpc_stream* gs, */ static void reset_byte_stream(void* arg, grpc_error* error) { - grpc_chttp2_stream* s = (grpc_chttp2_stream*)arg; + grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(arg); s->pending_byte_stream = false; if (error == GRPC_ERROR_NONE) { @@ -2740,7 +2733,7 @@ static void incoming_byte_stream_unref(grpc_chttp2_incoming_byte_stream* bs) { static void incoming_byte_stream_next_locked(void* argp, grpc_error* error_ignored) { grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)argp; + static_cast<grpc_chttp2_incoming_byte_stream*>(argp); grpc_chttp2_transport* t = bs->transport; grpc_chttp2_stream* s = bs->stream; @@ -2786,12 +2779,11 @@ static void incoming_byte_stream_next_locked(void* argp, static bool incoming_byte_stream_next(grpc_byte_stream* byte_stream, size_t max_size_hint, grpc_closure* on_complete) { - GPR_TIMER_BEGIN("incoming_byte_stream_next", 0); + GPR_TIMER_SCOPE("incoming_byte_stream_next", 0); grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)byte_stream; + reinterpret_cast<grpc_chttp2_incoming_byte_stream*>(byte_stream); grpc_chttp2_stream* s = bs->stream; if (s->unprocessed_incoming_frames_buffer.length > 0) { - GPR_TIMER_END("incoming_byte_stream_next", 0); return true; } else { gpr_ref(&bs->refs); @@ -2802,16 +2794,15 @@ static bool incoming_byte_stream_next(grpc_byte_stream* byte_stream, incoming_byte_stream_next_locked, bs, grpc_combiner_scheduler(bs->transport->combiner)), GRPC_ERROR_NONE); - GPR_TIMER_END("incoming_byte_stream_next", 0); return false; } } static grpc_error* incoming_byte_stream_pull(grpc_byte_stream* byte_stream, grpc_slice* slice) { - GPR_TIMER_BEGIN("incoming_byte_stream_pull", 0); + GPR_TIMER_SCOPE("incoming_byte_stream_pull", 0); grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)byte_stream; + reinterpret_cast<grpc_chttp2_incoming_byte_stream*>(byte_stream); grpc_chttp2_stream* s = bs->stream; grpc_error* error; @@ -2853,7 +2844,6 @@ static grpc_error* incoming_byte_stream_pull(grpc_byte_stream* byte_stream, GRPC_CLOSURE_SCHED(&s->reset_byte_stream, GRPC_ERROR_REF(error)); return error; } - GPR_TIMER_END("incoming_byte_stream_pull", 0); return GRPC_ERROR_NONE; } @@ -2861,15 +2851,14 @@ static void incoming_byte_stream_destroy_locked(void* byte_stream, grpc_error* error_ignored); static void incoming_byte_stream_destroy(grpc_byte_stream* byte_stream) { - GPR_TIMER_BEGIN("incoming_byte_stream_destroy", 0); + GPR_TIMER_SCOPE("incoming_byte_stream_destroy", 0); grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)byte_stream; + reinterpret_cast<grpc_chttp2_incoming_byte_stream*>(byte_stream); GRPC_CLOSURE_SCHED( GRPC_CLOSURE_INIT(&bs->destroy_action, incoming_byte_stream_destroy_locked, bs, grpc_combiner_scheduler(bs->transport->combiner)), GRPC_ERROR_NONE); - GPR_TIMER_END("incoming_byte_stream_destroy", 0); } static void incoming_byte_stream_publish_error( @@ -2897,7 +2886,7 @@ grpc_error* grpc_chttp2_incoming_byte_stream_push( grpc_slice_unref_internal(slice); return error; } else { - bs->remaining_bytes -= (uint32_t)GRPC_SLICE_LENGTH(slice); + bs->remaining_bytes -= static_cast<uint32_t> GRPC_SLICE_LENGTH(slice); if (slice_out != nullptr) { *slice_out = slice; } @@ -2925,7 +2914,7 @@ grpc_error* grpc_chttp2_incoming_byte_stream_finished( static void incoming_byte_stream_shutdown(grpc_byte_stream* byte_stream, grpc_error* error) { grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)byte_stream; + reinterpret_cast<grpc_chttp2_incoming_byte_stream*>(byte_stream); GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( bs, error, true /* reset_on_error */)); } @@ -2937,7 +2926,7 @@ static const grpc_byte_stream_vtable grpc_chttp2_incoming_byte_stream_vtable = { static void incoming_byte_stream_destroy_locked(void* byte_stream, grpc_error* error_ignored) { grpc_chttp2_incoming_byte_stream* bs = - (grpc_chttp2_incoming_byte_stream*)byte_stream; + static_cast<grpc_chttp2_incoming_byte_stream*>(byte_stream); grpc_chttp2_stream* s = bs->stream; grpc_chttp2_transport* t = s->t; @@ -2952,8 +2941,8 @@ grpc_chttp2_incoming_byte_stream* grpc_chttp2_incoming_byte_stream_create( grpc_chttp2_transport* t, grpc_chttp2_stream* s, uint32_t frame_size, uint32_t flags) { grpc_chttp2_incoming_byte_stream* incoming_byte_stream = - (grpc_chttp2_incoming_byte_stream*)gpr_malloc( - sizeof(*incoming_byte_stream)); + static_cast<grpc_chttp2_incoming_byte_stream*>( + gpr_malloc(sizeof(*incoming_byte_stream))); incoming_byte_stream->base.length = frame_size; incoming_byte_stream->remaining_bytes = frame_size; incoming_byte_stream->base.flags = flags; @@ -2989,7 +2978,7 @@ static void post_destructive_reclaimer(grpc_chttp2_transport* t) { } static void benign_reclaimer_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg); if (error == GRPC_ERROR_NONE && grpc_chttp2_stream_map_size(&t->stream_map) == 0) { /* Channel with no active streams: send a goaway to try and make it @@ -3017,12 +3006,12 @@ static void benign_reclaimer_locked(void* arg, grpc_error* error) { } static void destructive_reclaimer_locked(void* arg, grpc_error* error) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg); size_t n = grpc_chttp2_stream_map_size(&t->stream_map); t->destructive_reclaimer_registered = false; if (error == GRPC_ERROR_NONE && n > 0) { - grpc_chttp2_stream* s = - (grpc_chttp2_stream*)grpc_chttp2_stream_map_rand(&t->stream_map); + grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>( + grpc_chttp2_stream_map_rand(&t->stream_map)); if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "HTTP2: %s - abandon stream id %d", t->peer_string, s->id); @@ -3099,7 +3088,7 @@ const char* grpc_chttp2_initiate_write_reason_string( } static grpc_endpoint* chttp2_get_endpoint(grpc_transport* t) { - return ((grpc_chttp2_transport*)t)->ep; + return (reinterpret_cast<grpc_chttp2_transport*>(t))->ep; } static const grpc_transport_vtable vtable = {sizeof(grpc_chttp2_stream), @@ -3117,8 +3106,8 @@ static const grpc_transport_vtable* get_vtable(void) { return &vtable; } grpc_transport* grpc_create_chttp2_transport( const grpc_channel_args* channel_args, grpc_endpoint* ep, bool is_client) { - grpc_chttp2_transport* t = - (grpc_chttp2_transport*)gpr_zalloc(sizeof(grpc_chttp2_transport)); + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>( + gpr_zalloc(sizeof(grpc_chttp2_transport))); init_transport(t, channel_args, ep, is_client); return &t->base; } @@ -3126,7 +3115,8 @@ grpc_transport* grpc_create_chttp2_transport( void grpc_chttp2_transport_start_reading( grpc_transport* transport, grpc_slice_buffer* read_buffer, grpc_closure* notify_on_receive_settings) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)transport; + grpc_chttp2_transport* t = + reinterpret_cast<grpc_chttp2_transport*>(transport); GRPC_CHTTP2_REF_TRANSPORT( t, "reading_action"); /* matches unref inside reading_action */ if (read_buffer != nullptr) { 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); diff --git a/src/core/ext/transport/chttp2/transport/flow_control.h b/src/core/ext/transport/chttp2/transport/flow_control.h index 2ee1345260..b58027790d 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -22,8 +22,8 @@ #include <grpc/support/port_platform.h> #include <stdint.h> -#include <grpc/support/useful.h> #include "src/core/ext/transport/chttp2/transport/http2_settings.h" +#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/manual_constructor.h" #include "src/core/lib/transport/bdp_estimator.h" @@ -44,7 +44,7 @@ namespace grpc_core { namespace chttp2 { static constexpr uint32_t kDefaultWindow = 65535; -static constexpr int64_t kMaxWindow = (int64_t)((1u << 31) - 1); +static constexpr int64_t kMaxWindow = static_cast<int64_t>((1u << 31) - 1); // TODO(ncteisen): Tune this static constexpr uint32_t kFrameSize = 1024 * 1024; @@ -271,9 +271,10 @@ class TransportFlowControl final : public TransportFlowControlBase { // See comment above announced_stream_total_over_incoming_window_ for the // logic behind this decision. int64_t target_window() const override { - return (uint32_t)GPR_MIN((int64_t)((1u << 31) - 1), - announced_stream_total_over_incoming_window_ + - target_initial_window_size_); + return static_cast<uint32_t> GPR_MIN( + (int64_t)((1u << 31) - 1), + announced_stream_total_over_incoming_window_ + + target_initial_window_size_); } const grpc_chttp2_transport* transport() const { return t_; } diff --git a/src/core/ext/transport/chttp2/transport/frame_data.cc b/src/core/ext/transport/chttp2/transport/frame_data.cc index 043b80a3cb..721f0a55a1 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.cc +++ b/src/core/ext/transport/chttp2/transport/frame_data.cc @@ -23,7 +23,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" #include "src/core/lib/slice/slice_internal.h" @@ -52,9 +51,9 @@ grpc_error* grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser* parser, if (flags & ~GRPC_CHTTP2_DATA_FLAG_END_STREAM) { char* msg; gpr_asprintf(&msg, "unsupported data flags: 0x%02x", flags); - grpc_error* err = - grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg), - GRPC_ERROR_INT_STREAM_ID, (intptr_t)stream_id); + grpc_error* err = grpc_error_set_int( + GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg), GRPC_ERROR_INT_STREAM_ID, + static_cast<intptr_t>(stream_id)); gpr_free(msg); return err; } @@ -79,15 +78,15 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer* inbuf, hdr = GRPC_SLICE_MALLOC(header_size); p = GRPC_SLICE_START_PTR(hdr); GPR_ASSERT(write_bytes < (1 << 24)); - *p++ = (uint8_t)(write_bytes >> 16); - *p++ = (uint8_t)(write_bytes >> 8); - *p++ = (uint8_t)(write_bytes); + *p++ = static_cast<uint8_t>(write_bytes >> 16); + *p++ = static_cast<uint8_t>(write_bytes >> 8); + *p++ = static_cast<uint8_t>(write_bytes); *p++ = GRPC_CHTTP2_FRAME_DATA; *p++ = is_eof ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0; - *p++ = (uint8_t)(id >> 24); - *p++ = (uint8_t)(id >> 16); - *p++ = (uint8_t)(id >> 8); - *p++ = (uint8_t)(id); + *p++ = static_cast<uint8_t>(id >> 24); + *p++ = static_cast<uint8_t>(id >> 16); + *p++ = static_cast<uint8_t>(id >> 8); + *p++ = static_cast<uint8_t>(id); grpc_slice_buffer_add(outbuf, hdr); grpc_slice_buffer_move_first_no_ref(inbuf, write_bytes, outbuf); @@ -140,7 +139,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( gpr_asprintf(&msg, "Bad GRPC frame type 0x%02x", p->frame_type); p->error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); p->error = grpc_error_set_int(p->error, GRPC_ERROR_INT_STREAM_ID, - (intptr_t)s->id); + static_cast<intptr_t>(s->id)); gpr_free(msg); msg = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); p->error = grpc_error_set_str(p->error, GRPC_ERROR_STR_RAW_BYTES, @@ -160,7 +159,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( /* fallthrough */ case GRPC_CHTTP2_DATA_FH_1: s->stats.incoming.framing_bytes++; - p->frame_size = ((uint32_t)*cur) << 24; + p->frame_size = (static_cast<uint32_t>(*cur)) << 24; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_2; grpc_slice_unref_internal(slice); @@ -169,7 +168,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( /* fallthrough */ case GRPC_CHTTP2_DATA_FH_2: s->stats.incoming.framing_bytes++; - p->frame_size |= ((uint32_t)*cur) << 16; + p->frame_size |= (static_cast<uint32_t>(*cur)) << 16; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_3; grpc_slice_unref_internal(slice); @@ -178,7 +177,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( /* fallthrough */ case GRPC_CHTTP2_DATA_FH_3: s->stats.incoming.framing_bytes++; - p->frame_size |= ((uint32_t)*cur) << 8; + p->frame_size |= (static_cast<uint32_t>(*cur)) << 8; if (++cur == end) { p->state = GRPC_CHTTP2_DATA_FH_4; grpc_slice_unref_internal(slice); @@ -189,7 +188,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( s->stats.incoming.framing_bytes++; GPR_ASSERT(stream_out != nullptr); GPR_ASSERT(p->parsing_frame == nullptr); - p->frame_size |= ((uint32_t)*cur); + p->frame_size |= (static_cast<uint32_t>(*cur)); p->state = GRPC_CHTTP2_DATA_FRAME; ++cur; message_flags = 0; @@ -209,8 +208,8 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( if (cur != end) { grpc_slice_buffer_undo_take_first( - slices, - grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); + slices, grpc_slice_sub(slice, static_cast<size_t>(cur - beg), + static_cast<size_t>(end - beg))); } grpc_slice_unref_internal(slice); return GRPC_ERROR_NONE; @@ -221,14 +220,15 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( grpc_slice_unref_internal(slice); continue; } - uint32_t remaining = (uint32_t)(end - cur); + uint32_t remaining = static_cast<uint32_t>(end - cur); if (remaining == p->frame_size) { s->stats.incoming.data_bytes += remaining; - if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( - p->parsing_frame, - grpc_slice_sub(slice, (size_t)(cur - beg), - (size_t)(end - beg)), - slice_out))) { + if (GRPC_ERROR_NONE != + (error = grpc_chttp2_incoming_byte_stream_push( + p->parsing_frame, + grpc_slice_sub(slice, static_cast<size_t>(cur - beg), + static_cast<size_t>(end - beg)), + slice_out))) { grpc_slice_unref_internal(slice); return error; } @@ -244,11 +244,12 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( return GRPC_ERROR_NONE; } else if (remaining < p->frame_size) { s->stats.incoming.data_bytes += remaining; - if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( - p->parsing_frame, - grpc_slice_sub(slice, (size_t)(cur - beg), - (size_t)(end - beg)), - slice_out))) { + if (GRPC_ERROR_NONE != + (error = grpc_chttp2_incoming_byte_stream_push( + p->parsing_frame, + grpc_slice_sub(slice, static_cast<size_t>(cur - beg), + static_cast<size_t>(end - beg)), + slice_out))) { return error; } p->frame_size -= remaining; @@ -260,8 +261,9 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( if (GRPC_ERROR_NONE != (grpc_chttp2_incoming_byte_stream_push( p->parsing_frame, - grpc_slice_sub(slice, (size_t)(cur - beg), - (size_t)(cur + p->frame_size - beg)), + grpc_slice_sub( + slice, static_cast<size_t>(cur - beg), + static_cast<size_t>(cur + p->frame_size - beg)), slice_out))) { grpc_slice_unref_internal(slice); return error; @@ -276,8 +278,8 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( p->state = GRPC_CHTTP2_DATA_FH_0; cur += p->frame_size; grpc_slice_buffer_undo_take_first( - slices, - grpc_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); + slices, grpc_slice_sub(slice, static_cast<size_t>(cur - beg), + static_cast<size_t>(end - beg))); grpc_slice_unref_internal(slice); return GRPC_ERROR_NONE; } diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.cc b/src/core/ext/transport/chttp2/transport/frame_goaway.cc index b60b4227fe..70931ed22d 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.cc +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.cc @@ -46,7 +46,7 @@ grpc_error* grpc_chttp2_goaway_parser_begin_frame(grpc_chttp2_goaway_parser* p, gpr_free(p->debug_data); p->debug_length = length - 8; - p->debug_data = (char*)gpr_malloc(p->debug_length); + p->debug_data = static_cast<char*>(gpr_malloc(p->debug_length)); p->debug_pos = 0; p->state = GRPC_CHTTP2_GOAWAY_LSI0; return GRPC_ERROR_NONE; @@ -59,7 +59,8 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, uint8_t* const beg = GRPC_SLICE_START_PTR(slice); uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; - grpc_chttp2_goaway_parser* p = (grpc_chttp2_goaway_parser*)parser; + grpc_chttp2_goaway_parser* p = + static_cast<grpc_chttp2_goaway_parser*>(parser); switch (p->state) { case GRPC_CHTTP2_GOAWAY_LSI0: @@ -67,7 +68,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_LSI0; return GRPC_ERROR_NONE; } - p->last_stream_id = ((uint32_t)*cur) << 24; + p->last_stream_id = (static_cast<uint32_t>(*cur)) << 24; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_LSI1: @@ -75,7 +76,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_LSI1; return GRPC_ERROR_NONE; } - p->last_stream_id |= ((uint32_t)*cur) << 16; + p->last_stream_id |= (static_cast<uint32_t>(*cur)) << 16; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_LSI2: @@ -83,7 +84,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_LSI2; return GRPC_ERROR_NONE; } - p->last_stream_id |= ((uint32_t)*cur) << 8; + p->last_stream_id |= (static_cast<uint32_t>(*cur)) << 8; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_LSI3: @@ -91,7 +92,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_LSI3; return GRPC_ERROR_NONE; } - p->last_stream_id |= ((uint32_t)*cur); + p->last_stream_id |= (static_cast<uint32_t>(*cur)); ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR0: @@ -99,7 +100,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_ERR0; return GRPC_ERROR_NONE; } - p->error_code = ((uint32_t)*cur) << 24; + p->error_code = (static_cast<uint32_t>(*cur)) << 24; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR1: @@ -107,7 +108,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_ERR1; return GRPC_ERROR_NONE; } - p->error_code |= ((uint32_t)*cur) << 16; + p->error_code |= (static_cast<uint32_t>(*cur)) << 16; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR2: @@ -115,7 +116,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_ERR2; return GRPC_ERROR_NONE; } - p->error_code |= ((uint32_t)*cur) << 8; + p->error_code |= (static_cast<uint32_t>(*cur)) << 8; ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR3: @@ -123,18 +124,19 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, p->state = GRPC_CHTTP2_GOAWAY_ERR3; return GRPC_ERROR_NONE; } - p->error_code |= ((uint32_t)*cur); + p->error_code |= (static_cast<uint32_t>(*cur)); ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_DEBUG: if (end != cur) - memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur)); + memcpy(p->debug_data + p->debug_pos, cur, + static_cast<size_t>(end - cur)); GPR_ASSERT((size_t)(end - cur) < UINT32_MAX - p->debug_pos); - p->debug_pos += (uint32_t)(end - cur); + p->debug_pos += static_cast<uint32_t>(end - cur); p->state = GRPC_CHTTP2_GOAWAY_DEBUG; if (is_last) { grpc_chttp2_add_incoming_goaway( - t, (uint32_t)p->error_code, + t, p->error_code, grpc_slice_new(p->debug_data, p->debug_length, gpr_free)); p->debug_data = nullptr; } @@ -151,12 +153,12 @@ void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code, uint8_t* p = GRPC_SLICE_START_PTR(header); uint32_t frame_length; GPR_ASSERT(GRPC_SLICE_LENGTH(debug_data) < UINT32_MAX - 4 - 4); - frame_length = 4 + 4 + (uint32_t)GRPC_SLICE_LENGTH(debug_data); + frame_length = 4 + 4 + static_cast<uint32_t> GRPC_SLICE_LENGTH(debug_data); /* frame header: length */ - *p++ = (uint8_t)(frame_length >> 16); - *p++ = (uint8_t)(frame_length >> 8); - *p++ = (uint8_t)(frame_length); + *p++ = static_cast<uint8_t>(frame_length >> 16); + *p++ = static_cast<uint8_t>(frame_length >> 8); + *p++ = static_cast<uint8_t>(frame_length); /* frame header: type */ *p++ = GRPC_CHTTP2_FRAME_GOAWAY; /* frame header: flags */ @@ -167,15 +169,15 @@ void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code, *p++ = 0; *p++ = 0; /* payload: last stream id */ - *p++ = (uint8_t)(last_stream_id >> 24); - *p++ = (uint8_t)(last_stream_id >> 16); - *p++ = (uint8_t)(last_stream_id >> 8); - *p++ = (uint8_t)(last_stream_id); + *p++ = static_cast<uint8_t>(last_stream_id >> 24); + *p++ = static_cast<uint8_t>(last_stream_id >> 16); + *p++ = static_cast<uint8_t>(last_stream_id >> 8); + *p++ = static_cast<uint8_t>(last_stream_id); /* payload: error code */ - *p++ = (uint8_t)(error_code >> 24); - *p++ = (uint8_t)(error_code >> 16); - *p++ = (uint8_t)(error_code >> 8); - *p++ = (uint8_t)(error_code); + *p++ = static_cast<uint8_t>(error_code >> 24); + *p++ = static_cast<uint8_t>(error_code >> 16); + *p++ = static_cast<uint8_t>(error_code >> 8); + *p++ = static_cast<uint8_t>(error_code); GPR_ASSERT(p == GRPC_SLICE_END_PTR(header)); grpc_slice_buffer_add(slice_buffer, header); grpc_slice_buffer_add(slice_buffer, debug_data); diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.cc b/src/core/ext/transport/chttp2/transport/frame_ping.cc index 298a56721a..6229459397 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.cc +++ b/src/core/ext/transport/chttp2/transport/frame_ping.cc @@ -40,14 +40,14 @@ grpc_slice grpc_chttp2_ping_create(uint8_t ack, uint64_t opaque_8bytes) { *p++ = 0; *p++ = 0; *p++ = 0; - *p++ = (uint8_t)(opaque_8bytes >> 56); - *p++ = (uint8_t)(opaque_8bytes >> 48); - *p++ = (uint8_t)(opaque_8bytes >> 40); - *p++ = (uint8_t)(opaque_8bytes >> 32); - *p++ = (uint8_t)(opaque_8bytes >> 24); - *p++ = (uint8_t)(opaque_8bytes >> 16); - *p++ = (uint8_t)(opaque_8bytes >> 8); - *p++ = (uint8_t)(opaque_8bytes); + *p++ = static_cast<uint8_t>(opaque_8bytes >> 56); + *p++ = static_cast<uint8_t>(opaque_8bytes >> 48); + *p++ = static_cast<uint8_t>(opaque_8bytes >> 40); + *p++ = static_cast<uint8_t>(opaque_8bytes >> 32); + *p++ = static_cast<uint8_t>(opaque_8bytes >> 24); + *p++ = static_cast<uint8_t>(opaque_8bytes >> 16); + *p++ = static_cast<uint8_t>(opaque_8bytes >> 8); + *p++ = static_cast<uint8_t>(opaque_8bytes); return slice; } @@ -75,10 +75,10 @@ grpc_error* grpc_chttp2_ping_parser_parse(void* parser, uint8_t* const beg = GRPC_SLICE_START_PTR(slice); uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; - grpc_chttp2_ping_parser* p = (grpc_chttp2_ping_parser*)parser; + grpc_chttp2_ping_parser* p = static_cast<grpc_chttp2_ping_parser*>(parser); while (p->byte != 8 && cur != end) { - p->opaque_8bytes |= (((uint64_t)*cur) << (56 - 8 * p->byte)); + p->opaque_8bytes |= ((static_cast<uint64_t>(*cur)) << (56 - 8 * p->byte)); cur++; p->byte++; } @@ -112,8 +112,8 @@ grpc_error* grpc_chttp2_ping_parser_parse(void* parser, if (!g_disable_ping_ack) { if (t->ping_ack_count == t->ping_ack_capacity) { t->ping_ack_capacity = GPR_MAX(t->ping_ack_capacity * 3 / 2, 3); - t->ping_acks = (uint64_t*)gpr_realloc( - t->ping_acks, t->ping_ack_capacity * sizeof(*t->ping_acks)); + t->ping_acks = static_cast<uint64_t*>(gpr_realloc( + t->ping_acks, t->ping_ack_capacity * sizeof(*t->ping_acks))); } t->ping_acks[t->ping_ack_count++] = p->opaque_8bytes; grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_PING_RESPONSE); diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc index fee576678d..79528762e0 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc @@ -42,15 +42,15 @@ grpc_slice grpc_chttp2_rst_stream_create(uint32_t id, uint32_t code, // Flags. *p++ = 0; // Stream ID. - *p++ = (uint8_t)(id >> 24); - *p++ = (uint8_t)(id >> 16); - *p++ = (uint8_t)(id >> 8); - *p++ = (uint8_t)(id); + *p++ = static_cast<uint8_t>(id >> 24); + *p++ = static_cast<uint8_t>(id >> 16); + *p++ = static_cast<uint8_t>(id >> 8); + *p++ = static_cast<uint8_t>(id); // Error code. - *p++ = (uint8_t)(code >> 24); - *p++ = (uint8_t)(code >> 16); - *p++ = (uint8_t)(code >> 8); - *p++ = (uint8_t)(code); + *p++ = static_cast<uint8_t>(code >> 24); + *p++ = static_cast<uint8_t>(code >> 16); + *p++ = static_cast<uint8_t>(code >> 8); + *p++ = static_cast<uint8_t>(code); return slice; } @@ -76,21 +76,22 @@ grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser, uint8_t* const beg = GRPC_SLICE_START_PTR(slice); uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; - grpc_chttp2_rst_stream_parser* p = (grpc_chttp2_rst_stream_parser*)parser; + grpc_chttp2_rst_stream_parser* p = + static_cast<grpc_chttp2_rst_stream_parser*>(parser); while (p->byte != 4 && cur != end) { p->reason_bytes[p->byte] = *cur; cur++; p->byte++; } - s->stats.incoming.framing_bytes += (uint64_t)(end - cur); + s->stats.incoming.framing_bytes += static_cast<uint64_t>(end - cur); if (p->byte == 4) { GPR_ASSERT(is_last); - uint32_t reason = (((uint32_t)p->reason_bytes[0]) << 24) | - (((uint32_t)p->reason_bytes[1]) << 16) | - (((uint32_t)p->reason_bytes[2]) << 8) | - (((uint32_t)p->reason_bytes[3])); + uint32_t reason = ((static_cast<uint32_t>(p->reason_bytes[0])) << 24) | + ((static_cast<uint32_t>(p->reason_bytes[1])) << 16) | + ((static_cast<uint32_t>(p->reason_bytes[2])) << 8) | + ((static_cast<uint32_t>(p->reason_bytes[3]))); grpc_error* error = GRPC_ERROR_NONE; if (reason != GRPC_HTTP2_NO_ERROR || s->metadata_buffer[1].size == 0) { char* message; @@ -99,7 +100,7 @@ grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser, grpc_error_set_str(GRPC_ERROR_CREATE_FROM_STATIC_STRING("RST_STREAM"), GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_copied_string(message)), - GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)reason); + GRPC_ERROR_INT_HTTP2_ERROR, static_cast<intptr_t>(reason)); gpr_free(message); } grpc_chttp2_mark_stream_closed(t, s, true, true, error); diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index 0d245f4ba1..737a9382e0 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -24,7 +24,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/chttp2_transport.h" #include "src/core/ext/transport/chttp2/transport/frame.h" @@ -32,9 +31,9 @@ #include "src/core/lib/transport/http2_errors.h" static uint8_t* fill_header(uint8_t* out, uint32_t length, uint8_t flags) { - *out++ = (uint8_t)(length >> 16); - *out++ = (uint8_t)(length >> 8); - *out++ = (uint8_t)(length); + *out++ = static_cast<uint8_t>(length >> 16); + *out++ = static_cast<uint8_t>(length >> 8); + *out++ = static_cast<uint8_t>(length); *out++ = GRPC_CHTTP2_FRAME_SETTINGS; *out++ = flags; *out++ = 0; @@ -61,12 +60,12 @@ grpc_slice grpc_chttp2_settings_create(uint32_t* old_settings, for (i = 0; i < count; i++) { if (new_settings[i] != old_settings[i] || (force_mask & (1u << i)) != 0) { - *p++ = (uint8_t)(grpc_setting_id_to_wire_id[i] >> 8); - *p++ = (uint8_t)(grpc_setting_id_to_wire_id[i]); - *p++ = (uint8_t)(new_settings[i] >> 24); - *p++ = (uint8_t)(new_settings[i] >> 16); - *p++ = (uint8_t)(new_settings[i] >> 8); - *p++ = (uint8_t)(new_settings[i]); + *p++ = static_cast<uint8_t>(grpc_setting_id_to_wire_id[i] >> 8); + *p++ = static_cast<uint8_t>(grpc_setting_id_to_wire_id[i]); + *p++ = static_cast<uint8_t>(new_settings[i] >> 24); + *p++ = static_cast<uint8_t>(new_settings[i] >> 16); + *p++ = static_cast<uint8_t>(new_settings[i] >> 8); + *p++ = static_cast<uint8_t>(new_settings[i]); old_settings[i] = new_settings[i]; } } @@ -111,7 +110,8 @@ grpc_error* grpc_chttp2_settings_parser_begin_frame( grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { - grpc_chttp2_settings_parser* parser = (grpc_chttp2_settings_parser*)p; + grpc_chttp2_settings_parser* parser = + static_cast<grpc_chttp2_settings_parser*>(p); const uint8_t* cur = GRPC_SLICE_START_PTR(slice); const uint8_t* end = GRPC_SLICE_END_PTR(slice); char* msg; @@ -138,7 +138,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, } return GRPC_ERROR_NONE; } - parser->id = (uint16_t)(((uint16_t)*cur) << 8); + parser->id = static_cast<uint16_t>((static_cast<uint16_t>(*cur)) << 8); cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_ID1: @@ -146,7 +146,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, parser->state = GRPC_CHTTP2_SPS_ID1; return GRPC_ERROR_NONE; } - parser->id = (uint16_t)(parser->id | (*cur)); + parser->id = static_cast<uint16_t>(parser->id | (*cur)); cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_VAL0: @@ -154,7 +154,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, parser->state = GRPC_CHTTP2_SPS_VAL0; return GRPC_ERROR_NONE; } - parser->value = ((uint32_t)*cur) << 24; + parser->value = (static_cast<uint32_t>(*cur)) << 24; cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_VAL1: @@ -162,7 +162,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, parser->state = GRPC_CHTTP2_SPS_VAL1; return GRPC_ERROR_NONE; } - parser->value |= ((uint32_t)*cur) << 16; + parser->value |= (static_cast<uint32_t>(*cur)) << 16; cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_VAL2: @@ -170,7 +170,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, parser->state = GRPC_CHTTP2_SPS_VAL2; return GRPC_ERROR_NONE; } - parser->value |= ((uint32_t)*cur) << 8; + parser->value |= (static_cast<uint32_t>(*cur)) << 8; cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_VAL3: @@ -212,12 +212,12 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t, } if (id == GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE && parser->incoming_settings[id] != parser->value) { - t->initial_window_update += - (int64_t)parser->value - parser->incoming_settings[id]; + t->initial_window_update += static_cast<int64_t>(parser->value) - + parser->incoming_settings[id]; if (grpc_http_trace.enabled() || grpc_flowctl_trace.enabled()) { gpr_log(GPR_DEBUG, "%p[%s] adding %d for initial_window change", t, t->is_client ? "cli" : "svr", - (int)t->initial_window_update); + static_cast<int>(t->initial_window_update)); } } parser->incoming_settings[id] = parser->value; diff --git a/src/core/ext/transport/chttp2/transport/frame_window_update.cc b/src/core/ext/transport/chttp2/transport/frame_window_update.cc index 418ca144ce..95be5b42d2 100644 --- a/src/core/ext/transport/chttp2/transport/frame_window_update.cc +++ b/src/core/ext/transport/chttp2/transport/frame_window_update.cc @@ -37,14 +37,14 @@ grpc_slice grpc_chttp2_window_update_create( *p++ = 4; *p++ = GRPC_CHTTP2_FRAME_WINDOW_UPDATE; *p++ = 0; - *p++ = (uint8_t)(id >> 24); - *p++ = (uint8_t)(id >> 16); - *p++ = (uint8_t)(id >> 8); - *p++ = (uint8_t)(id); - *p++ = (uint8_t)(window_update >> 24); - *p++ = (uint8_t)(window_update >> 16); - *p++ = (uint8_t)(window_update >> 8); - *p++ = (uint8_t)(window_update); + *p++ = static_cast<uint8_t>(id >> 24); + *p++ = static_cast<uint8_t>(id >> 16); + *p++ = static_cast<uint8_t>(id >> 8); + *p++ = static_cast<uint8_t>(id); + *p++ = static_cast<uint8_t>(window_update >> 24); + *p++ = static_cast<uint8_t>(window_update >> 16); + *p++ = static_cast<uint8_t>(window_update >> 8); + *p++ = static_cast<uint8_t>(window_update); return slice; } @@ -73,16 +73,16 @@ grpc_error* grpc_chttp2_window_update_parser_parse(void* parser, uint8_t* const end = GRPC_SLICE_END_PTR(slice); uint8_t* cur = beg; grpc_chttp2_window_update_parser* p = - (grpc_chttp2_window_update_parser*)parser; + static_cast<grpc_chttp2_window_update_parser*>(parser); while (p->byte != 4 && cur != end) { - p->amount |= ((uint32_t)*cur) << (8 * (3 - p->byte)); + p->amount |= (static_cast<uint32_t>(*cur)) << (8 * (3 - p->byte)); cur++; p->byte++; } if (s != nullptr) { - s->stats.incoming.framing_bytes += (uint32_t)(end - cur); + s->stats.incoming.framing_bytes += static_cast<uint32_t>(end - cur); } if (p->byte == 4) { diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index 3a5692a694..4855455130 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -28,7 +28,6 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include <grpc/support/useful.h> #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" #include "src/core/ext/transport/chttp2/transport/hpack_table.h" @@ -79,15 +78,15 @@ typedef struct { static void fill_header(uint8_t* p, uint8_t type, uint32_t id, size_t len, uint8_t flags) { GPR_ASSERT(len < 16777316); - *p++ = (uint8_t)(len >> 16); - *p++ = (uint8_t)(len >> 8); - *p++ = (uint8_t)(len); + *p++ = static_cast<uint8_t>(len >> 16); + *p++ = static_cast<uint8_t>(len >> 8); + *p++ = static_cast<uint8_t>(len); *p++ = type; *p++ = flags; - *p++ = (uint8_t)(id >> 24); - *p++ = (uint8_t)(id >> 16); - *p++ = (uint8_t)(id >> 8); - *p++ = (uint8_t)(id); + *p++ = static_cast<uint8_t>(id >> 24); + *p++ = static_cast<uint8_t>(id >> 16); + *p++ = static_cast<uint8_t>(id >> 8); + *p++ = static_cast<uint8_t>(id); } /* finish a frame - fill in the previously reserved header */ @@ -99,8 +98,9 @@ static void finish_frame(framer_state* st, int is_header_boundary, fill_header( GRPC_SLICE_START_PTR(st->output->slices[st->header_idx]), type, st->stream_id, st->output->length - st->output_length_at_start_of_frame, - (uint8_t)((is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | - (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0))); + static_cast<uint8_t>( + (is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | + (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0))); st->stats->framing_bytes += 9; st->is_first_frame = 0; } @@ -170,9 +170,9 @@ static void evict_entry(grpc_chttp2_hpack_compressor* c) { GPR_ASSERT(c->table_size >= c->table_elem_size[c->tail_remote_index % c->cap_table_elems]); GPR_ASSERT(c->table_elems > 0); - c->table_size = - (uint16_t)(c->table_size - - c->table_elem_size[c->tail_remote_index % c->cap_table_elems]); + c->table_size = static_cast<uint16_t>( + c->table_size - + c->table_elem_size[c->tail_remote_index % c->cap_table_elems]); c->table_elems--; } @@ -198,8 +198,9 @@ static uint32_t prepare_space_for_new_elem(grpc_chttp2_hpack_compressor* c, evict_entry(c); } GPR_ASSERT(c->table_elems < c->max_table_size); - c->table_elem_size[new_index % c->cap_table_elems] = (uint16_t)elem_size; - c->table_size = (uint16_t)(c->table_size + elem_size); + c->table_elem_size[new_index % c->cap_table_elems] = + static_cast<uint16_t>(elem_size); + c->table_size = static_cast<uint16_t>(c->table_size + elem_size); c->table_elems++; return new_index; @@ -395,9 +396,9 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor* c, GPR_ASSERT(unused_index == 0); GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V(); GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); - uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); + uint32_t len_key = static_cast<uint32_t> GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); wire_value value = get_wire_value(elem, st->use_true_binary_metadata); - uint32_t len_val = (uint32_t)wire_value_length(value); + uint32_t len_val = static_cast<uint32_t>(wire_value_length(value)); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); GPR_ASSERT(len_key <= UINT32_MAX); @@ -417,9 +418,9 @@ static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor* c, GPR_ASSERT(unused_index == 0); GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V(); GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(); - uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); + uint32_t len_key = static_cast<uint32_t> GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); wire_value value = get_wire_value(elem, st->use_true_binary_metadata); - uint32_t len_val = (uint32_t)wire_value_length(value); + uint32_t len_val = static_cast<uint32_t>(wire_value_length(value)); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); GPR_ASSERT(len_key <= UINT32_MAX); @@ -584,8 +585,8 @@ void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor* c) { c->cap_table_elems = elems_for_bytes(c->max_table_size); c->max_table_elems = c->cap_table_elems; c->max_usable_size = GRPC_CHTTP2_HPACKC_INITIAL_TABLE_SIZE; - c->table_elem_size = - (uint16_t*)gpr_malloc(sizeof(*c->table_elem_size) * c->cap_table_elems); + c->table_elem_size = static_cast<uint16_t*>( + gpr_malloc(sizeof(*c->table_elem_size) * c->cap_table_elems)); memset(c->table_elem_size, 0, sizeof(*c->table_elem_size) * c->cap_table_elems); for (size_t i = 0; i < GPR_ARRAY_SIZE(c->entries_keys); i++) { @@ -613,7 +614,7 @@ void grpc_chttp2_hpack_compressor_set_max_usable_size( static void rebuild_elems(grpc_chttp2_hpack_compressor* c, uint32_t new_cap) { uint16_t* table_elem_size = - (uint16_t*)gpr_malloc(sizeof(*table_elem_size) * new_cap); + static_cast<uint16_t*>(gpr_malloc(sizeof(*table_elem_size) * new_cap)); uint32_t i; memset(table_elem_size, 0, sizeof(*table_elem_size) * new_cap); diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index ebee5913cb..26a38e3f87 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -27,7 +27,6 @@ #include <grpc/support/log.h> #include <grpc/support/port_platform.h> #include <grpc/support/string_util.h> -#include <grpc/support/useful.h> #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" #include "src/core/lib/debug/stats.h" @@ -758,8 +757,9 @@ static grpc_error* finish_indexed_field(grpc_chttp2_hpack_parser* p, return grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Invalid HPACK index received"), - GRPC_ERROR_INT_INDEX, (intptr_t)p->index), - GRPC_ERROR_INT_SIZE, (intptr_t)p->table.num_ents); + GRPC_ERROR_INT_INDEX, + static_cast<intptr_t>(p->index)), + GRPC_ERROR_INT_SIZE, static_cast<intptr_t>(p->table.num_ents)); } GRPC_MDELEM_REF(md); GRPC_STATS_INC_HPACK_RECV_INDEXED(); @@ -1088,7 +1088,7 @@ static grpc_error* parse_value1(grpc_chttp2_hpack_parser* p, const uint8_t* cur, return GRPC_ERROR_NONE; } - *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 7; + *p->parsing.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 7; if ((*cur) & 0x80) { return parse_value2(p, cur + 1, end); @@ -1106,7 +1106,7 @@ static grpc_error* parse_value2(grpc_chttp2_hpack_parser* p, const uint8_t* cur, return GRPC_ERROR_NONE; } - *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 14; + *p->parsing.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 14; if ((*cur) & 0x80) { return parse_value3(p, cur + 1, end); @@ -1124,7 +1124,7 @@ static grpc_error* parse_value3(grpc_chttp2_hpack_parser* p, const uint8_t* cur, return GRPC_ERROR_NONE; } - *p->parsing.value += (((uint32_t)*cur) & 0x7f) << 21; + *p->parsing.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 21; if ((*cur) & 0x80) { return parse_value4(p, cur + 1, end); @@ -1153,7 +1153,7 @@ static grpc_error* parse_value4(grpc_chttp2_hpack_parser* p, const uint8_t* cur, } cur_value = *p->parsing.value; - add_value = ((uint32_t)c) << 28; + add_value = (static_cast<uint32_t>(c)) << 28; if (add_value > 0xffffffffu - cur_value) { goto error; } @@ -1228,13 +1228,14 @@ static void append_bytes(grpc_chttp2_hpack_parser_string* str, if (length == 0) return; if (length + str->data.copied.length > str->data.copied.capacity) { GPR_ASSERT(str->data.copied.length + length <= UINT32_MAX); - str->data.copied.capacity = (uint32_t)(str->data.copied.length + length); - str->data.copied.str = - (char*)gpr_realloc(str->data.copied.str, str->data.copied.capacity); + str->data.copied.capacity = + static_cast<uint32_t>(str->data.copied.length + length); + str->data.copied.str = static_cast<char*>( + gpr_realloc(str->data.copied.str, str->data.copied.capacity)); } memcpy(str->data.copied.str + str->data.copied.length, data, length); GPR_ASSERT(length <= UINT32_MAX - str->data.copied.length); - str->data.copied.length += (uint32_t)length; + str->data.copied.length += static_cast<uint32_t>(length); } static grpc_error* append_string(grpc_chttp2_hpack_parser* p, @@ -1242,9 +1243,9 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, grpc_chttp2_hpack_parser_string* str = p->parsing.str; uint32_t bits; uint8_t decoded[3]; - switch ((binary_state)p->binary) { + switch (static_cast<binary_state>(p->binary)) { case NOT_BINARY: - append_bytes(str, cur, (size_t)(end - cur)); + append_bytes(str, cur, static_cast<size_t>(end - cur)); return GRPC_ERROR_NONE; case BINARY_BEGIN: if (cur == end) { @@ -1256,7 +1257,7 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, ++cur; p->binary = NOT_BINARY; GRPC_STATS_INC_HPACK_RECV_BINARY(); - append_bytes(str, cur, (size_t)(end - cur)); + append_bytes(str, cur, static_cast<size_t>(end - cur)); return GRPC_ERROR_NONE; } GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64(); @@ -1325,9 +1326,9 @@ static grpc_error* append_string(grpc_chttp2_hpack_parser* p, goto b64_byte3; p->base64_buffer |= bits; bits = p->base64_buffer; - decoded[0] = (uint8_t)(bits >> 16); - decoded[1] = (uint8_t)(bits >> 8); - decoded[2] = (uint8_t)(bits); + decoded[0] = static_cast<uint8_t>(bits >> 16); + decoded[1] = static_cast<uint8_t>(bits >> 8); + decoded[2] = static_cast<uint8_t>(bits); append_bytes(str, decoded, 3); goto b64_byte0; } @@ -1341,7 +1342,7 @@ static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, uint8_t decoded[2]; uint32_t bits; grpc_chttp2_hpack_parser_string* str = p->parsing.str; - switch ((binary_state)p->binary) { + switch (static_cast<binary_state>(p->binary)) { case NOT_BINARY: break; case BINARY_BEGIN: @@ -1362,7 +1363,7 @@ static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, gpr_free(msg); return parse_error(p, cur, end, err); } - decoded[0] = (uint8_t)(bits >> 16); + decoded[0] = static_cast<uint8_t>(bits >> 16); append_bytes(str, decoded, 1); break; case B64_BYTE3: @@ -1375,8 +1376,8 @@ static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur, gpr_free(msg); return parse_error(p, cur, end, err); } - decoded[0] = (uint8_t)(bits >> 16); - decoded[1] = (uint8_t)(bits >> 8); + decoded[0] = static_cast<uint8_t>(bits >> 16); + decoded[1] = static_cast<uint8_t>(bits >> 8); append_bytes(str, decoded, 2); break; } @@ -1389,7 +1390,7 @@ static grpc_error* huff_nibble(grpc_chttp2_hpack_parser* p, uint8_t nibble) { int16_t next = next_sub_tbl[16 * next_tbl[p->huff_state] + nibble]; if (emit != -1) { if (emit >= 0 && emit < 256) { - uint8_t c = (uint8_t)emit; + uint8_t c = static_cast<uint8_t>(emit); grpc_error* err = append_string(p, &c, (&c) + 1); if (err != GRPC_ERROR_NONE) return err; } else { @@ -1427,7 +1428,7 @@ static grpc_error* add_str_bytes(grpc_chttp2_hpack_parser* p, static grpc_error* parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) { size_t remaining = p->strlen - p->strgot; - size_t given = (size_t)(end - cur); + size_t given = static_cast<size_t>(end - cur); if (remaining <= given) { grpc_error* err = add_str_bytes(p, cur, cur + remaining); if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); @@ -1438,7 +1439,7 @@ static grpc_error* parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, grpc_error* err = add_str_bytes(p, cur, cur + given); if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err); GPR_ASSERT(given <= UINT32_MAX - p->strgot); - p->strgot += (uint32_t)given; + p->strgot += static_cast<uint32_t>(given); p->state = parse_string; return GRPC_ERROR_NONE; } @@ -1449,12 +1450,13 @@ static grpc_error* begin_parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end, uint8_t binary, grpc_chttp2_hpack_parser_string* str) { - if (!p->huff && binary == NOT_BINARY && (end - cur) >= (intptr_t)p->strlen && + if (!p->huff && binary == NOT_BINARY && + (end - cur) >= static_cast<intptr_t>(p->strlen) && p->current_slice_refcount != nullptr) { GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(); str->copied = false; str->data.referenced.refcount = p->current_slice_refcount; - str->data.referenced.data.refcounted.bytes = (uint8_t*)cur; + str->data.referenced.data.refcounted.bytes = const_cast<uint8_t*>(cur); str->data.referenced.data.refcounted.length = p->strlen; grpc_slice_ref_internal(str->data.referenced); return parse_next(p, cur + p->strlen, end); @@ -1504,8 +1506,9 @@ static grpc_error* is_binary_indexed_header(grpc_chttp2_hpack_parser* p, return grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Invalid HPACK index received"), - GRPC_ERROR_INT_INDEX, (intptr_t)p->index), - GRPC_ERROR_INT_SIZE, (intptr_t)p->table.num_ents); + GRPC_ERROR_INT_INDEX, + static_cast<intptr_t>(p->index)), + GRPC_ERROR_INT_SIZE, static_cast<intptr_t>(p->table.num_ents)); } *is = grpc_is_binary_header(GRPC_MDKEY(elem)); return GRPC_ERROR_NONE; @@ -1590,7 +1593,7 @@ static const maybe_complete_func_type maybe_complete_funcs[] = { grpc_chttp2_maybe_complete_recv_trailing_metadata}; static void force_client_rst_stream(void* sp, grpc_error* error) { - grpc_chttp2_stream* s = (grpc_chttp2_stream*)sp; + grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(sp); grpc_chttp2_transport* t = s->t; if (!s->write_closed) { grpc_slice_buffer_add( @@ -1618,19 +1621,18 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { - grpc_chttp2_hpack_parser* parser = (grpc_chttp2_hpack_parser*)hpack_parser; - GPR_TIMER_BEGIN("grpc_chttp2_hpack_parser_parse", 0); + GPR_TIMER_SCOPE("grpc_chttp2_hpack_parser_parse", 0); + grpc_chttp2_hpack_parser* parser = + static_cast<grpc_chttp2_hpack_parser*>(hpack_parser); if (s != nullptr) { s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice); } grpc_error* error = grpc_chttp2_hpack_parser_parse(parser, slice); if (error != GRPC_ERROR_NONE) { - GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); return error; } if (is_last) { if (parser->is_boundary && parser->state != parse_begin) { - GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "end of header frame not aligned with a hpack record boundary"); } @@ -1639,7 +1641,6 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, if (s != nullptr) { if (parser->is_boundary) { if (s->header_frames_received == GPR_ARRAY_SIZE(s->metadata_buffer)) { - GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Too many trailer frames"); } @@ -1674,6 +1675,5 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, parser->is_eof = 0xde; parser->dynamic_table_update_allowed = 2; } - GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); return GRPC_ERROR_NONE; } diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.cc b/src/core/ext/transport/chttp2/transport/hpack_table.cc index 9fad158d27..d7cabbde04 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_table.cc @@ -173,7 +173,8 @@ void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl* tbl) { GRPC_CHTTP2_INITIAL_HPACK_TABLE_SIZE; tbl->max_entries = tbl->cap_entries = entries_for_bytes(tbl->current_table_bytes); - tbl->ents = (grpc_mdelem*)gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries); + tbl->ents = static_cast<grpc_mdelem*>( + gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries)); memset(tbl->ents, 0, sizeof(*tbl->ents) * tbl->cap_entries); for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { tbl->static_ents[i - 1] = grpc_mdelem_from_slices( @@ -218,14 +219,15 @@ static void evict1(grpc_chttp2_hptbl* tbl) { GRPC_SLICE_LENGTH(GRPC_MDVALUE(first_ent)) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; GPR_ASSERT(elem_bytes <= tbl->mem_used); - tbl->mem_used -= (uint32_t)elem_bytes; + tbl->mem_used -= static_cast<uint32_t>(elem_bytes); tbl->first_ent = ((tbl->first_ent + 1) % tbl->cap_entries); tbl->num_ents--; GRPC_MDELEM_UNREF(first_ent); } static void rebuild_ents(grpc_chttp2_hptbl* tbl, uint32_t new_cap) { - grpc_mdelem* ents = (grpc_mdelem*)gpr_malloc(sizeof(*ents) * new_cap); + grpc_mdelem* ents = + static_cast<grpc_mdelem*>(gpr_malloc(sizeof(*ents) * new_cap)); uint32_t i; for (i = 0; i < tbl->num_ents; i++) { @@ -320,7 +322,8 @@ grpc_error* grpc_chttp2_hptbl_add(grpc_chttp2_hptbl* tbl, grpc_mdelem md) { } /* evict entries to ensure no overflow */ - while (elem_bytes > (size_t)tbl->current_table_bytes - tbl->mem_used) { + while (elem_bytes > + static_cast<size_t>(tbl->current_table_bytes) - tbl->mem_used) { evict1(tbl); } @@ -330,7 +333,7 @@ grpc_error* grpc_chttp2_hptbl_add(grpc_chttp2_hptbl* tbl, grpc_mdelem md) { /* update accounting values */ tbl->num_ents++; - tbl->mem_used += (uint32_t)elem_bytes; + tbl->mem_used += static_cast<uint32_t>(elem_bytes); return GRPC_ERROR_NONE; } @@ -350,8 +353,8 @@ grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( /* Scan the dynamic table */ for (i = 0; i < tbl->num_ents; i++) { - uint32_t idx = - (uint32_t)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); + uint32_t idx = static_cast<uint32_t>(tbl->num_ents - i + + GRPC_CHTTP2_LAST_STATIC_ENTRY); grpc_mdelem ent = tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]; if (!grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDKEY(ent))) continue; r.index = idx; diff --git a/src/core/ext/transport/chttp2/transport/http2_settings.cc b/src/core/ext/transport/chttp2/transport/http2_settings.cc index 0aab864400..745b1656f9 100644 --- a/src/core/ext/transport/chttp2/transport/http2_settings.cc +++ b/src/core/ext/transport/chttp2/transport/http2_settings.cc @@ -20,7 +20,7 @@ #include "src/core/ext/transport/chttp2/transport/http2_settings.h" -#include <grpc/support/useful.h> +#include "src/core/lib/gpr/useful.h" #include "src/core/lib/transport/http2_errors.h" const uint16_t grpc_setting_id_to_wire_id[] = {1, 2, 3, 4, 5, 6, 65027}; @@ -35,7 +35,7 @@ bool grpc_wire_id_to_setting_id(uint32_t wire_id, grpc_chttp2_setting_id* out) { h += 4; break; } - *out = (grpc_chttp2_setting_id)h; + *out = static_cast<grpc_chttp2_setting_id>(h); return h < GPR_ARRAY_SIZE(grpc_setting_id_to_wire_id) && grpc_setting_id_to_wire_id[h] == wire_id; } diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc index ef0c9ed230..18d89f06d8 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc @@ -42,8 +42,8 @@ grpc_error* grpc_chttp2_incoming_metadata_buffer_add( buffer->size += GRPC_MDELEM_LENGTH(elem); return grpc_metadata_batch_add_tail( &buffer->batch, - (grpc_linked_mdelem*)gpr_arena_alloc(buffer->arena, - sizeof(grpc_linked_mdelem)), + static_cast<grpc_linked_mdelem*>( + gpr_arena_alloc(buffer->arena, sizeof(grpc_linked_mdelem))), elem); } diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index 59dc38ef98..9357fedb5c 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -88,15 +88,16 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, "Connect string mismatch: expected '%c' (%d) got '%c' (%d) " "at byte %d", GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state], - (int)(uint8_t)GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state], - *cur, (int)*cur, t->deframe_state); + static_cast<int>(static_cast<uint8_t>( + GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state])), + *cur, static_cast<int>(*cur), t->deframe_state); err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } ++cur; - t->deframe_state = - (grpc_chttp2_deframe_transport_state)(1 + (int)t->deframe_state); + t->deframe_state = static_cast<grpc_chttp2_deframe_transport_state>( + 1 + static_cast<int>(t->deframe_state)); } if (cur == end) { return GRPC_ERROR_NONE; @@ -105,7 +106,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, dts_fh_0: case GRPC_DTS_FH_0: GPR_ASSERT(cur < end); - t->incoming_frame_size = ((uint32_t)*cur) << 16; + t->incoming_frame_size = (static_cast<uint32_t>(*cur)) << 16; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_1; return GRPC_ERROR_NONE; @@ -113,7 +114,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FH_1: GPR_ASSERT(cur < end); - t->incoming_frame_size |= ((uint32_t)*cur) << 8; + t->incoming_frame_size |= (static_cast<uint32_t>(*cur)) << 8; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_2; return GRPC_ERROR_NONE; @@ -145,7 +146,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FH_5: GPR_ASSERT(cur < end); - t->incoming_stream_id = (((uint32_t)*cur) & 0x7f) << 24; + t->incoming_stream_id = ((static_cast<uint32_t>(*cur)) & 0x7f) << 24; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_6; return GRPC_ERROR_NONE; @@ -153,7 +154,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FH_6: GPR_ASSERT(cur < end); - t->incoming_stream_id |= ((uint32_t)*cur) << 16; + t->incoming_stream_id |= (static_cast<uint32_t>(*cur)) << 16; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_7; return GRPC_ERROR_NONE; @@ -161,7 +162,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FH_7: GPR_ASSERT(cur < end); - t->incoming_stream_id |= ((uint32_t)*cur) << 8; + t->incoming_stream_id |= (static_cast<uint32_t>(*cur)) << 8; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_8; return GRPC_ERROR_NONE; @@ -169,7 +170,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FH_8: GPR_ASSERT(cur < end); - t->incoming_stream_id |= ((uint32_t)*cur); + t->incoming_stream_id |= (static_cast<uint32_t>(*cur)); t->deframe_state = GRPC_DTS_FRAME; err = init_frame_parser(t); if (err != GRPC_ERROR_NONE) { @@ -205,20 +206,20 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, /* fallthrough */ case GRPC_DTS_FRAME: GPR_ASSERT(cur < end); - if ((uint32_t)(end - cur) == t->incoming_frame_size) { - err = - parse_frame_slice(t, - grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), - (size_t)(end - beg)), - 1); + if (static_cast<uint32_t>(end - cur) == t->incoming_frame_size) { + err = parse_frame_slice( + t, + grpc_slice_sub_no_ref(slice, static_cast<size_t>(cur - beg), + static_cast<size_t>(end - beg)), + 1); if (err != GRPC_ERROR_NONE) { return err; } t->deframe_state = GRPC_DTS_FH_0; t->incoming_stream = nullptr; return GRPC_ERROR_NONE; - } else if ((uint32_t)(end - cur) > t->incoming_frame_size) { - size_t cur_offset = (size_t)(cur - beg); + } else if (static_cast<uint32_t>(end - cur) > t->incoming_frame_size) { + size_t cur_offset = static_cast<size_t>(cur - beg); err = parse_frame_slice( t, grpc_slice_sub_no_ref(slice, cur_offset, @@ -231,15 +232,15 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, t->incoming_stream = nullptr; goto dts_fh_0; /* loop */ } else { - err = - parse_frame_slice(t, - grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), - (size_t)(end - beg)), - 0); + err = parse_frame_slice( + t, + grpc_slice_sub_no_ref(slice, static_cast<size_t>(cur - beg), + static_cast<size_t>(end - beg)), + 0); if (err != GRPC_ERROR_NONE) { return err; } - t->incoming_frame_size -= (uint32_t)(end - cur); + t->incoming_frame_size -= static_cast<uint32_t>(end - cur); return GRPC_ERROR_NONE; } GPR_UNREACHABLE_CODE(return nullptr); @@ -325,7 +326,7 @@ static grpc_error* init_skip_frame_parser(grpc_chttp2_transport* t, t->hpack_parser.on_header = skip_header; t->hpack_parser.on_header_user_data = nullptr; t->hpack_parser.is_boundary = is_eoh; - t->hpack_parser.is_eof = (uint8_t)(is_eoh ? t->header_eof : 0); + t->hpack_parser.is_eof = static_cast<uint8_t>(is_eoh ? t->header_eof : 0); } else { t->parser = skip_parser; } @@ -392,11 +393,10 @@ error_handler: static void free_timeout(void* p) { gpr_free(p); } static void on_initial_header(void* tp, grpc_mdelem md) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; - grpc_chttp2_stream* s = t->incoming_stream; - - GPR_TIMER_BEGIN("on_initial_header", 0); + GPR_TIMER_SCOPE("on_initial_header", 0); + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); + grpc_chttp2_stream* s = t->incoming_stream; GPR_ASSERT(s != nullptr); if (grpc_http_trace.enabled()) { @@ -430,7 +430,8 @@ static void on_initial_header(void* tp, grpc_mdelem md) { } if (GRPC_MDELEM_IS_INTERNED(md)) { /* store the result */ - cached_timeout = (grpc_millis*)gpr_malloc(sizeof(grpc_millis)); + cached_timeout = + static_cast<grpc_millis*>(gpr_malloc(sizeof(grpc_millis))); *cached_timeout = timeout; grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); } @@ -470,16 +471,13 @@ static void on_initial_header(void* tp, grpc_mdelem md) { } } } - - GPR_TIMER_END("on_initial_header", 0); } static void on_trailing_header(void* tp, grpc_mdelem md) { - grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; - grpc_chttp2_stream* s = t->incoming_stream; - - GPR_TIMER_BEGIN("on_trailing_header", 0); + GPR_TIMER_SCOPE("on_trailing_header", 0); + grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(tp); + grpc_chttp2_stream* s = t->incoming_stream; GPR_ASSERT(s != nullptr); if (grpc_http_trace.enabled()) { @@ -526,8 +524,6 @@ static void on_trailing_header(void* tp, grpc_mdelem md) { GRPC_MDELEM_UNREF(md); } } - - GPR_TIMER_END("on_trailing_header", 0); } static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, @@ -640,7 +636,7 @@ static grpc_error* init_header_frame_parser(grpc_chttp2_transport* t, } t->hpack_parser.on_header_user_data = t; t->hpack_parser.is_boundary = is_eoh; - t->hpack_parser.is_eof = (uint8_t)(is_eoh ? t->header_eof : 0); + t->hpack_parser.is_eof = static_cast<uint8_t>(is_eoh ? t->header_eof : 0); if (!is_continuation && (t->incoming_frame_flags & GRPC_CHTTP2_FLAG_HAS_PRIORITY)) { grpc_chttp2_hpack_parser_set_has_priority(&t->hpack_parser); diff --git a/src/core/ext/transport/chttp2/transport/stream_map.cc b/src/core/ext/transport/chttp2/transport/stream_map.cc index e4f08f5a6c..a40eaffd5f 100644 --- a/src/core/ext/transport/chttp2/transport/stream_map.cc +++ b/src/core/ext/transport/chttp2/transport/stream_map.cc @@ -22,13 +22,14 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include <grpc/support/useful.h> void grpc_chttp2_stream_map_init(grpc_chttp2_stream_map* map, size_t initial_capacity) { GPR_ASSERT(initial_capacity > 1); - map->keys = (uint32_t*)gpr_malloc(sizeof(uint32_t) * initial_capacity); - map->values = (void**)gpr_malloc(sizeof(void*) * initial_capacity); + map->keys = + static_cast<uint32_t*>(gpr_malloc(sizeof(uint32_t) * initial_capacity)); + map->values = + static_cast<void**>(gpr_malloc(sizeof(void*) * initial_capacity)); map->count = 0; map->free = 0; map->capacity = initial_capacity; @@ -72,10 +73,10 @@ void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map* map, uint32_t key, /* resize when less than 25% of the table is free, because compaction won't help much */ map->capacity = capacity = 3 * capacity / 2; - map->keys = keys = - (uint32_t*)gpr_realloc(keys, capacity * sizeof(uint32_t)); + map->keys = keys = static_cast<uint32_t*>( + gpr_realloc(keys, capacity * sizeof(uint32_t))); map->values = values = - (void**)gpr_realloc(values, capacity * sizeof(void*)); + static_cast<void**>(gpr_realloc(values, capacity * sizeof(void*))); } } @@ -147,7 +148,7 @@ void* grpc_chttp2_stream_map_rand(grpc_chttp2_stream_map* map) { map->free = 0; GPR_ASSERT(map->count > 0); } - return map->values[((size_t)rand()) % map->count]; + return map->values[(static_cast<size_t>(rand())) % map->count]; } void grpc_chttp2_stream_map_for_each(grpc_chttp2_stream_map* map, diff --git a/src/core/ext/transport/chttp2/transport/varint.cc b/src/core/ext/transport/chttp2/transport/varint.cc index 0d94ddcbc3..621a8100c7 100644 --- a/src/core/ext/transport/chttp2/transport/varint.cc +++ b/src/core/ext/transport/chttp2/transport/varint.cc @@ -36,19 +36,19 @@ void grpc_chttp2_hpack_write_varint_tail(uint32_t tail_value, uint8_t* target, uint32_t tail_length) { switch (tail_length) { case 5: - target[4] = (uint8_t)((tail_value >> 28) | 0x80); + target[4] = static_cast<uint8_t>((tail_value >> 28) | 0x80); /* fallthrough */ case 4: - target[3] = (uint8_t)((tail_value >> 21) | 0x80); + target[3] = static_cast<uint8_t>((tail_value >> 21) | 0x80); /* fallthrough */ case 3: - target[2] = (uint8_t)((tail_value >> 14) | 0x80); + target[2] = static_cast<uint8_t>((tail_value >> 14) | 0x80); /* fallthrough */ case 2: - target[1] = (uint8_t)((tail_value >> 7) | 0x80); + target[1] = static_cast<uint8_t>((tail_value >> 7) | 0x80); /* fallthrough */ case 1: - target[0] = (uint8_t)((tail_value) | 0x80); + target[0] = static_cast<uint8_t>((tail_value) | 0x80); } target[tail_length - 1] &= 0x7f; } diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index 9a6f5e9bcf..42cba9ae60 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -83,11 +83,12 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) { "%s: Ping delayed [%p]: not enough time elapsed since last ping. " " Last ping %f: Next ping %f: Now %f", t->is_client ? "CLIENT" : "SERVER", t->peer_string, - (double)t->ping_state.last_ping_sent_time, - (double)next_allowed_ping, (double)now); + static_cast<double>(t->ping_state.last_ping_sent_time), + static_cast<double>(next_allowed_ping), static_cast<double>(now)); } if (!t->ping_state.is_delayed_ping_timer_set) { t->ping_state.is_delayed_ping_timer_set = true; + GRPC_CHTTP2_REF_TRANSPORT(t, "retry_initiate_ping_locked"); grpc_timer_init(&t->ping_state.delayed_ping_timer, next_allowed_ping, &t->retry_initiate_ping_locked); } @@ -146,7 +147,7 @@ static void report_stall(grpc_chttp2_transport* t, grpc_chttp2_stream* s, t->settings[GRPC_ACKED_SETTINGS] [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE], t->flow_control->remote_window(), - (uint32_t)GPR_MAX( + static_cast<uint32_t> GPR_MAX( 0, s->flow_control->remote_window_delta() + (int64_t)t->settings[GRPC_PEER_SETTINGS] @@ -180,7 +181,7 @@ class WriteContext { public: WriteContext(grpc_chttp2_transport* t) : t_(t) { GRPC_STATS_INC_HTTP2_WRITES_BEGUN(); - GPR_TIMER_BEGIN("grpc_chttp2_begin_write", 0); + GPR_TIMER_SCOPE("grpc_chttp2_begin_write", 0); } // TODO(ctiller): make this the destructor @@ -309,14 +310,14 @@ class DataSendContext { sending_bytes_before_(s_->sending_bytes) {} uint32_t stream_remote_window() const { - return (uint32_t)GPR_MAX( + return static_cast<uint32_t> GPR_MAX( 0, s_->flow_control->remote_window_delta() + (int64_t)t_->settings[GRPC_PEER_SETTINGS] [GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE]); } uint32_t max_outgoing() const { - return (uint32_t)GPR_MIN( + return static_cast<uint32_t> GPR_MIN( t_->settings[GRPC_PEER_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], GPR_MIN(stream_remote_window(), t_->flow_control->remote_window())); } @@ -324,8 +325,8 @@ class DataSendContext { bool AnyOutgoing() const { return max_outgoing() > 0; } void FlushCompressedBytes() { - uint32_t send_bytes = - (uint32_t)GPR_MIN(max_outgoing(), s_->compressed_data_buffer.length); + uint32_t send_bytes = static_cast<uint32_t> GPR_MIN( + max_outgoing(), s_->compressed_data_buffer.length); bool is_last_data_frame = (send_bytes == s_->compressed_data_buffer.length && s_->flow_controlled_buffer.length == 0 && @@ -374,10 +375,11 @@ class DataSendContext { bool is_last_frame() const { return is_last_frame_; } void CallCallbacks() { - if (update_list(t_, s_, - (int64_t)(s_->sending_bytes - sending_bytes_before_), - &s_->on_flow_controlled_cbs, - &s_->flow_controlled_bytes_flowed, GRPC_ERROR_NONE)) { + if (update_list( + t_, s_, + static_cast<int64_t>(s_->sending_bytes - sending_bytes_before_), + &s_->on_flow_controlled_cbs, &s_->flow_controlled_bytes_flowed, + GRPC_ERROR_NONE)) { write_context_->NoteScheduledResults(); } } @@ -614,24 +616,22 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write( maybe_initiate_ping(t); - GPR_TIMER_END("grpc_chttp2_begin_write", 0); - return ctx.Result(); } void grpc_chttp2_end_write(grpc_chttp2_transport* t, grpc_error* error) { - GPR_TIMER_BEGIN("grpc_chttp2_end_write", 0); + GPR_TIMER_SCOPE("grpc_chttp2_end_write", 0); grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_writing_stream(t, &s)) { if (s->sending_bytes != 0) { - update_list(t, s, (int64_t)s->sending_bytes, &s->on_write_finished_cbs, - &s->flow_controlled_bytes_written, GRPC_ERROR_REF(error)); + update_list(t, s, static_cast<int64_t>(s->sending_bytes), + &s->on_write_finished_cbs, &s->flow_controlled_bytes_written, + GRPC_ERROR_REF(error)); s->sending_bytes = 0; } GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:end"); } grpc_slice_buffer_reset_and_unref_internal(&t->outbuf); GRPC_ERROR_UNREF(error); - GPR_TIMER_END("grpc_chttp2_end_write", 0); } |