diff options
Diffstat (limited to 'src/core/ext/transport')
20 files changed, 221 insertions, 168 deletions
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 322fcb23e1..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 = - static_cast<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); } @@ -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(const_cast<grpc_channel_args*>(subchannel_args->args)); + grpc_channel_args_destroy( + const_cast<grpc_channel_args*>(subchannel_args->args)); gpr_free(subchannel_args); return s; } diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index c1e7946f5f..90b2ee1af9 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -79,7 +79,8 @@ static void server_connection_state_unref( } static void on_timeout(void* arg, grpc_error* error) { - server_connection_state* connection_state = static_cast<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) { @@ -92,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 = static_cast<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); } @@ -132,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 = reinterpret_cast<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, @@ -177,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 = - static_cast<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; diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.cc b/src/core/ext/transport/chttp2/transport/bin_decoder.cc index 0e5e4d0535..91980e6974 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.cc @@ -192,11 +192,12 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, } 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", - static_cast<int>(output_length), - static_cast<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 d9c095ede7..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 = reinterpret_cast<char*>GRPC_SLICE_START_PTR(output); + char* out = reinterpret_cast<char*> GRPC_SLICE_START_PTR(output); size_t i; /* encode full triplets */ @@ -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++ = static_cast<uint8_t>(static_cast<uint8_t>(temp << (8u - temp_length)) | - static_cast<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)); @@ -151,7 +152,8 @@ static void enc_add2(huff_out* out, uint8_t a, uint8_t b) { b64_huff_sym sb = huff_alphabet[b]; out->temp = (out->temp << (sa.length + 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); + out->temp_length += + static_cast<uint32_t>(sa.length) + static_cast<uint32_t>(sb.length); enc_flush_some(out); } @@ -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++ = static_cast<uint8_t>(static_cast<uint8_t>(out.temp << (8u - out.temp_length)) | - static_cast<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 ec5431bb00..ad8da94cb3 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -387,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, - static_cast<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)) { @@ -421,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 = static_cast<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); @@ -447,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 = - static_cast<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) { @@ -498,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 < static_cast<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]) { @@ -774,7 +774,8 @@ static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_chttp2_stream* grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport* t, uint32_t id) { - return static_cast<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, @@ -786,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*)static_cast<uintptr_t>(id)); + &t->base, + (void*)static_cast<uintptr_t>(id)); t->accepting_stream = nullptr; return accepting; } @@ -1100,7 +1102,7 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, current_keepalive_time_ms > INT_MAX / KEEPALIVE_TIME_BACKOFF_MULTIPLIER ? GRPC_MILLIS_INF_FUTURE : static_cast<grpc_millis>(current_keepalive_time_ms * - KEEPALIVE_TIME_BACKOFF_MULTIPLIER); + KEEPALIVE_TIME_BACKOFF_MULTIPLIER); } /* lie: use transient failure from the transport to indicate goaway has been @@ -1189,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, - 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)); + 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) { @@ -1239,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 += - static_cast<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); } @@ -1329,7 +1333,8 @@ static void perform_stream_op_locked(void* stream_op, grpc_transport_stream_op_batch* op = static_cast<grpc_transport_stream_op_batch*>(stream_op); - grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(op->handler_private.extra_arg); + 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; @@ -1409,7 +1414,8 @@ static void perform_stream_op_locked(void* stream_op, "exceeds peer limit"), GRPC_ERROR_INT_SIZE, static_cast<intptr_t>(metadata_size)), - GRPC_ERROR_INT_LIMIT, static_cast<intptr_t>(metadata_peer_limit)), + 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)) { @@ -1488,9 +1494,10 @@ static void perform_stream_op_locked(void* stream_op, 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 + - static_cast<int64_t>(s->flow_controlled_buffer.length) + - static_cast<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; @@ -1525,7 +1532,8 @@ static void perform_stream_op_locked(void* stream_op, "exceeds peer limit"), GRPC_ERROR_INT_SIZE, static_cast<intptr_t>(metadata_size)), - GRPC_ERROR_INT_LIMIT, static_cast<intptr_t>(metadata_peer_limit)), + 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)) { @@ -1690,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, static_cast<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); @@ -1925,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 = - static_cast<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; @@ -1978,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, static_cast<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); } } @@ -2180,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 += static_cast<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); @@ -2216,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 += static_cast<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)); @@ -2243,7 +2253,7 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, *p++ = static_cast<uint8_t>('0' + (grpc_status % 10)); } GPR_ASSERT(p == GRPC_SLICE_END_PTR(status_hdr)); - len += static_cast<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); @@ -2267,7 +2277,7 @@ 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 += static_cast<uint32_t>GRPC_SLICE_LENGTH(message_pfx); + len += static_cast<uint32_t> GRPC_SLICE_LENGTH(message_pfx); len += static_cast<uint32_t>(msg_len); hdr = GRPC_SLICE_MALLOC(9); @@ -2411,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( - static_cast<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]); } @@ -2876,7 +2886,7 @@ grpc_error* grpc_chttp2_incoming_byte_stream_push( grpc_slice_unref_internal(slice); return error; } else { - bs->remaining_bytes -= static_cast<uint32_t>GRPC_SLICE_LENGTH(slice); + bs->remaining_bytes -= static_cast<uint32_t> GRPC_SLICE_LENGTH(slice); if (slice_out != nullptr) { *slice_out = slice; } @@ -2931,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 = - static_cast<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; @@ -3000,8 +3010,8 @@ static void destructive_reclaimer_locked(void* arg, grpc_error* error) { 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 = - static_cast<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); @@ -3096,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 = - static_cast<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; } @@ -3105,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 = reinterpret_cast<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 e9014d8234..45b6f97b05 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -184,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 = static_cast<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 = static_cast<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; @@ -261,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 = static_cast<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; @@ -337,8 +338,8 @@ double TransportFlowControl::SmoothLogBdp(double value) { FlowControlAction::Urgency TransportFlowControl::DeltaUrgency( int64_t value, grpc_chttp2_setting_id setting_id) { - int64_t delta = - value - static_cast<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; @@ -357,7 +358,8 @@ 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_ = static_cast<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_, @@ -367,12 +369,13 @@ FlowControlAction TransportFlowControl::PeriodicUpdate() { // 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 = static_cast<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(static_cast<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 7800a55d40..b58027790d 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -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 static_cast<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 dd4830cc17..721f0a55a1 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.cc +++ b/src/core/ext/transport/chttp2/transport/frame_data.cc @@ -51,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, static_cast<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; } @@ -208,8 +208,8 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( if (cur != end) { grpc_slice_buffer_undo_take_first( - slices, - grpc_slice_sub(slice, static_cast<size_t>(cur - beg), static_cast<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; @@ -223,11 +223,12 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( 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, static_cast<size_t>(cur - beg), - static_cast<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; } @@ -243,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, static_cast<size_t>(cur - beg), - static_cast<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; @@ -259,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, static_cast<size_t>(cur - beg), - static_cast<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; @@ -275,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, static_cast<size_t>(cur - beg), static_cast<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 d712bc657e..70931ed22d 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.cc +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.cc @@ -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 = static_cast<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: @@ -128,7 +129,8 @@ grpc_error* grpc_chttp2_goaway_parser_parse(void* parser, /* fallthrough */ case GRPC_CHTTP2_GOAWAY_DEBUG: if (end != cur) - memcpy(p->debug_data + p->debug_pos, cur, static_cast<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 += static_cast<uint32_t>(end - cur); p->state = GRPC_CHTTP2_GOAWAY_DEBUG; @@ -151,7 +153,7 @@ 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 + static_cast<uint32_t>GRPC_SLICE_LENGTH(debug_data); + frame_length = 4 + 4 + static_cast<uint32_t> GRPC_SLICE_LENGTH(debug_data); /* frame header: length */ *p++ = static_cast<uint8_t>(frame_length >> 16); 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 0b2bc4baed..79528762e0 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc @@ -76,7 +76,8 @@ 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 = static_cast<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; diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index 2501ad9397..737a9382e0 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -110,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 = static_cast<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; @@ -211,8 +212,8 @@ 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 += - static_cast<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", diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index dc0e475aa1..4855455130 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -98,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, - 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))); + 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; } @@ -169,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 = - static_cast<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--; } @@ -197,7 +198,8 @@ 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] = static_cast<uint16_t>(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++; @@ -394,7 +396,7 @@ 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 = static_cast<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 = static_cast<uint32_t>(wire_value_length(value)); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); @@ -416,7 +418,7 @@ 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 = static_cast<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 = static_cast<uint32_t>(wire_value_length(value)); uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); @@ -583,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 = - static_cast<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++) { diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 4b512b6439..26a38e3f87 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -757,7 +757,8 @@ 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, static_cast<intptr_t>(p->index)), + 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); @@ -1227,9 +1228,10 @@ 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 = 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)); + 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); @@ -1448,7 +1450,8 @@ 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) >= static_cast<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; @@ -1503,7 +1506,8 @@ 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, static_cast<intptr_t>(p->index)), + 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)); @@ -1618,7 +1622,8 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { GPR_TIMER_SCOPE("grpc_chttp2_hpack_parser_parse", 0); - grpc_chttp2_hpack_parser* parser = static_cast<grpc_chttp2_hpack_parser*>(hpack_parser); + 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); } diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.cc b/src/core/ext/transport/chttp2/transport/hpack_table.cc index e8c44e35ab..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 = static_cast<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( @@ -225,7 +226,8 @@ static void evict1(grpc_chttp2_hptbl* tbl) { } static void rebuild_ents(grpc_chttp2_hptbl* tbl, uint32_t new_cap) { - grpc_mdelem* ents = static_cast<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 > static_cast<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); } @@ -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 = - static_cast<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/incoming_metadata.cc b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc index 2d06bb5038..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, - static_cast<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 d720397de5..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], - static_cast<int>(static_cast<uint8_t>(GRPC_CHTTP2_CLIENT_CONNECT_STRING[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 = - static_cast<grpc_chttp2_deframe_transport_state>(1 + static_cast<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; @@ -206,11 +207,11 @@ grpc_error* grpc_chttp2_perform_read(grpc_chttp2_transport* t, case GRPC_DTS_FRAME: GPR_ASSERT(cur < end); 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); + 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; } @@ -231,11 +232,11 @@ 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, static_cast<size_t>(cur - beg), - static_cast<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; } @@ -429,7 +430,8 @@ static void on_initial_header(void* tp, grpc_mdelem md) { } if (GRPC_MDELEM_IS_INTERNED(md)) { /* store the result */ - cached_timeout = static_cast<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); } diff --git a/src/core/ext/transport/chttp2/transport/stream_map.cc b/src/core/ext/transport/chttp2/transport/stream_map.cc index 045f868430..a40eaffd5f 100644 --- a/src/core/ext/transport/chttp2/transport/stream_map.cc +++ b/src/core/ext/transport/chttp2/transport/stream_map.cc @@ -26,8 +26,10 @@ void grpc_chttp2_stream_map_init(grpc_chttp2_stream_map* map, size_t initial_capacity) { GPR_ASSERT(initial_capacity > 1); - 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->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; @@ -71,8 +73,8 @@ 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 = - static_cast<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 = static_cast<void**>(gpr_realloc(values, capacity * sizeof(void*))); } diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index b5970fd646..42cba9ae60 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -147,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(), - static_cast<uint32_t>GPR_MAX( + static_cast<uint32_t> GPR_MAX( 0, s->flow_control->remote_window_delta() + (int64_t)t->settings[GRPC_PEER_SETTINGS] @@ -310,14 +310,14 @@ class DataSendContext { sending_bytes_before_(s_->sending_bytes) {} uint32_t stream_remote_window() const { - return static_cast<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 static_cast<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())); } @@ -325,8 +325,8 @@ class DataSendContext { bool AnyOutgoing() const { return max_outgoing() > 0; } void FlushCompressedBytes() { - uint32_t send_bytes = - static_cast<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 && @@ -375,10 +375,11 @@ class DataSendContext { bool is_last_frame() const { return is_last_frame_; } void CallCallbacks() { - 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)) { + 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(); } } @@ -624,8 +625,9 @@ void grpc_chttp2_end_write(grpc_chttp2_transport* t, grpc_error* error) { while (grpc_chttp2_list_pop_writing_stream(t, &s)) { if (s->sending_bytes != 0) { - 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)); + 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"); diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.cc b/src/core/ext/transport/cronet/transport/cronet_transport.cc index 3111b6db43..8904c122a7 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.cc +++ b/src/core/ext/transport/cronet/transport/cronet_transport.cc @@ -284,7 +284,8 @@ static void maybe_flush_read(stream_obj* s) { CRONET_LOG(GPR_DEBUG, "%p: Flush read", s); s->state.flush_read = true; null_and_maybe_free_read_buffer(s); - s->state.rs.read_buffer = static_cast<char*>(gpr_malloc(GRPC_FLUSH_READ_SIZE)); + s->state.rs.read_buffer = + static_cast<char*>(gpr_malloc(GRPC_FLUSH_READ_SIZE)); if (!s->state.pending_read_from_cronet) { CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs); bidirectional_stream_read(s->cbs, s->state.rs.read_buffer, @@ -309,8 +310,8 @@ static void add_to_storage(struct stream_obj* s, struct op_storage* storage = &s->storage; /* add new op at the beginning of the linked list. The memory is freed in remove_from_storage */ - struct op_and_state* new_op = - static_cast<struct op_and_state*>(gpr_malloc(sizeof(struct op_and_state))); + struct op_and_state* new_op = static_cast<struct op_and_state*>( + gpr_malloc(sizeof(struct op_and_state))); memcpy(&new_op->op, op, sizeof(grpc_transport_stream_op_batch)); memset(&new_op->state, 0, sizeof(new_op->state)); new_op->s = s; @@ -671,7 +672,8 @@ static void create_grpc_frame(grpc_slice_buffer* write_slice_buffer, size_t length = GRPC_SLICE_LENGTH(slice); *p_write_buffer_size = length + GRPC_HEADER_SIZE_IN_BYTES; /* This is freed in the on_write_completed callback */ - char* write_buffer = static_cast<char*>(gpr_malloc(length + GRPC_HEADER_SIZE_IN_BYTES)); + char* write_buffer = + static_cast<char*>(gpr_malloc(length + GRPC_HEADER_SIZE_IN_BYTES)); *pp_write_buffer = write_buffer; uint8_t* p = reinterpret_cast<uint8_t*>(write_buffer); /* Append 5 byte header */ @@ -1151,14 +1153,14 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { stream_state->rs.remaining_bytes == 0) { /* Start a read operation for data */ stream_state->rs.length_field_received = true; - parse_grpc_header(reinterpret_cast<const uint8_t*>(stream_state->rs.read_buffer), - &stream_state->rs.length_field, - &stream_state->rs.compressed); + parse_grpc_header( + reinterpret_cast<const uint8_t*>(stream_state->rs.read_buffer), + &stream_state->rs.length_field, &stream_state->rs.compressed); CRONET_LOG(GPR_DEBUG, "length field = %d", stream_state->rs.length_field); if (stream_state->rs.length_field > 0) { - stream_state->rs.read_buffer = - static_cast<char*>(gpr_malloc(static_cast<size_t>(stream_state->rs.length_field))); + stream_state->rs.read_buffer = static_cast<char*>( + gpr_malloc(static_cast<size_t>(stream_state->rs.length_field))); GPR_ASSERT(stream_state->rs.read_buffer); stream_state->rs.remaining_bytes = stream_state->rs.length_field; stream_state->rs.received_bytes = 0; @@ -1181,7 +1183,8 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { if (stream_state->rs.compressed) { stream_state->rs.sbs.base.flags |= GRPC_WRITE_INTERNAL_COMPRESS; } - *(reinterpret_cast<grpc_byte_buffer**>(stream_op->payload->recv_message.recv_message)) = + *(reinterpret_cast<grpc_byte_buffer**>( + stream_op->payload->recv_message.recv_message)) = reinterpret_cast<grpc_byte_buffer*>(&stream_state->rs.sbs); GRPC_CLOSURE_SCHED( stream_op->payload->recv_message.recv_message_ready, @@ -1237,7 +1240,8 @@ static enum e_op_result execute_stream_op(struct op_and_state* oas) { if (stream_state->rs.compressed) { stream_state->rs.sbs.base.flags = GRPC_WRITE_INTERNAL_COMPRESS; } - *(reinterpret_cast<grpc_byte_buffer**>(stream_op->payload->recv_message.recv_message)) = + *(reinterpret_cast<grpc_byte_buffer**>( + stream_op->payload->recv_message.recv_message)) = reinterpret_cast<grpc_byte_buffer*>(&stream_state->rs.sbs); GRPC_CLOSURE_SCHED(stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); @@ -1417,8 +1421,8 @@ static const grpc_transport_vtable grpc_cronet_vtable = { grpc_transport* grpc_create_cronet_transport(void* engine, const char* target, const grpc_channel_args* args, void* reserved) { - grpc_cronet_transport* ct = - static_cast<grpc_cronet_transport*>(gpr_malloc(sizeof(grpc_cronet_transport))); + grpc_cronet_transport* ct = static_cast<grpc_cronet_transport*>( + gpr_malloc(sizeof(grpc_cronet_transport))); if (!ct) { goto error; } diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index 97d908fa5d..2022eaffe5 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -208,8 +208,8 @@ static grpc_error* fill_in_metadata(inproc_stream* s, grpc_error* error = GRPC_ERROR_NONE; for (grpc_linked_mdelem* elem = metadata->list.head; (elem != nullptr) && (error == GRPC_ERROR_NONE); elem = elem->next) { - grpc_linked_mdelem* nelem = - static_cast<grpc_linked_mdelem*>(gpr_arena_alloc(s->arena, sizeof(*nelem))); + grpc_linked_mdelem* nelem = static_cast<grpc_linked_mdelem*>( + gpr_arena_alloc(s->arena, sizeof(*nelem))); nelem->md = grpc_mdelem_from_slices(grpc_slice_intern(GRPC_MDKEY(elem->md)), grpc_slice_intern(GRPC_MDVALUE(elem->md))); @@ -425,13 +425,13 @@ static void fail_helper_locked(inproc_stream* s, grpc_error* error) { // since it expects that as well as no error yet grpc_metadata_batch fake_md; grpc_metadata_batch_init(&fake_md); - grpc_linked_mdelem* path_md = - static_cast<grpc_linked_mdelem*>(gpr_arena_alloc(s->arena, sizeof(*path_md))); + grpc_linked_mdelem* path_md = static_cast<grpc_linked_mdelem*>( + gpr_arena_alloc(s->arena, sizeof(*path_md))); path_md->md = grpc_mdelem_from_slices(g_fake_path_key, g_fake_path_value); GPR_ASSERT(grpc_metadata_batch_link_tail(&fake_md, path_md) == GRPC_ERROR_NONE); - grpc_linked_mdelem* auth_md = - static_cast<grpc_linked_mdelem*>(gpr_arena_alloc(s->arena, sizeof(*auth_md))); + grpc_linked_mdelem* auth_md = static_cast<grpc_linked_mdelem*>( + gpr_arena_alloc(s->arena, sizeof(*auth_md))); auth_md->md = grpc_mdelem_from_slices(g_fake_auth_key, g_fake_auth_value); GPR_ASSERT(grpc_metadata_batch_link_tail(&fake_md, auth_md) == GRPC_ERROR_NONE); @@ -1151,8 +1151,10 @@ static void inproc_transports_create(grpc_transport** server_transport, grpc_transport** client_transport, const grpc_channel_args* client_args) { INPROC_LOG(GPR_DEBUG, "inproc_transports_create"); - inproc_transport* st = static_cast<inproc_transport*>(gpr_zalloc(sizeof(*st))); - inproc_transport* ct = static_cast<inproc_transport*>(gpr_zalloc(sizeof(*ct))); + inproc_transport* st = + static_cast<inproc_transport*>(gpr_zalloc(sizeof(*st))); + inproc_transport* ct = + static_cast<inproc_transport*>(gpr_zalloc(sizeof(*ct))); // Share one lock between both sides since both sides get affected st->mu = ct->mu = static_cast<shared_mu*>(gpr_malloc(sizeof(*st->mu))); gpr_mu_init(&st->mu->mu); |