diff options
Diffstat (limited to 'src/core/ext')
109 files changed, 4257 insertions, 4236 deletions
diff --git a/src/core/ext/census/grpc_context.cc b/src/core/ext/census/grpc_context.cc index 34eafcab8e..fb4fcb34a8 100644 --- a/src/core/ext/census/grpc_context.cc +++ b/src/core/ext/census/grpc_context.cc @@ -21,7 +21,7 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/call.h" -void grpc_census_call_set_context(grpc_call *call, census_context *context) { +void grpc_census_call_set_context(grpc_call* call, census_context* context) { GRPC_API_TRACE("grpc_census_call_set_context(call=%p, census_context=%p)", 2, (call, context)); if (context != NULL) { @@ -29,7 +29,7 @@ void grpc_census_call_set_context(grpc_call *call, census_context *context) { } } -census_context *grpc_census_call_get_context(grpc_call *call) { +census_context* grpc_census_call_get_context(grpc_call* call) { GRPC_API_TRACE("grpc_census_call_get_context(call=%p)", 1, (call)); - return (census_context *)grpc_call_context_get(call, GRPC_CONTEXT_TRACING); + return (census_context*)grpc_call_context_get(call, GRPC_CONTEXT_TRACING); } diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 31a8fc39ce..82a5edca93 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -29,9 +29,9 @@ #include "src/core/lib/surface/completion_queue.h" grpc_connectivity_state grpc_channel_check_connectivity_state( - grpc_channel *channel, int try_to_connect) { + grpc_channel* channel, int try_to_connect) { /* forward through to the underlying client channel */ - grpc_channel_element *client_channel_elem = + grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_connectivity_state state; @@ -66,15 +66,15 @@ typedef struct { grpc_closure watcher_timer_init; grpc_timer alarm; grpc_connectivity_state state; - grpc_completion_queue *cq; + grpc_completion_queue* cq; grpc_cq_completion completion_storage; - grpc_channel *channel; - grpc_error *error; - void *tag; + grpc_channel* channel; + grpc_error* error; + void* tag; } state_watcher; -static void delete_state_watcher(grpc_exec_ctx *exec_ctx, state_watcher *w) { - grpc_channel_element *client_channel_elem = grpc_channel_stack_last_element( +static void delete_state_watcher(grpc_exec_ctx* exec_ctx, state_watcher* w) { + grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element( grpc_channel_get_channel_stack(w->channel)); if (client_channel_elem->filter == &grpc_client_channel_filter) { GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, w->channel, @@ -86,10 +86,10 @@ static void delete_state_watcher(grpc_exec_ctx *exec_ctx, state_watcher *w) { gpr_free(w); } -static void finished_completion(grpc_exec_ctx *exec_ctx, void *pw, - grpc_cq_completion *ignored) { +static void finished_completion(grpc_exec_ctx* exec_ctx, void* pw, + grpc_cq_completion* ignored) { bool should_delete = false; - state_watcher *w = (state_watcher *)pw; + state_watcher* w = (state_watcher*)pw; gpr_mu_lock(&w->mu); switch (w->phase) { case WAITING: @@ -106,12 +106,12 @@ static void finished_completion(grpc_exec_ctx *exec_ctx, void *pw, } } -static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w, - bool due_to_completion, grpc_error *error) { +static void partly_done(grpc_exec_ctx* exec_ctx, state_watcher* w, + bool due_to_completion, grpc_error* error) { if (due_to_completion) { grpc_timer_cancel(exec_ctx, &w->alarm); } else { - grpc_channel_element *client_channel_elem = grpc_channel_stack_last_element( + grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element( grpc_channel_get_channel_stack(w->channel)); grpc_client_channel_watch_connectivity_state( exec_ctx, client_channel_elem, @@ -161,31 +161,31 @@ static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w, GRPC_ERROR_UNREF(error); } -static void watch_complete(grpc_exec_ctx *exec_ctx, void *pw, - grpc_error *error) { - partly_done(exec_ctx, (state_watcher *)pw, true, GRPC_ERROR_REF(error)); +static void watch_complete(grpc_exec_ctx* exec_ctx, void* pw, + grpc_error* error) { + partly_done(exec_ctx, (state_watcher*)pw, true, GRPC_ERROR_REF(error)); } -static void timeout_complete(grpc_exec_ctx *exec_ctx, void *pw, - grpc_error *error) { - partly_done(exec_ctx, (state_watcher *)pw, false, GRPC_ERROR_REF(error)); +static void timeout_complete(grpc_exec_ctx* exec_ctx, void* pw, + grpc_error* error) { + partly_done(exec_ctx, (state_watcher*)pw, false, GRPC_ERROR_REF(error)); } -int grpc_channel_num_external_connectivity_watchers(grpc_channel *channel) { - grpc_channel_element *client_channel_elem = +int grpc_channel_num_external_connectivity_watchers(grpc_channel* channel) { + grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); return grpc_client_channel_num_external_connectivity_watchers( client_channel_elem); } typedef struct watcher_timer_init_arg { - state_watcher *w; + state_watcher* w; gpr_timespec deadline; } watcher_timer_init_arg; -static void watcher_timer_init(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error_ignored) { - watcher_timer_init_arg *wa = (watcher_timer_init_arg *)arg; +static void watcher_timer_init(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error_ignored) { + watcher_timer_init_arg* wa = (watcher_timer_init_arg*)arg; grpc_timer_init(exec_ctx, &wa->w->alarm, grpc_timespec_to_millis_round_up(wa->deadline), @@ -193,19 +193,19 @@ static void watcher_timer_init(grpc_exec_ctx *exec_ctx, void *arg, gpr_free(wa); } -int grpc_channel_support_connectivity_watcher(grpc_channel *channel) { - grpc_channel_element *client_channel_elem = +int grpc_channel_support_connectivity_watcher(grpc_channel* channel) { + grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); return client_channel_elem->filter != &grpc_client_channel_filter ? 0 : 1; } void grpc_channel_watch_connectivity_state( - grpc_channel *channel, grpc_connectivity_state last_observed_state, - gpr_timespec deadline, grpc_completion_queue *cq, void *tag) { - grpc_channel_element *client_channel_elem = + grpc_channel* channel, grpc_connectivity_state last_observed_state, + gpr_timespec deadline, grpc_completion_queue* cq, void* tag) { + grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - state_watcher *w = (state_watcher *)gpr_malloc(sizeof(*w)); + state_watcher* w = (state_watcher*)gpr_malloc(sizeof(*w)); GRPC_API_TRACE( "grpc_channel_watch_connectivity_state(" @@ -213,8 +213,9 @@ void grpc_channel_watch_connectivity_state( "deadline=gpr_timespec { tv_sec: %" PRId64 ", tv_nsec: %d, clock_type: %d }, " "cq=%p, tag=%p)", - 7, (channel, (int)last_observed_state, deadline.tv_sec, deadline.tv_nsec, - (int)deadline.clock_type, cq, tag)); + 7, + (channel, (int)last_observed_state, deadline.tv_sec, deadline.tv_nsec, + (int)deadline.clock_type, cq, tag)); GPR_ASSERT(grpc_cq_begin_op(cq, tag)); @@ -230,8 +231,8 @@ void grpc_channel_watch_connectivity_state( w->channel = channel; w->error = NULL; - watcher_timer_init_arg *wa = - (watcher_timer_init_arg *)gpr_malloc(sizeof(watcher_timer_init_arg)); + watcher_timer_init_arg* wa = + (watcher_timer_init_arg*)gpr_malloc(sizeof(watcher_timer_init_arg)); wa->w = w; wa->deadline = deadline; GRPC_CLOSURE_INIT(&w->watcher_timer_init, watcher_timer_init, wa, diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 9eae6e02c9..584872bfc1 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -76,29 +76,29 @@ typedef struct { wait_for_ready_value wait_for_ready; } method_parameters; -static method_parameters *method_parameters_ref( - method_parameters *method_params) { +static method_parameters* method_parameters_ref( + method_parameters* method_params) { gpr_ref(&method_params->refs); return method_params; } -static void method_parameters_unref(method_parameters *method_params) { +static void method_parameters_unref(method_parameters* method_params) { if (gpr_unref(&method_params->refs)) { gpr_free(method_params); } } // Wrappers to pass to grpc_service_config_create_method_config_table(). -static void *method_parameters_ref_wrapper(void *value) { - return method_parameters_ref((method_parameters *)value); +static void* method_parameters_ref_wrapper(void* value) { + return method_parameters_ref((method_parameters*)value); } -static void method_parameters_unref_wrapper(grpc_exec_ctx *exec_ctx, - void *value) { - method_parameters_unref((method_parameters *)value); +static void method_parameters_unref_wrapper(grpc_exec_ctx* exec_ctx, + void* value) { + method_parameters_unref((method_parameters*)value); } -static bool parse_wait_for_ready(grpc_json *field, - wait_for_ready_value *wait_for_ready) { +static bool parse_wait_for_ready(grpc_json* field, + wait_for_ready_value* wait_for_ready) { if (field->type != GRPC_JSON_TRUE && field->type != GRPC_JSON_FALSE) { return false; } @@ -107,13 +107,13 @@ static bool parse_wait_for_ready(grpc_json *field, return true; } -static bool parse_timeout(grpc_json *field, grpc_millis *timeout) { +static bool parse_timeout(grpc_json* field, grpc_millis* timeout) { if (field->type != GRPC_JSON_STRING) return false; size_t len = strlen(field->value); if (field->value[len - 1] != 's') return false; - char *buf = gpr_strdup(field->value); + char* buf = gpr_strdup(field->value); buf[len - 1] = '\0'; // Remove trailing 's'. - char *decimal_point = strchr(buf, '.'); + char* decimal_point = strchr(buf, '.'); int nanos = 0; if (decimal_point != NULL) { *decimal_point = '\0'; @@ -138,10 +138,10 @@ static bool parse_timeout(grpc_json *field, grpc_millis *timeout) { return true; } -static void *method_parameters_create_from_json(const grpc_json *json) { +static void* method_parameters_create_from_json(const grpc_json* json) { wait_for_ready_value wait_for_ready = WAIT_FOR_READY_UNSET; grpc_millis timeout = 0; - for (grpc_json *field = json->child; field != NULL; field = field->next) { + for (grpc_json* field = json->child; field != NULL; field = field->next) { if (field->key == NULL) continue; if (strcmp(field->key, "waitForReady") == 0) { if (wait_for_ready != WAIT_FOR_READY_UNSET) return NULL; // Duplicate. @@ -151,8 +151,8 @@ static void *method_parameters_create_from_json(const grpc_json *json) { if (!parse_timeout(field, &timeout)) return NULL; } } - method_parameters *value = - (method_parameters *)gpr_malloc(sizeof(method_parameters)); + method_parameters* value = + (method_parameters*)gpr_malloc(sizeof(method_parameters)); gpr_ref_init(&value->refs, 1); value->timeout = timeout; value->wait_for_ready = wait_for_ready; @@ -167,24 +167,24 @@ struct external_connectivity_watcher; typedef struct client_channel_channel_data { /** resolver for this channel */ - grpc_resolver *resolver; + grpc_resolver* resolver; /** have we started resolving this channel */ bool started_resolving; /** is deadline checking enabled? */ bool deadline_checking_enabled; /** client channel factory */ - grpc_client_channel_factory *client_channel_factory; + grpc_client_channel_factory* client_channel_factory; /** combiner protecting all variables below in this data structure */ - grpc_combiner *combiner; + grpc_combiner* combiner; /** currently active load balancer */ - grpc_lb_policy *lb_policy; + grpc_lb_policy* lb_policy; /** retry throttle data */ - grpc_server_retry_throttle_data *retry_throttle_data; + grpc_server_retry_throttle_data* retry_throttle_data; /** maps method names to method_parameters structs */ - grpc_slice_hash_table *method_params_table; + grpc_slice_hash_table* method_params_table; /** incoming resolver result - set by resolver.next() */ - grpc_channel_args *resolver_result; + grpc_channel_args* resolver_result; /** a list of closures that are all waiting for resolver result to come in */ grpc_closure_list waiting_for_resolver_result_closures; /** resolver callback */ @@ -194,42 +194,42 @@ typedef struct client_channel_channel_data { /** when an lb_policy arrives, should we try to exit idle */ bool exit_idle_when_lb_policy_arrives; /** owning stack */ - grpc_channel_stack *owning_stack; + grpc_channel_stack* owning_stack; /** interested parties (owned) */ - grpc_pollset_set *interested_parties; + grpc_pollset_set* interested_parties; /* external_connectivity_watcher_list head is guarded by its own mutex, since * counts need to be grabbed immediately without polling on a cq */ gpr_mu external_connectivity_watcher_list_mu; - struct external_connectivity_watcher *external_connectivity_watcher_list_head; + struct external_connectivity_watcher* external_connectivity_watcher_list_head; /* the following properties are guarded by a mutex since API's require them to be instantaneously available */ gpr_mu info_mu; - char *info_lb_policy_name; + char* info_lb_policy_name; /** service config in JSON form */ - char *info_service_config_json; + char* info_service_config_json; } channel_data; /** We create one watcher for each new lb_policy that is returned from a resolver, to watch for state changes from the lb_policy. When a state change is seen, we update the channel, and create a new watcher. */ typedef struct { - channel_data *chand; + channel_data* chand; grpc_closure on_changed; grpc_connectivity_state state; - grpc_lb_policy *lb_policy; + grpc_lb_policy* lb_policy; } lb_policy_connectivity_watcher; -static void watch_lb_policy_locked(grpc_exec_ctx *exec_ctx, channel_data *chand, - grpc_lb_policy *lb_policy, +static void watch_lb_policy_locked(grpc_exec_ctx* exec_ctx, channel_data* chand, + grpc_lb_policy* lb_policy, grpc_connectivity_state current_state); -static void set_channel_connectivity_state_locked(grpc_exec_ctx *exec_ctx, - channel_data *chand, +static void set_channel_connectivity_state_locked(grpc_exec_ctx* exec_ctx, + channel_data* chand, grpc_connectivity_state state, - grpc_error *error, - const char *reason) { + grpc_error* error, + const char* reason) { /* TODO: Improve failure handling: * - Make it possible for policies to return GRPC_CHANNEL_TRANSIENT_FAILURE. * - Hand over pending picks from old policies during the switch that happens @@ -256,9 +256,9 @@ static void set_channel_connectivity_state_locked(grpc_exec_ctx *exec_ctx, reason); } -static void on_lb_policy_state_changed_locked(grpc_exec_ctx *exec_ctx, - void *arg, grpc_error *error) { - lb_policy_connectivity_watcher *w = (lb_policy_connectivity_watcher *)arg; +static void on_lb_policy_state_changed_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { + lb_policy_connectivity_watcher* w = (lb_policy_connectivity_watcher*)arg; grpc_connectivity_state publish_state = w->state; /* check if the notification is for the latest policy */ if (w->lb_policy == w->chand->lb_policy) { @@ -282,11 +282,11 @@ static void on_lb_policy_state_changed_locked(grpc_exec_ctx *exec_ctx, gpr_free(w); } -static void watch_lb_policy_locked(grpc_exec_ctx *exec_ctx, channel_data *chand, - grpc_lb_policy *lb_policy, +static void watch_lb_policy_locked(grpc_exec_ctx* exec_ctx, channel_data* chand, + grpc_lb_policy* lb_policy, grpc_connectivity_state current_state) { - lb_policy_connectivity_watcher *w = - (lb_policy_connectivity_watcher *)gpr_malloc(sizeof(*w)); + lb_policy_connectivity_watcher* w = + (lb_policy_connectivity_watcher*)gpr_malloc(sizeof(*w)); GRPC_CHANNEL_STACK_REF(chand->owning_stack, "watch_lb_policy"); w->chand = chand; GRPC_CLOSURE_INIT(&w->on_changed, on_lb_policy_state_changed_locked, w, @@ -297,8 +297,8 @@ static void watch_lb_policy_locked(grpc_exec_ctx *exec_ctx, channel_data *chand, &w->on_changed); } -static void start_resolving_locked(grpc_exec_ctx *exec_ctx, - channel_data *chand) { +static void start_resolving_locked(grpc_exec_ctx* exec_ctx, + channel_data* chand) { if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p: starting name resolution", chand); } @@ -310,19 +310,19 @@ static void start_resolving_locked(grpc_exec_ctx *exec_ctx, } typedef struct { - char *server_name; - grpc_server_retry_throttle_data *retry_throttle_data; + char* server_name; + grpc_server_retry_throttle_data* retry_throttle_data; } service_config_parsing_state; -static void parse_retry_throttle_params(const grpc_json *field, void *arg) { - service_config_parsing_state *parsing_state = - (service_config_parsing_state *)arg; +static void parse_retry_throttle_params(const grpc_json* field, void* arg) { + service_config_parsing_state* parsing_state = + (service_config_parsing_state*)arg; if (strcmp(field->key, "retryThrottling") == 0) { if (parsing_state->retry_throttle_data != NULL) return; // Duplicate. if (field->type != GRPC_JSON_OBJECT) return; int max_milli_tokens = 0; int milli_token_ratio = 0; - for (grpc_json *sub_field = field->child; sub_field != NULL; + for (grpc_json* sub_field = field->child; sub_field != NULL; sub_field = sub_field->next) { if (sub_field->key == NULL) return; if (strcmp(sub_field->key, "maxTokens") == 0) { @@ -338,7 +338,7 @@ static void parse_retry_throttle_params(const grpc_json *field, void *arg) { size_t whole_len = strlen(sub_field->value); uint32_t multiplier = 1; uint32_t decimal_value = 0; - const char *decimal_point = strchr(sub_field->value, '.'); + const char* decimal_point = strchr(sub_field->value, '.'); if (decimal_point != NULL) { whole_len = (size_t)(decimal_point - sub_field->value); multiplier = 1000; @@ -369,25 +369,25 @@ static void parse_retry_throttle_params(const grpc_json *field, void *arg) { } } -static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx, - void *arg, grpc_error *error) { - channel_data *chand = (channel_data *)arg; +static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { + channel_data* chand = (channel_data*)arg; if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p: got resolver result: error=%s", chand, grpc_error_string(error)); } // Extract the following fields from the resolver result, if non-NULL. bool lb_policy_updated = false; - char *lb_policy_name_dup = NULL; + char* lb_policy_name_dup = NULL; bool lb_policy_name_changed = false; - grpc_lb_policy *new_lb_policy = NULL; - char *service_config_json = NULL; - grpc_server_retry_throttle_data *retry_throttle_data = NULL; - grpc_slice_hash_table *method_params_table = NULL; + grpc_lb_policy* new_lb_policy = NULL; + char* service_config_json = NULL; + grpc_server_retry_throttle_data* retry_throttle_data = NULL; + grpc_slice_hash_table* method_params_table = NULL; if (chand->resolver_result != NULL) { // Find LB policy name. - const char *lb_policy_name = NULL; - const grpc_arg *channel_arg = + const char* lb_policy_name = NULL; + const grpc_arg* channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_POLICY_NAME); if (channel_arg != NULL) { GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); @@ -398,8 +398,8 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx, channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_ADDRESSES); if (channel_arg != NULL && channel_arg->type == GRPC_ARG_POINTER) { - grpc_lb_addresses *addresses = - (grpc_lb_addresses *)channel_arg->value.pointer.p; + grpc_lb_addresses* addresses = + (grpc_lb_addresses*)channel_arg->value.pointer.p; bool found_balancer_address = false; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (addresses->addresses[i].is_balancer) { @@ -450,14 +450,14 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx, if (channel_arg != NULL) { GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); service_config_json = gpr_strdup(channel_arg->value.string); - grpc_service_config *service_config = + grpc_service_config* service_config = grpc_service_config_create(service_config_json); if (service_config != NULL) { channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_SERVER_URI); GPR_ASSERT(channel_arg != NULL); GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); - grpc_uri *uri = + grpc_uri* uri = grpc_uri_parse(exec_ctx, channel_arg->value.string, true); GPR_ASSERT(uri->path[0] != '\0'); service_config_parsing_state parsing_state; @@ -560,7 +560,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx, &chand->waiting_for_resolver_result_closures); } else { // Not shutting down. grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; - grpc_error *state_error = + grpc_error* state_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("No load balancing policy"); if (new_lb_policy != NULL) { if (GRPC_TRACER_ON(grpc_client_channel_trace)) { @@ -592,12 +592,12 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx, } } -static void start_transport_op_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error_ignored) { - grpc_transport_op *op = (grpc_transport_op *)arg; - grpc_channel_element *elem = - (grpc_channel_element *)op->handler_private.extra_arg; - channel_data *chand = (channel_data *)elem->channel_data; +static void start_transport_op_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error_ignored) { + grpc_transport_op* op = (grpc_transport_op*)arg; + grpc_channel_element* elem = + (grpc_channel_element*)op->handler_private.extra_arg; + channel_data* chand = (channel_data*)elem->channel_data; if (op->on_connectivity_state_change != NULL) { grpc_connectivity_state_notify_on_state_change( @@ -648,10 +648,10 @@ static void start_transport_op_locked(grpc_exec_ctx *exec_ctx, void *arg, GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); } -static void cc_start_transport_op(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_transport_op *op) { - channel_data *chand = (channel_data *)elem->channel_data; +static void cc_start_transport_op(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + grpc_transport_op* op) { + channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(op->set_accept_stream == false); if (op->bind_pollset != NULL) { @@ -668,10 +668,10 @@ static void cc_start_transport_op(grpc_exec_ctx *exec_ctx, GRPC_ERROR_NONE); } -static void cc_get_channel_info(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - const grpc_channel_info *info) { - channel_data *chand = (channel_data *)elem->channel_data; +static void cc_get_channel_info(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + const grpc_channel_info* info) { + channel_data* chand = (channel_data*)elem->channel_data; gpr_mu_lock(&chand->info_mu); if (info->lb_policy_name != NULL) { *info->lb_policy_name = chand->info_lb_policy_name == NULL @@ -688,10 +688,10 @@ static void cc_get_channel_info(grpc_exec_ctx *exec_ctx, } /* Constructor for channel_data */ -static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_channel_element_args *args) { - channel_data *chand = (channel_data *)elem->channel_data; +static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + grpc_channel_element_args* args) { + channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(args->is_last); GPR_ASSERT(elem->filter == &grpc_client_channel_filter); // Initialize data members. @@ -712,7 +712,7 @@ static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx, "client_channel"); grpc_client_channel_start_backup_polling(exec_ctx, chand->interested_parties); // Record client channel factory. - const grpc_arg *arg = grpc_channel_args_find(args->channel_args, + const grpc_arg* arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_CLIENT_CHANNEL_FACTORY); if (arg == NULL) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( @@ -723,9 +723,9 @@ static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx, "client channel factory arg must be a pointer"); } grpc_client_channel_factory_ref( - (grpc_client_channel_factory *)arg->value.pointer.p); + (grpc_client_channel_factory*)arg->value.pointer.p); chand->client_channel_factory = - (grpc_client_channel_factory *)arg->value.pointer.p; + (grpc_client_channel_factory*)arg->value.pointer.p; // Get server name to resolve, using proxy mapper if needed. arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVER_URI); if (arg == NULL) { @@ -736,8 +736,8 @@ static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "server uri arg must be a string"); } - char *proxy_name = NULL; - grpc_channel_args *new_args = NULL; + char* proxy_name = NULL; + grpc_channel_args* new_args = NULL; grpc_proxy_mappers_map_name(exec_ctx, arg->value.string, args->channel_args, &proxy_name, &new_args); // Instantiate resolver. @@ -755,21 +755,22 @@ static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -static void shutdown_resolver_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_resolver *resolver = (grpc_resolver *)arg; +static void shutdown_resolver_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_resolver* resolver = (grpc_resolver*)arg; grpc_resolver_shutdown_locked(exec_ctx, resolver); GRPC_RESOLVER_UNREF(exec_ctx, resolver, "channel"); } /* Destructor for channel_data */ -static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem) { - channel_data *chand = (channel_data *)elem->channel_data; +static void cc_destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { + channel_data* chand = (channel_data*)elem->channel_data; if (chand->resolver != NULL) { GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE(shutdown_resolver_locked, chand->resolver, - grpc_combiner_scheduler(chand->combiner)), + exec_ctx, + GRPC_CLOSURE_CREATE(shutdown_resolver_locked, chand->resolver, + grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); } if (chand->client_channel_factory != NULL) { @@ -829,45 +830,45 @@ typedef struct client_channel_call_data { grpc_slice path; // Request path. gpr_timespec call_start_time; grpc_millis deadline; - gpr_arena *arena; - grpc_call_stack *owning_call; - grpc_call_combiner *call_combiner; + gpr_arena* arena; + grpc_call_stack* owning_call; + grpc_call_combiner* call_combiner; - grpc_server_retry_throttle_data *retry_throttle_data; - method_parameters *method_params; + grpc_server_retry_throttle_data* retry_throttle_data; + method_parameters* method_params; - grpc_subchannel_call *subchannel_call; - grpc_error *error; + grpc_subchannel_call* subchannel_call; + grpc_error* error; - grpc_lb_policy *lb_policy; // Holds ref while LB pick is pending. + grpc_lb_policy* lb_policy; // Holds ref while LB pick is pending. grpc_closure lb_pick_closure; grpc_closure lb_pick_cancel_closure; - grpc_connected_subchannel *connected_subchannel; + grpc_connected_subchannel* connected_subchannel; grpc_call_context_element subchannel_call_context[GRPC_CONTEXT_COUNT]; - grpc_polling_entity *pollent; + grpc_polling_entity* pollent; - grpc_transport_stream_op_batch *waiting_for_pick_batches[MAX_WAITING_BATCHES]; + grpc_transport_stream_op_batch* waiting_for_pick_batches[MAX_WAITING_BATCHES]; size_t waiting_for_pick_batches_count; grpc_closure handle_pending_batch_in_call_combiner[MAX_WAITING_BATCHES]; - grpc_transport_stream_op_batch *initial_metadata_batch; + grpc_transport_stream_op_batch* initial_metadata_batch; grpc_linked_mdelem lb_token_mdelem; grpc_closure on_complete; - grpc_closure *original_on_complete; + grpc_closure* original_on_complete; } call_data; -grpc_subchannel_call *grpc_client_channel_get_subchannel_call( - grpc_call_element *elem) { - call_data *calld = (call_data *)elem->call_data; +grpc_subchannel_call* grpc_client_channel_get_subchannel_call( + grpc_call_element* elem) { + call_data* calld = (call_data*)elem->call_data; return calld->subchannel_call; } // This is called via the call combiner, so access to calld is synchronized. static void waiting_for_pick_batches_add( - call_data *calld, grpc_transport_stream_op_batch *batch) { + call_data* calld, grpc_transport_stream_op_batch* batch) { if (batch->send_initial_metadata) { GPR_ASSERT(calld->initial_metadata_batch == NULL); calld->initial_metadata_batch = batch; @@ -879,9 +880,9 @@ static void waiting_for_pick_batches_add( } // This is called via the call combiner, so access to calld is synchronized. -static void fail_pending_batch_in_call_combiner(grpc_exec_ctx *exec_ctx, - void *arg, grpc_error *error) { - call_data *calld = (call_data *)arg; +static void fail_pending_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { + call_data* calld = (call_data*)arg; if (calld->waiting_for_pick_batches_count > 0) { --calld->waiting_for_pick_batches_count; grpc_transport_stream_op_batch_finish_with_failure( @@ -892,10 +893,10 @@ static void fail_pending_batch_in_call_combiner(grpc_exec_ctx *exec_ctx, } // This is called via the call combiner, so access to calld is synchronized. -static void waiting_for_pick_batches_fail(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_error *error) { - call_data *calld = (call_data *)elem->call_data; +static void waiting_for_pick_batches_fail(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_error* error) { + call_data* calld = (call_data*)elem->call_data; if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: failing %" PRIuPTR " pending batches: %s", @@ -923,9 +924,9 @@ static void waiting_for_pick_batches_fail(grpc_exec_ctx *exec_ctx, } // This is called via the call combiner, so access to calld is synchronized. -static void run_pending_batch_in_call_combiner(grpc_exec_ctx *exec_ctx, - void *arg, grpc_error *ignored) { - call_data *calld = (call_data *)arg; +static void run_pending_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* ignored) { + call_data* calld = (call_data*)arg; if (calld->waiting_for_pick_batches_count > 0) { --calld->waiting_for_pick_batches_count; grpc_subchannel_call_process_op( @@ -935,13 +936,14 @@ static void run_pending_batch_in_call_combiner(grpc_exec_ctx *exec_ctx, } // This is called via the call combiner, so access to calld is synchronized. -static void waiting_for_pick_batches_resume(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) { - channel_data *chand = (channel_data *)elem->channel_data; - call_data *calld = (call_data *)elem->call_data; +static void waiting_for_pick_batches_resume(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { + channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = (call_data*)elem->call_data; if (GRPC_TRACER_ON(grpc_client_channel_trace)) { - gpr_log(GPR_DEBUG, "chand=%p calld=%p: sending %" PRIuPTR - " pending batches to subchannel_call=%p", + gpr_log(GPR_DEBUG, + "chand=%p calld=%p: sending %" PRIuPTR + " pending batches to subchannel_call=%p", chand, calld, calld->waiting_for_pick_batches_count, calld->subchannel_call); } @@ -961,10 +963,10 @@ static void waiting_for_pick_batches_resume(grpc_exec_ctx *exec_ctx, // Applies service config to the call. Must be invoked once we know // that the resolver has returned results to the channel. -static void apply_service_config_to_call_locked(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) { - channel_data *chand = (channel_data *)elem->channel_data; - call_data *calld = (call_data *)elem->call_data; +static void apply_service_config_to_call_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { + channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = (call_data*)elem->call_data; if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: applying service config to call", chand, calld); @@ -974,7 +976,7 @@ static void apply_service_config_to_call_locked(grpc_exec_ctx *exec_ctx, grpc_server_retry_throttle_data_ref(chand->retry_throttle_data); } if (chand->method_params_table != NULL) { - calld->method_params = (method_parameters *)grpc_method_config_table_get( + calld->method_params = (method_parameters*)grpc_method_config_table_get( exec_ctx, chand->method_params_table, calld->path); if (calld->method_params != NULL) { method_parameters_ref(calld->method_params); @@ -994,11 +996,11 @@ static void apply_service_config_to_call_locked(grpc_exec_ctx *exec_ctx, } } -static void create_subchannel_call_locked(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_error *error) { - channel_data *chand = (channel_data *)elem->channel_data; - call_data *calld = (call_data *)elem->call_data; +static void create_subchannel_call_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_error* error) { + channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = (call_data*)elem->call_data; const grpc_connected_subchannel_call_args call_args = { calld->pollent, // pollent calld->path, // path @@ -1008,7 +1010,7 @@ static void create_subchannel_call_locked(grpc_exec_ctx *exec_ctx, calld->subchannel_call_context, // context calld->call_combiner // call_combiner }; - grpc_error *new_error = grpc_connected_subchannel_create_call( + grpc_error* new_error = grpc_connected_subchannel_create_call( exec_ctx, calld->connected_subchannel, &call_args, &calld->subchannel_call); if (GRPC_TRACER_ON(grpc_client_channel_trace)) { @@ -1025,10 +1027,10 @@ static void create_subchannel_call_locked(grpc_exec_ctx *exec_ctx, } // Invoked when a pick is completed, on both success or failure. -static void pick_done_locked(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_error *error) { - call_data *calld = (call_data *)elem->call_data; - channel_data *chand = (channel_data *)elem->channel_data; +static void pick_done_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_error* error) { + call_data* calld = (call_data*)elem->call_data; + channel_data* chand = (channel_data*)elem->channel_data; if (calld->connected_subchannel == NULL) { // Failed to create subchannel. GRPC_ERROR_UNREF(calld->error); @@ -1054,10 +1056,10 @@ static void pick_done_locked(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, // either (a) the pick was deferred pending a resolver result or (b) the // pick was done asynchronously. Removes the call's polling entity from // chand->interested_parties before invoking pick_done_locked(). -static void async_pick_done_locked(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, grpc_error *error) { - channel_data *chand = (channel_data *)elem->channel_data; - call_data *calld = (call_data *)elem->call_data; +static void async_pick_done_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, grpc_error* error) { + channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = (call_data*)elem->call_data; grpc_polling_entity_del_from_pollset_set(exec_ctx, calld->pollent, chand->interested_parties); pick_done_locked(exec_ctx, elem, error); @@ -1065,11 +1067,11 @@ static void async_pick_done_locked(grpc_exec_ctx *exec_ctx, // Note: This runs under the client_channel combiner, but will NOT be // holding the call combiner. -static void pick_callback_cancel_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_call_element *elem = (grpc_call_element *)arg; - channel_data *chand = (channel_data *)elem->channel_data; - call_data *calld = (call_data *)elem->call_data; +static void pick_callback_cancel_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_call_element* elem = (grpc_call_element*)arg; + channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = (call_data*)elem->call_data; if (calld->lb_policy != NULL) { if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: cancelling pick from LB policy %p", @@ -1084,11 +1086,11 @@ static void pick_callback_cancel_locked(grpc_exec_ctx *exec_ctx, void *arg, // Callback invoked by grpc_lb_policy_pick_locked() for async picks. // Unrefs the LB policy and invokes async_pick_done_locked(). -static void pick_callback_done_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_call_element *elem = (grpc_call_element *)arg; - channel_data *chand = (channel_data *)elem->channel_data; - call_data *calld = (call_data *)elem->call_data; +static void pick_callback_done_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_call_element* elem = (grpc_call_element*)arg; + channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = (call_data*)elem->call_data; if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed asynchronously", chand, calld); @@ -1102,10 +1104,10 @@ static void pick_callback_done_locked(grpc_exec_ctx *exec_ctx, void *arg, // Takes a ref to chand->lb_policy and calls grpc_lb_policy_pick_locked(). // If the pick was completed synchronously, unrefs the LB policy and // returns true. -static bool pick_callback_start_locked(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) { - channel_data *chand = (channel_data *)elem->channel_data; - call_data *calld = (call_data *)elem->call_data; +static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { + channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = (call_data*)elem->call_data; if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: starting pick on lb_policy=%p", chand, calld, chand->lb_policy); @@ -1162,7 +1164,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx *exec_ctx, } typedef struct { - grpc_call_element *elem; + grpc_call_element* elem; bool finished; grpc_closure closure; grpc_closure cancel_closure; @@ -1170,11 +1172,10 @@ typedef struct { // Note: This runs under the client_channel combiner, but will NOT be // holding the call combiner. -static void pick_after_resolver_result_cancel_locked(grpc_exec_ctx *exec_ctx, - void *arg, - grpc_error *error) { - pick_after_resolver_result_args *args = - (pick_after_resolver_result_args *)arg; +static void pick_after_resolver_result_cancel_locked(grpc_exec_ctx* exec_ctx, + void* arg, + grpc_error* error) { + pick_after_resolver_result_args* args = (pick_after_resolver_result_args*)arg; if (args->finished) { gpr_free(args); return; @@ -1187,9 +1188,9 @@ static void pick_after_resolver_result_cancel_locked(grpc_exec_ctx *exec_ctx, // is called, it will be a no-op. We also immediately invoke // async_pick_done_locked() to propagate the error back to the caller. args->finished = true; - grpc_call_element *elem = args->elem; - channel_data *chand = (channel_data *)elem->channel_data; - call_data *calld = (call_data *)elem->call_data; + grpc_call_element* elem = args->elem; + channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = (call_data*)elem->call_data; if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: cancelling pick waiting for resolver result", @@ -1205,14 +1206,13 @@ static void pick_after_resolver_result_cancel_locked(grpc_exec_ctx *exec_ctx, "Pick cancelled", &error, 1)); } -static void pick_after_resolver_result_start_locked(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem); +static void pick_after_resolver_result_start_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem); -static void pick_after_resolver_result_done_locked(grpc_exec_ctx *exec_ctx, - void *arg, - grpc_error *error) { - pick_after_resolver_result_args *args = - (pick_after_resolver_result_args *)arg; +static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, + void* arg, + grpc_error* error) { + pick_after_resolver_result_args* args = (pick_after_resolver_result_args*)arg; if (args->finished) { /* cancelled, do nothing */ if (GRPC_TRACER_ON(grpc_client_channel_trace)) { @@ -1222,9 +1222,9 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx *exec_ctx, return; } args->finished = true; - grpc_call_element *elem = args->elem; - channel_data *chand = (channel_data *)elem->channel_data; - call_data *calld = (call_data *)elem->call_data; + grpc_call_element* elem = args->elem; + channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = (call_data*)elem->call_data; if (error != GRPC_ERROR_NONE) { if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver failed to return data", @@ -1271,17 +1271,17 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx *exec_ctx, } } -static void pick_after_resolver_result_start_locked(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) { - channel_data *chand = (channel_data *)elem->channel_data; - call_data *calld = (call_data *)elem->call_data; +static void pick_after_resolver_result_start_locked(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { + channel_data* chand = (channel_data*)elem->channel_data; + call_data* calld = (call_data*)elem->call_data; if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: deferring pick pending resolver result", chand, calld); } - pick_after_resolver_result_args *args = - (pick_after_resolver_result_args *)gpr_zalloc(sizeof(*args)); + pick_after_resolver_result_args* args = + (pick_after_resolver_result_args*)gpr_zalloc(sizeof(*args)); args->elem = elem; GRPC_CLOSURE_INIT(&args->closure, pick_after_resolver_result_done_locked, args, grpc_combiner_scheduler(chand->combiner)); @@ -1294,11 +1294,11 @@ static void pick_after_resolver_result_start_locked(grpc_exec_ctx *exec_ctx, grpc_combiner_scheduler(chand->combiner))); } -static void start_pick_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *ignored) { - grpc_call_element *elem = (grpc_call_element *)arg; - call_data *calld = (call_data *)elem->call_data; - channel_data *chand = (channel_data *)elem->channel_data; +static void start_pick_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* ignored) { + grpc_call_element* elem = (grpc_call_element*)arg; + call_data* calld = (call_data*)elem->call_data; + channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(calld->connected_subchannel == NULL); if (chand->lb_policy != NULL) { // We already have an LB policy, so ask it for a pick. @@ -1328,9 +1328,9 @@ static void start_pick_locked(grpc_exec_ctx *exec_ctx, void *arg, chand->interested_parties); } -static void on_complete(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - grpc_call_element *elem = (grpc_call_element *)arg; - call_data *calld = (call_data *)elem->call_data; +static void on_complete(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + grpc_call_element* elem = (grpc_call_element*)arg; + call_data* calld = (call_data*)elem->call_data; if (calld->retry_throttle_data != NULL) { if (error == GRPC_ERROR_NONE) { grpc_server_retry_throttle_data_record_success( @@ -1349,10 +1349,10 @@ static void on_complete(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { } static void cc_start_transport_stream_op_batch( - grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_transport_stream_op_batch *batch) { - call_data *calld = (call_data *)elem->call_data; - channel_data *chand = (channel_data *)elem->channel_data; + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { + call_data* calld = (call_data*)elem->call_data; + channel_data* chand = (channel_data*)elem->channel_data; if (chand->deadline_checking_enabled) { grpc_deadline_state_client_start_transport_stream_op_batch(exec_ctx, elem, batch); @@ -1443,11 +1443,11 @@ done: } /* Constructor for call_data */ -static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_element_args *args) { - call_data *calld = (call_data *)elem->call_data; - channel_data *chand = (channel_data *)elem->channel_data; +static grpc_error* cc_init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + const grpc_call_element_args* args) { + call_data* calld = (call_data*)elem->call_data; + channel_data* chand = (channel_data*)elem->channel_data; // Initialize data members. calld->path = grpc_slice_ref_internal(args->path); calld->call_start_time = args->start_time; @@ -1463,12 +1463,12 @@ static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, } /* Destructor for call_data */ -static void cc_destroy_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_final_info *final_info, - grpc_closure *then_schedule_closure) { - call_data *calld = (call_data *)elem->call_data; - channel_data *chand = (channel_data *)elem->channel_data; +static void cc_destroy_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* then_schedule_closure) { + call_data* calld = (call_data*)elem->call_data; + channel_data* chand = (channel_data*)elem->channel_data; if (chand->deadline_checking_enabled) { grpc_deadline_state_destroy(exec_ctx, elem); } @@ -1499,10 +1499,10 @@ static void cc_destroy_call_elem(grpc_exec_ctx *exec_ctx, GRPC_CLOSURE_SCHED(exec_ctx, then_schedule_closure, GRPC_ERROR_NONE); } -static void cc_set_pollset_or_pollset_set(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_polling_entity *pollent) { - call_data *calld = (call_data *)elem->call_data; +static void cc_set_pollset_or_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_polling_entity* pollent) { + call_data* calld = (call_data*)elem->call_data; calld->pollent = pollent; } @@ -1524,9 +1524,9 @@ const grpc_channel_filter grpc_client_channel_filter = { "client-channel", }; -static void try_to_connect_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error_ignored) { - channel_data *chand = (channel_data *)arg; +static void try_to_connect_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error_ignored) { + channel_data* chand = (channel_data*)arg; if (chand->lb_policy != NULL) { grpc_lb_policy_exit_idle_locked(exec_ctx, chand->lb_policy); } else { @@ -1539,34 +1539,35 @@ static void try_to_connect_locked(grpc_exec_ctx *exec_ctx, void *arg, } grpc_connectivity_state grpc_client_channel_check_connectivity_state( - grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, int try_to_connect) { - channel_data *chand = (channel_data *)elem->channel_data; + grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, int try_to_connect) { + channel_data* chand = (channel_data*)elem->channel_data; grpc_connectivity_state out = grpc_connectivity_state_check(&chand->state_tracker); if (out == GRPC_CHANNEL_IDLE && try_to_connect) { GRPC_CHANNEL_STACK_REF(chand->owning_stack, "try_to_connect"); GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_CREATE(try_to_connect_locked, chand, - grpc_combiner_scheduler(chand->combiner)), + exec_ctx, + GRPC_CLOSURE_CREATE(try_to_connect_locked, chand, + grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); } return out; } typedef struct external_connectivity_watcher { - channel_data *chand; + channel_data* chand; grpc_polling_entity pollent; - grpc_closure *on_complete; - grpc_closure *watcher_timer_init; - grpc_connectivity_state *state; + grpc_closure* on_complete; + grpc_closure* watcher_timer_init; + grpc_connectivity_state* state; grpc_closure my_closure; - struct external_connectivity_watcher *next; + struct external_connectivity_watcher* next; } external_connectivity_watcher; -static external_connectivity_watcher *lookup_external_connectivity_watcher( - channel_data *chand, grpc_closure *on_complete) { +static external_connectivity_watcher* lookup_external_connectivity_watcher( + channel_data* chand, grpc_closure* on_complete) { gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); - external_connectivity_watcher *w = + external_connectivity_watcher* w = chand->external_connectivity_watcher_list_head; while (w != NULL && w->on_complete != on_complete) { w = w->next; @@ -1576,7 +1577,7 @@ static external_connectivity_watcher *lookup_external_connectivity_watcher( } static void external_connectivity_watcher_list_append( - channel_data *chand, external_connectivity_watcher *w) { + channel_data* chand, external_connectivity_watcher* w) { GPR_ASSERT(!lookup_external_connectivity_watcher(chand, w->on_complete)); gpr_mu_lock(&w->chand->external_connectivity_watcher_list_mu); @@ -1587,7 +1588,7 @@ static void external_connectivity_watcher_list_append( } static void external_connectivity_watcher_list_remove( - channel_data *chand, external_connectivity_watcher *too_remove) { + channel_data* chand, external_connectivity_watcher* too_remove) { GPR_ASSERT( lookup_external_connectivity_watcher(chand, too_remove->on_complete)); gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); @@ -1596,7 +1597,7 @@ static void external_connectivity_watcher_list_remove( gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); return; } - external_connectivity_watcher *w = + external_connectivity_watcher* w = chand->external_connectivity_watcher_list_head; while (w != NULL) { if (w->next == too_remove) { @@ -1610,12 +1611,12 @@ static void external_connectivity_watcher_list_remove( } int grpc_client_channel_num_external_connectivity_watchers( - grpc_channel_element *elem) { - channel_data *chand = (channel_data *)elem->channel_data; + grpc_channel_element* elem) { + channel_data* chand = (channel_data*)elem->channel_data; int count = 0; gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); - external_connectivity_watcher *w = + external_connectivity_watcher* w = chand->external_connectivity_watcher_list_head; while (w != NULL) { count++; @@ -1626,10 +1627,10 @@ int grpc_client_channel_num_external_connectivity_watchers( return count; } -static void on_external_watch_complete_locked(grpc_exec_ctx *exec_ctx, - void *arg, grpc_error *error) { - external_connectivity_watcher *w = (external_connectivity_watcher *)arg; - grpc_closure *follow_up = w->on_complete; +static void on_external_watch_complete_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { + external_connectivity_watcher* w = (external_connectivity_watcher*)arg; + grpc_closure* follow_up = w->on_complete; grpc_polling_entity_del_from_pollset_set(exec_ctx, &w->pollent, w->chand->interested_parties); GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, @@ -1639,10 +1640,10 @@ static void on_external_watch_complete_locked(grpc_exec_ctx *exec_ctx, GRPC_CLOSURE_RUN(exec_ctx, follow_up, GRPC_ERROR_REF(error)); } -static void watch_connectivity_state_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error_ignored) { - external_connectivity_watcher *w = (external_connectivity_watcher *)arg; - external_connectivity_watcher *found = NULL; +static void watch_connectivity_state_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error_ignored) { + external_connectivity_watcher* w = (external_connectivity_watcher*)arg; + external_connectivity_watcher* found = NULL; if (w->state != NULL) { external_connectivity_watcher_list_append(w->chand, w); GRPC_CLOSURE_RUN(exec_ctx, w->watcher_timer_init, GRPC_ERROR_NONE); @@ -1667,12 +1668,12 @@ static void watch_connectivity_state_locked(grpc_exec_ctx *exec_ctx, void *arg, } void grpc_client_channel_watch_connectivity_state( - grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, - grpc_polling_entity pollent, grpc_connectivity_state *state, - grpc_closure *closure, grpc_closure *watcher_timer_init) { - channel_data *chand = (channel_data *)elem->channel_data; - external_connectivity_watcher *w = - (external_connectivity_watcher *)gpr_zalloc(sizeof(*w)); + grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_polling_entity pollent, grpc_connectivity_state* state, + grpc_closure* closure, grpc_closure* watcher_timer_init) { + channel_data* chand = (channel_data*)elem->channel_data; + external_connectivity_watcher* w = + (external_connectivity_watcher*)gpr_zalloc(sizeof(*w)); w->chand = chand; w->pollent = pollent; w->on_complete = closure; diff --git a/src/core/ext/filters/client_channel/client_channel.h b/src/core/ext/filters/client_channel/client_channel.h index 152fe2365a..27862cf239 100644 --- a/src/core/ext/filters/client_channel/client_channel.h +++ b/src/core/ext/filters/client_channel/client_channel.h @@ -42,19 +42,19 @@ extern "C" { extern const grpc_channel_filter grpc_client_channel_filter; grpc_connectivity_state grpc_client_channel_check_connectivity_state( - grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, int try_to_connect); + grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, int try_to_connect); int grpc_client_channel_num_external_connectivity_watchers( - grpc_channel_element *elem); + grpc_channel_element* elem); void grpc_client_channel_watch_connectivity_state( - grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, - grpc_polling_entity pollent, grpc_connectivity_state *state, - grpc_closure *on_complete, grpc_closure *watcher_timer_init); + grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_polling_entity pollent, grpc_connectivity_state* state, + grpc_closure* on_complete, grpc_closure* watcher_timer_init); /* Debug helper: pull the subchannel call from a call stack element */ -grpc_subchannel_call *grpc_client_channel_get_subchannel_call( - grpc_call_element *elem); +grpc_subchannel_call* grpc_client_channel_get_subchannel_call( + grpc_call_element* elem); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/client_channel_factory.h b/src/core/ext/filters/client_channel/client_channel_factory.h index 4273c90058..db8645cd00 100644 --- a/src/core/ext/filters/client_channel/client_channel_factory.h +++ b/src/core/ext/filters/client_channel/client_channel_factory.h @@ -44,39 +44,39 @@ typedef enum { /** Constructor for new configured channels. Creating decorators around this type is encouraged to adapt behavior. */ struct grpc_client_channel_factory { - const grpc_client_channel_factory_vtable *vtable; + const grpc_client_channel_factory_vtable* vtable; }; struct grpc_client_channel_factory_vtable { - void (*ref)(grpc_client_channel_factory *factory); - void (*unref)(grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory); - grpc_subchannel *(*create_subchannel)(grpc_exec_ctx *exec_ctx, - grpc_client_channel_factory *factory, - const grpc_subchannel_args *args); - grpc_channel *(*create_client_channel)(grpc_exec_ctx *exec_ctx, - grpc_client_channel_factory *factory, - const char *target, + void (*ref)(grpc_client_channel_factory* factory); + void (*unref)(grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory); + grpc_subchannel* (*create_subchannel)(grpc_exec_ctx* exec_ctx, + grpc_client_channel_factory* factory, + const grpc_subchannel_args* args); + grpc_channel* (*create_client_channel)(grpc_exec_ctx* exec_ctx, + grpc_client_channel_factory* factory, + const char* target, grpc_client_channel_type type, - const grpc_channel_args *args); + const grpc_channel_args* args); }; -void grpc_client_channel_factory_ref(grpc_client_channel_factory *factory); -void grpc_client_channel_factory_unref(grpc_exec_ctx *exec_ctx, - grpc_client_channel_factory *factory); +void grpc_client_channel_factory_ref(grpc_client_channel_factory* factory); +void grpc_client_channel_factory_unref(grpc_exec_ctx* exec_ctx, + grpc_client_channel_factory* factory); /** Create a new grpc_subchannel */ -grpc_subchannel *grpc_client_channel_factory_create_subchannel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, - const grpc_subchannel_args *args); +grpc_subchannel* grpc_client_channel_factory_create_subchannel( + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, + const grpc_subchannel_args* args); /** Create a new grpc_channel */ -grpc_channel *grpc_client_channel_factory_create_channel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, - const char *target, grpc_client_channel_type type, - const grpc_channel_args *args); +grpc_channel* grpc_client_channel_factory_create_channel( + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, + const char* target, grpc_client_channel_type type, + const grpc_channel_args* args); grpc_arg grpc_client_channel_factory_create_channel_arg( - grpc_client_channel_factory *factory); + grpc_client_channel_factory* factory); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/client_channel_plugin.cc b/src/core/ext/filters/client_channel/client_channel_plugin.cc index 4431d11519..0db894913c 100644 --- a/src/core/ext/filters/client_channel/client_channel_plugin.cc +++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc @@ -34,16 +34,16 @@ #include "src/core/ext/filters/client_channel/subchannel_index.h" #include "src/core/lib/surface/channel_init.h" -static bool append_filter(grpc_exec_ctx *exec_ctx, - grpc_channel_stack_builder *builder, void *arg) { +static bool append_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_append_filter( - builder, (const grpc_channel_filter *)arg, NULL, NULL); + builder, (const grpc_channel_filter*)arg, NULL, NULL); } -static bool set_default_host_if_unset(grpc_exec_ctx *exec_ctx, - grpc_channel_stack_builder *builder, - void *unused) { - const grpc_channel_args *args = +static bool set_default_host_if_unset(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, + void* unused) { + const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); for (size_t i = 0; i < args->num_args; i++) { if (0 == strcmp(args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY) || @@ -51,12 +51,12 @@ static bool set_default_host_if_unset(grpc_exec_ctx *exec_ctx, return true; } } - char *default_authority = grpc_get_default_authority( + char* default_authority = grpc_get_default_authority( exec_ctx, grpc_channel_stack_builder_get_target(builder)); if (default_authority != NULL) { grpc_arg arg = grpc_channel_arg_string_create( - (char *)GRPC_ARG_DEFAULT_AUTHORITY, default_authority); - grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1); + (char*)GRPC_ARG_DEFAULT_AUTHORITY, default_authority); + grpc_channel_args* new_args = grpc_channel_args_copy_and_add(args, &arg, 1); grpc_channel_stack_builder_set_channel_arguments(exec_ctx, builder, new_args); gpr_free(default_authority); @@ -76,7 +76,7 @@ extern "C" void grpc_client_channel_init(void) { set_default_host_if_unset, NULL); grpc_channel_init_register_stage( GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter, - (void *)&grpc_client_channel_filter); + (void*)&grpc_client_channel_filter); grpc_http_connect_register_handshaker_factory(); grpc_register_tracer(&grpc_client_channel_trace); #ifndef NDEBUG diff --git a/src/core/ext/filters/client_channel/connector.h b/src/core/ext/filters/client_channel/connector.h index b71e0aab00..12dc59bcdf 100644 --- a/src/core/ext/filters/client_channel/connector.h +++ b/src/core/ext/filters/client_channel/connector.h @@ -31,48 +31,48 @@ typedef struct grpc_connector grpc_connector; typedef struct grpc_connector_vtable grpc_connector_vtable; struct grpc_connector { - const grpc_connector_vtable *vtable; + const grpc_connector_vtable* vtable; }; typedef struct { /** set of pollsets interested in this connection */ - grpc_pollset_set *interested_parties; + grpc_pollset_set* interested_parties; /** deadline for connection */ grpc_millis deadline; /** channel arguments (to be passed to transport) */ - const grpc_channel_args *channel_args; + const grpc_channel_args* channel_args; } grpc_connect_in_args; typedef struct { /** the connected transport */ - grpc_transport *transport; + grpc_transport* transport; /** channel arguments (to be passed to the filters) */ - grpc_channel_args *channel_args; + grpc_channel_args* channel_args; } grpc_connect_out_args; struct grpc_connector_vtable { - void (*ref)(grpc_connector *connector); - void (*unref)(grpc_exec_ctx *exec_ctx, grpc_connector *connector); + void (*ref)(grpc_connector* connector); + void (*unref)(grpc_exec_ctx* exec_ctx, grpc_connector* connector); /** Implementation of grpc_connector_shutdown */ - void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_connector *connector, - grpc_error *why); + void (*shutdown)(grpc_exec_ctx* exec_ctx, grpc_connector* connector, + grpc_error* why); /** Implementation of grpc_connector_connect */ - void (*connect)(grpc_exec_ctx *exec_ctx, grpc_connector *connector, - const grpc_connect_in_args *in_args, - grpc_connect_out_args *out_args, grpc_closure *notify); + void (*connect)(grpc_exec_ctx* exec_ctx, grpc_connector* connector, + const grpc_connect_in_args* in_args, + grpc_connect_out_args* out_args, grpc_closure* notify); }; -grpc_connector *grpc_connector_ref(grpc_connector *connector); -void grpc_connector_unref(grpc_exec_ctx *exec_ctx, grpc_connector *connector); +grpc_connector* grpc_connector_ref(grpc_connector* connector); +void grpc_connector_unref(grpc_exec_ctx* exec_ctx, grpc_connector* connector); /** Connect using the connector: max one outstanding call at a time */ -void grpc_connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *connector, - const grpc_connect_in_args *in_args, - grpc_connect_out_args *out_args, - grpc_closure *notify); +void grpc_connector_connect(grpc_exec_ctx* exec_ctx, grpc_connector* connector, + const grpc_connect_in_args* in_args, + grpc_connect_out_args* out_args, + grpc_closure* notify); /** Cancel any pending connection */ -void grpc_connector_shutdown(grpc_exec_ctx *exec_ctx, grpc_connector *connector, - grpc_error *why); +void grpc_connector_shutdown(grpc_exec_ctx* exec_ctx, grpc_connector* connector, + grpc_error* why); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/lb_policy.cc b/src/core/ext/filters/client_channel/lb_policy.cc index 8e6673d737..387c26ed5c 100644 --- a/src/core/ext/filters/client_channel/lb_policy.cc +++ b/src/core/ext/filters/client_channel/lb_policy.cc @@ -26,9 +26,9 @@ grpc_tracer_flag grpc_trace_lb_policy_refcount = GRPC_TRACER_INITIALIZER(false, "lb_policy_refcount"); #endif -void grpc_lb_policy_init(grpc_lb_policy *policy, - const grpc_lb_policy_vtable *vtable, - grpc_combiner *combiner) { +void grpc_lb_policy_init(grpc_lb_policy* policy, + const grpc_lb_policy_vtable* vtable, + grpc_combiner* combiner) { policy->vtable = vtable; gpr_atm_no_barrier_store(&policy->ref_pair, 1 << WEAK_REF_BITS); policy->interested_parties = grpc_pollset_set_create(); @@ -37,7 +37,7 @@ void grpc_lb_policy_init(grpc_lb_policy *policy, #ifndef NDEBUG #define REF_FUNC_EXTRA_ARGS , const char *file, int line, const char *reason -#define REF_MUTATE_EXTRA_ARGS REF_FUNC_EXTRA_ARGS, const char *purpose +#define REF_MUTATE_EXTRA_ARGS REF_FUNC_EXTRA_ARGS, const char* purpose #define REF_FUNC_PASS_ARGS(new_reason) , file, line, new_reason #define REF_MUTATE_PASS_ARGS(purpose) , file, line, reason, purpose #else @@ -47,7 +47,7 @@ void grpc_lb_policy_init(grpc_lb_policy *policy, #define REF_MUTATE_PASS_ARGS(x) #endif -static gpr_atm ref_mutate(grpc_lb_policy *c, gpr_atm delta, +static gpr_atm ref_mutate(grpc_lb_policy* c, gpr_atm delta, int barrier REF_MUTATE_EXTRA_ARGS) { gpr_atm old_val = barrier ? gpr_atm_full_fetch_add(&c->ref_pair, delta) : gpr_atm_no_barrier_fetch_add(&c->ref_pair, delta); @@ -61,104 +61,105 @@ static gpr_atm ref_mutate(grpc_lb_policy *c, gpr_atm delta, return old_val; } -void grpc_lb_policy_ref(grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { +void grpc_lb_policy_ref(grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { ref_mutate(policy, 1 << WEAK_REF_BITS, 0 REF_MUTATE_PASS_ARGS("STRONG_REF")); } -static void shutdown_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_lb_policy *policy = (grpc_lb_policy *)arg; +static void shutdown_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_lb_policy* policy = (grpc_lb_policy*)arg; policy->vtable->shutdown_locked(exec_ctx, policy); GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, policy, "strong-unref"); } -void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { +void grpc_lb_policy_unref(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { gpr_atm old_val = ref_mutate(policy, (gpr_atm)1 - (gpr_atm)(1 << WEAK_REF_BITS), 1 REF_MUTATE_PASS_ARGS("STRONG_UNREF")); gpr_atm mask = ~(gpr_atm)((1 << WEAK_REF_BITS) - 1); gpr_atm check = 1 << WEAK_REF_BITS; if ((old_val & mask) == check) { - GRPC_CLOSURE_SCHED(exec_ctx, GRPC_CLOSURE_CREATE( - shutdown_locked, policy, - grpc_combiner_scheduler(policy->combiner)), - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED( + exec_ctx, + GRPC_CLOSURE_CREATE(shutdown_locked, policy, + grpc_combiner_scheduler(policy->combiner)), + GRPC_ERROR_NONE); } else { grpc_lb_policy_weak_unref(exec_ctx, policy REF_FUNC_PASS_ARGS("strong-unref")); } } -void grpc_lb_policy_weak_ref(grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { +void grpc_lb_policy_weak_ref(grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { ref_mutate(policy, 1, 0 REF_MUTATE_PASS_ARGS("WEAK_REF")); } -void grpc_lb_policy_weak_unref(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { +void grpc_lb_policy_weak_unref(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy REF_FUNC_EXTRA_ARGS) { gpr_atm old_val = ref_mutate(policy, -(gpr_atm)1, 1 REF_MUTATE_PASS_ARGS("WEAK_UNREF")); if (old_val == 1) { grpc_pollset_set_destroy(exec_ctx, policy->interested_parties); - grpc_combiner *combiner = policy->combiner; + grpc_combiner* combiner = policy->combiner; policy->vtable->destroy(exec_ctx, policy); GRPC_COMBINER_UNREF(exec_ctx, combiner, "lb_policy"); } } -int grpc_lb_policy_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - const grpc_lb_policy_pick_args *pick_args, - grpc_connected_subchannel **target, - grpc_call_context_element *context, - void **user_data, grpc_closure *on_complete) { +int grpc_lb_policy_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + const grpc_lb_policy_pick_args* pick_args, + grpc_connected_subchannel** target, + grpc_call_context_element* context, + void** user_data, grpc_closure* on_complete) { return policy->vtable->pick_locked(exec_ctx, policy, pick_args, target, context, user_data, on_complete); } -void grpc_lb_policy_cancel_pick_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - grpc_connected_subchannel **target, - grpc_error *error) { +void grpc_lb_policy_cancel_pick_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, + grpc_connected_subchannel** target, + grpc_error* error) { policy->vtable->cancel_pick_locked(exec_ctx, policy, target, error); } -void grpc_lb_policy_cancel_picks_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, +void grpc_lb_policy_cancel_picks_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, - grpc_error *error) { + grpc_error* error) { policy->vtable->cancel_picks_locked(exec_ctx, policy, initial_metadata_flags_mask, initial_metadata_flags_eq, error); } -void grpc_lb_policy_exit_idle_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy) { +void grpc_lb_policy_exit_idle_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy) { policy->vtable->exit_idle_locked(exec_ctx, policy); } -void grpc_lb_policy_ping_one_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - grpc_closure *closure) { +void grpc_lb_policy_ping_one_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, + grpc_closure* closure) { policy->vtable->ping_one_locked(exec_ctx, policy, closure); } void grpc_lb_policy_notify_on_state_change_locked( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_connectivity_state *state, grpc_closure *closure) { + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_connectivity_state* state, grpc_closure* closure) { policy->vtable->notify_on_state_change_locked(exec_ctx, policy, state, closure); } grpc_connectivity_state grpc_lb_policy_check_connectivity_locked( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_error **connectivity_error) { + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_error** connectivity_error) { return policy->vtable->check_connectivity_locked(exec_ctx, policy, connectivity_error); } -void grpc_lb_policy_update_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - const grpc_lb_policy_args *lb_policy_args) { +void grpc_lb_policy_update_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, + const grpc_lb_policy_args* lb_policy_args) { policy->vtable->update_locked(exec_ctx, policy, lb_policy_args); } diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index 010299c2f4..590094e67e 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -38,70 +38,70 @@ extern grpc_tracer_flag grpc_trace_lb_policy_refcount; #endif struct grpc_lb_policy { - const grpc_lb_policy_vtable *vtable; + const grpc_lb_policy_vtable* vtable; gpr_atm ref_pair; /* owned pointer to interested parties in load balancing decisions */ - grpc_pollset_set *interested_parties; + grpc_pollset_set* interested_parties; /* combiner under which lb_policy actions take place */ - grpc_combiner *combiner; + grpc_combiner* combiner; }; /** Extra arguments for an LB pick */ typedef struct grpc_lb_policy_pick_args { /** Initial metadata associated with the picking call. */ - grpc_metadata_batch *initial_metadata; + grpc_metadata_batch* initial_metadata; /** Bitmask used for selective cancelling. See \a * grpc_lb_policy_cancel_picks() and \a GRPC_INITIAL_METADATA_* in * grpc_types.h */ uint32_t initial_metadata_flags; /** Storage for LB token in \a initial_metadata, or NULL if not used */ - grpc_linked_mdelem *lb_token_mdelem_storage; + grpc_linked_mdelem* lb_token_mdelem_storage; } grpc_lb_policy_pick_args; struct grpc_lb_policy_vtable { - void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); - void (*shutdown_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); + void (*shutdown_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); /** \see grpc_lb_policy_pick */ - int (*pick_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - const grpc_lb_policy_pick_args *pick_args, - grpc_connected_subchannel **target, - grpc_call_context_element *context, void **user_data, - grpc_closure *on_complete); + int (*pick_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + const grpc_lb_policy_pick_args* pick_args, + grpc_connected_subchannel** target, + grpc_call_context_element* context, void** user_data, + grpc_closure* on_complete); /** \see grpc_lb_policy_cancel_pick */ - void (*cancel_pick_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_connected_subchannel **target, - grpc_error *error); + void (*cancel_pick_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_connected_subchannel** target, + grpc_error* error); /** \see grpc_lb_policy_cancel_picks */ - void (*cancel_picks_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + void (*cancel_picks_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, - grpc_error *error); + grpc_error* error); /** \see grpc_lb_policy_ping_one */ - void (*ping_one_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_closure *closure); + void (*ping_one_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_closure* closure); /** Try to enter a READY connectivity state */ - void (*exit_idle_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); + void (*exit_idle_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); /** check the current connectivity of the lb_policy */ grpc_connectivity_state (*check_connectivity_locked)( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_error **connectivity_error); + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_error** connectivity_error); /** call notify when the connectivity state of a channel changes from *state. Updates *state with the new state of the policy. Calling with a NULL \a state cancels the subscription. */ - void (*notify_on_state_change_locked)(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - grpc_connectivity_state *state, - grpc_closure *closure); + void (*notify_on_state_change_locked)(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, + grpc_connectivity_state* state, + grpc_closure* closure); - void (*update_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - const grpc_lb_policy_args *args); + void (*update_locked)(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + const grpc_lb_policy_args* args); }; #ifndef NDEBUG @@ -119,29 +119,29 @@ struct grpc_lb_policy_vtable { grpc_lb_policy_weak_ref((p), __FILE__, __LINE__, (r)) #define GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, p, r) \ grpc_lb_policy_weak_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) -void grpc_lb_policy_ref(grpc_lb_policy *policy, const char *file, int line, - const char *reason); -void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - const char *file, int line, const char *reason); -void grpc_lb_policy_weak_ref(grpc_lb_policy *policy, const char *file, int line, - const char *reason); -void grpc_lb_policy_weak_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - const char *file, int line, const char *reason); +void grpc_lb_policy_ref(grpc_lb_policy* policy, const char* file, int line, + const char* reason); +void grpc_lb_policy_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + const char* file, int line, const char* reason); +void grpc_lb_policy_weak_ref(grpc_lb_policy* policy, const char* file, int line, + const char* reason); +void grpc_lb_policy_weak_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + const char* file, int line, const char* reason); #else #define GRPC_LB_POLICY_REF(p, r) grpc_lb_policy_ref((p)) #define GRPC_LB_POLICY_UNREF(cl, p, r) grpc_lb_policy_unref((cl), (p)) #define GRPC_LB_POLICY_WEAK_REF(p, r) grpc_lb_policy_weak_ref((p)) #define GRPC_LB_POLICY_WEAK_UNREF(cl, p, r) grpc_lb_policy_weak_unref((cl), (p)) -void grpc_lb_policy_ref(grpc_lb_policy *policy); -void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); -void grpc_lb_policy_weak_ref(grpc_lb_policy *policy); -void grpc_lb_policy_weak_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); +void grpc_lb_policy_ref(grpc_lb_policy* policy); +void grpc_lb_policy_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); +void grpc_lb_policy_weak_ref(grpc_lb_policy* policy); +void grpc_lb_policy_weak_unref(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy); #endif /** called by concrete implementations to initialize the base struct */ -void grpc_lb_policy_init(grpc_lb_policy *policy, - const grpc_lb_policy_vtable *vtable, - grpc_combiner *combiner); +void grpc_lb_policy_init(grpc_lb_policy* policy, + const grpc_lb_policy_vtable* vtable, + grpc_combiner* combiner); /** Finds an appropriate subchannel for a call, based on \a pick_args. @@ -160,53 +160,53 @@ void grpc_lb_policy_init(grpc_lb_policy *policy, Any IO should be done under the \a interested_parties \a grpc_pollset_set in the \a grpc_lb_policy struct. */ -int grpc_lb_policy_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - const grpc_lb_policy_pick_args *pick_args, - grpc_connected_subchannel **target, - grpc_call_context_element *context, - void **user_data, grpc_closure *on_complete); +int grpc_lb_policy_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + const grpc_lb_policy_pick_args* pick_args, + grpc_connected_subchannel** target, + grpc_call_context_element* context, + void** user_data, grpc_closure* on_complete); /** Perform a connected subchannel ping (see \a grpc_connected_subchannel_ping) against one of the connected subchannels managed by \a policy. */ -void grpc_lb_policy_ping_one_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - grpc_closure *closure); +void grpc_lb_policy_ping_one_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, + grpc_closure* closure); /** Cancel picks for \a target. The \a on_complete callback of the pending picks will be invoked with \a *target set to NULL. */ -void grpc_lb_policy_cancel_pick_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - grpc_connected_subchannel **target, - grpc_error *error); +void grpc_lb_policy_cancel_pick_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, + grpc_connected_subchannel** target, + grpc_error* error); /** Cancel all pending picks for which their \a initial_metadata_flags (as given in the call to \a grpc_lb_policy_pick) matches \a initial_metadata_flags_eq when AND'd with \a initial_metadata_flags_mask */ -void grpc_lb_policy_cancel_picks_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, +void grpc_lb_policy_cancel_picks_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, - grpc_error *error); + grpc_error* error); /** Try to enter a READY connectivity state */ -void grpc_lb_policy_exit_idle_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy); +void grpc_lb_policy_exit_idle_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy); /* Call notify when the connectivity state of a channel changes from \a *state. * Updates \a *state with the new state of the policy */ void grpc_lb_policy_notify_on_state_change_locked( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_connectivity_state *state, grpc_closure *closure); + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_connectivity_state* state, grpc_closure* closure); grpc_connectivity_state grpc_lb_policy_check_connectivity_locked( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_error **connectivity_error); + grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + grpc_error** connectivity_error); /** Update \a policy with \a lb_policy_args. */ -void grpc_lb_policy_update_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - const grpc_lb_policy_args *lb_policy_args); +void grpc_lb_policy_update_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* policy, + const grpc_lb_policy_args* lb_policy_args); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc index 7ad322902b..d93a9c3710 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc @@ -25,31 +25,31 @@ #include "src/core/lib/iomgr/error.h" #include "src/core/lib/profiling/timers.h" -static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_channel_element_args *args) { +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + grpc_channel_element_args* args) { return GRPC_ERROR_NONE; } -static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} typedef struct { // Stats object to update. - grpc_grpclb_client_stats *client_stats; + grpc_grpclb_client_stats* client_stats; // State for intercepting send_initial_metadata. grpc_closure on_complete_for_send; - grpc_closure *original_on_complete_for_send; + grpc_closure* original_on_complete_for_send; bool send_initial_metadata_succeeded; // State for intercepting recv_initial_metadata. grpc_closure recv_initial_metadata_ready; - grpc_closure *original_recv_initial_metadata_ready; + grpc_closure* original_recv_initial_metadata_ready; bool recv_initial_metadata_succeeded; } call_data; -static void on_complete_for_send(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - call_data *calld = (call_data *)arg; +static void on_complete_for_send(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + call_data* calld = (call_data*)arg; if (error == GRPC_ERROR_NONE) { calld->send_initial_metadata_succeeded = true; } @@ -57,9 +57,9 @@ static void on_complete_for_send(grpc_exec_ctx *exec_ctx, void *arg, GRPC_ERROR_REF(error)); } -static void recv_initial_metadata_ready(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - call_data *calld = (call_data *)arg; +static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + call_data* calld = (call_data*)arg; if (error == GRPC_ERROR_NONE) { calld->recv_initial_metadata_succeeded = true; } @@ -67,25 +67,24 @@ static void recv_initial_metadata_ready(grpc_exec_ctx *exec_ctx, void *arg, GRPC_ERROR_REF(error)); } -static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_element_args *args) { - call_data *calld = (call_data *)elem->call_data; +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + const grpc_call_element_args* args) { + call_data* calld = (call_data*)elem->call_data; // Get stats object from context and take a ref. GPR_ASSERT(args->context != NULL); GPR_ASSERT(args->context[GRPC_GRPCLB_CLIENT_STATS].value != NULL); calld->client_stats = grpc_grpclb_client_stats_ref( - (grpc_grpclb_client_stats *)args->context[GRPC_GRPCLB_CLIENT_STATS] - .value); + (grpc_grpclb_client_stats*)args->context[GRPC_GRPCLB_CLIENT_STATS].value); // Record call started. grpc_grpclb_client_stats_add_call_started(calld->client_stats); return GRPC_ERROR_NONE; } -static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_final_info *final_info, - grpc_closure *ignored) { - call_data *calld = (call_data *)elem->call_data; +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* ignored) { + call_data* calld = (call_data*)elem->call_data; // Record call finished, optionally setting client_failed_to_send and // received. grpc_grpclb_client_stats_add_call_finished( @@ -97,9 +96,9 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, } static void start_transport_stream_op_batch( - grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_transport_stream_op_batch *batch) { - call_data *calld = (call_data *)elem->call_data; + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { + call_data* calld = (call_data*)elem->call_data; GPR_TIMER_BEGIN("clr_start_transport_stream_op_batch", 0); // Intercept send_initial_metadata. if (batch->send_initial_metadata) { diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h index c6a0d69c3f..abf613a23b 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h @@ -32,4 +32,4 @@ extern const grpc_channel_filter grpc_client_load_reporting_filter; #endif #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_CLIENT_LOAD_REPORTING_FILTER_H \ - */ + */ diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index 1b19650b61..01b243bc3e 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -130,17 +130,17 @@ grpc_tracer_flag grpc_lb_glb_trace = GRPC_TRACER_INITIALIZER(false, "glb"); /* add lb_token of selected subchannel (address) to the call's initial * metadata */ -static grpc_error *initial_metadata_add_lb_token( - grpc_exec_ctx *exec_ctx, grpc_metadata_batch *initial_metadata, - grpc_linked_mdelem *lb_token_mdelem_storage, grpc_mdelem lb_token) { +static grpc_error* initial_metadata_add_lb_token( + grpc_exec_ctx* exec_ctx, grpc_metadata_batch* initial_metadata, + grpc_linked_mdelem* lb_token_mdelem_storage, grpc_mdelem lb_token) { GPR_ASSERT(lb_token_mdelem_storage != NULL); GPR_ASSERT(!GRPC_MDISNULL(lb_token)); return grpc_metadata_batch_add_tail(exec_ctx, initial_metadata, lb_token_mdelem_storage, lb_token); } -static void destroy_client_stats(void *arg) { - grpc_grpclb_client_stats_unref((grpc_grpclb_client_stats *)arg); +static void destroy_client_stats(void* arg) { + grpc_grpclb_client_stats_unref((grpc_grpclb_client_stats*)arg); } typedef struct wrapped_rr_closure_arg { @@ -149,42 +149,42 @@ typedef struct wrapped_rr_closure_arg { /* the original closure. Usually a on_complete/notify cb for pick() and ping() * calls against the internal RR instance, respectively. */ - grpc_closure *wrapped_closure; + grpc_closure* wrapped_closure; /* the pick's initial metadata, kept in order to append the LB token for the * pick */ - grpc_metadata_batch *initial_metadata; + grpc_metadata_batch* initial_metadata; /* the picked target, used to determine which LB token to add to the pick's * initial metadata */ - grpc_connected_subchannel **target; + grpc_connected_subchannel** target; /* the context to be populated for the subchannel call */ - grpc_call_context_element *context; + grpc_call_context_element* context; /* Stats for client-side load reporting. Note that this holds a * reference, which must be either passed on via context or unreffed. */ - grpc_grpclb_client_stats *client_stats; + grpc_grpclb_client_stats* client_stats; /* the LB token associated with the pick */ grpc_mdelem lb_token; /* storage for the lb token initial metadata mdelem */ - grpc_linked_mdelem *lb_token_mdelem_storage; + grpc_linked_mdelem* lb_token_mdelem_storage; /* The RR instance related to the closure */ - grpc_lb_policy *rr_policy; + grpc_lb_policy* rr_policy; /* heap memory to be freed upon closure execution. */ - void *free_when_done; + void* free_when_done; } wrapped_rr_closure_arg; /* The \a on_complete closure passed as part of the pick requires keeping a * reference to its associated round robin instance. We wrap this closure in * order to unref the round robin instance upon its invocation */ -static void wrapped_rr_closure(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - wrapped_rr_closure_arg *wc_arg = (wrapped_rr_closure_arg *)arg; +static void wrapped_rr_closure(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + wrapped_rr_closure_arg* wc_arg = (wrapped_rr_closure_arg*)arg; GPR_ASSERT(wc_arg->wrapped_closure != NULL); GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_REF(error)); @@ -202,7 +202,7 @@ static void wrapped_rr_closure(grpc_exec_ctx *exec_ctx, void *arg, gpr_log(GPR_ERROR, "No LB token for connected subchannel pick %p (from RR " "instance %p).", - (void *)*wc_arg->target, (void *)wc_arg->rr_policy); + (void*)*wc_arg->target, (void*)wc_arg->rr_policy); abort(); } // Pass on client stats via context. Passes ownership of the reference. @@ -213,7 +213,7 @@ static void wrapped_rr_closure(grpc_exec_ctx *exec_ctx, void *arg, grpc_grpclb_client_stats_unref(wc_arg->client_stats); } if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { - gpr_log(GPR_INFO, "Unreffing RR %p", (void *)wc_arg->rr_policy); + gpr_log(GPR_INFO, "Unreffing RR %p", (void*)wc_arg->rr_policy); } GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "wrapped_rr_closure"); } @@ -230,25 +230,25 @@ static void wrapped_rr_closure(grpc_exec_ctx *exec_ctx, void *arg, * order to correctly unref the RR policy instance upon completion of the pick. * See \a wrapped_rr_closure for details. */ typedef struct pending_pick { - struct pending_pick *next; + struct pending_pick* next; /* original pick()'s arguments */ grpc_lb_policy_pick_args pick_args; /* output argument where to store the pick()ed connected subchannel, or NULL * upon error. */ - grpc_connected_subchannel **target; + grpc_connected_subchannel** target; /* args for wrapped_on_complete */ wrapped_rr_closure_arg wrapped_on_complete_arg; } pending_pick; -static void add_pending_pick(pending_pick **root, - const grpc_lb_policy_pick_args *pick_args, - grpc_connected_subchannel **target, - grpc_call_context_element *context, - grpc_closure *on_complete) { - pending_pick *pp = (pending_pick *)gpr_zalloc(sizeof(*pp)); +static void add_pending_pick(pending_pick** root, + const grpc_lb_policy_pick_args* pick_args, + grpc_connected_subchannel** target, + grpc_call_context_element* context, + grpc_closure* on_complete) { + pending_pick* pp = (pending_pick*)gpr_zalloc(sizeof(*pp)); pp->next = *root; pp->pick_args = *pick_args; pp->target = target; @@ -267,14 +267,14 @@ static void add_pending_pick(pending_pick **root, /* Same as the \a pending_pick struct but for ping operations */ typedef struct pending_ping { - struct pending_ping *next; + struct pending_ping* next; /* args for wrapped_notify */ wrapped_rr_closure_arg wrapped_notify_arg; } pending_ping; -static void add_pending_ping(pending_ping **root, grpc_closure *notify) { - pending_ping *pping = (pending_ping *)gpr_zalloc(sizeof(*pping)); +static void add_pending_ping(pending_ping** root, grpc_closure* notify) { + pending_ping* pping = (pending_ping*)gpr_zalloc(sizeof(*pping)); pping->wrapped_notify_arg.wrapped_closure = notify; pping->wrapped_notify_arg.free_when_done = pping; pping->next = *root; @@ -294,9 +294,9 @@ typedef struct glb_lb_policy { grpc_lb_policy base; /** who the client is trying to communicate with */ - const char *server_name; - grpc_client_channel_factory *cc_factory; - grpc_channel_args *args; + const char* server_name; + grpc_client_channel_factory* cc_factory; + grpc_channel_args* args; /** timeout in milliseconds for the LB call. 0 means no deadline. */ int lb_call_timeout_ms; @@ -306,13 +306,13 @@ typedef struct glb_lb_policy { int lb_fallback_timeout_ms; /** for communicating with the LB server */ - grpc_channel *lb_channel; + grpc_channel* lb_channel; /** response generator to inject address updates into \a lb_channel */ - grpc_fake_resolver_response_generator *response_generator; + grpc_fake_resolver_response_generator* response_generator; /** the RR policy to use of the backend servers returned by the LB server */ - grpc_lb_policy *rr_policy; + grpc_lb_policy* rr_policy; bool started_picking; @@ -324,7 +324,7 @@ typedef struct glb_lb_policy { /** stores the deserialized response from the LB. May be NULL until one such * response has arrived. */ - grpc_grpclb_serverlist *serverlist; + grpc_grpclb_serverlist* serverlist; /** Index into serverlist for next pick. * If the server at this index is a drop, we return a drop. @@ -332,13 +332,13 @@ typedef struct glb_lb_policy { size_t serverlist_index; /** stores the backend addresses from the resolver */ - grpc_lb_addresses *fallback_backend_addresses; + grpc_lb_addresses* fallback_backend_addresses; /** list of picks that are waiting on RR's policy connectivity */ - pending_pick *pending_picks; + pending_pick* pending_picks; /** list of pings that are waiting on RR's policy connectivity */ - pending_ping *pending_pings; + pending_ping* pending_pings; bool shutting_down; @@ -373,7 +373,7 @@ typedef struct glb_lb_policy { /* LB fallback timer callback. */ grpc_closure lb_on_fallback; - grpc_call *lb_call; /* streaming call to the LB server, */ + grpc_call* lb_call; /* streaming call to the LB server, */ grpc_metadata_array lb_initial_metadata_recv; /* initial MD from LB server */ grpc_metadata_array @@ -381,10 +381,10 @@ typedef struct glb_lb_policy { /* what's being sent to the LB server. Note that its value may vary if the LB * server indicates a redirect. */ - grpc_byte_buffer *lb_request_payload; + grpc_byte_buffer* lb_request_payload; /* response the LB server, if any. Processed in lb_on_response_received() */ - grpc_byte_buffer *lb_response_payload; + grpc_byte_buffer* lb_response_payload; /* call status code and details, set in lb_on_server_status_received() */ grpc_status_code lb_call_status; @@ -403,7 +403,7 @@ typedef struct glb_lb_policy { /* Stats for client-side load reporting. Should be unreffed and * recreated whenever lb_call is replaced. */ - grpc_grpclb_client_stats *client_stats; + grpc_grpclb_client_stats* client_stats; /* Interval and timer for next client load report. */ grpc_millis client_stats_report_interval; grpc_timer client_load_report_timer; @@ -413,20 +413,20 @@ typedef struct glb_lb_policy { * completion of sending the load report. */ grpc_closure client_load_report_closure; /* Client load report message payload. */ - grpc_byte_buffer *client_load_report_payload; + grpc_byte_buffer* client_load_report_payload; } glb_lb_policy; /* Keeps track and reacts to changes in connectivity of the RR instance */ struct rr_connectivity_data { grpc_closure on_change; grpc_connectivity_state state; - glb_lb_policy *glb_policy; + glb_lb_policy* glb_policy; }; -static bool is_server_valid(const grpc_grpclb_server *server, size_t idx, +static bool is_server_valid(const grpc_grpclb_server* server, size_t idx, bool log) { if (server->drop) return false; - const grpc_grpclb_ip_address *ip = &server->ip_address; + const grpc_grpclb_ip_address* ip = &server->ip_address; if (server->port >> 16 != 0) { if (log) { gpr_log(GPR_ERROR, @@ -448,17 +448,17 @@ static bool is_server_valid(const grpc_grpclb_server *server, size_t idx, } /* vtable for LB tokens in grpc_lb_addresses. */ -static void *lb_token_copy(void *token) { +static void* lb_token_copy(void* token) { return token == NULL ? NULL - : (void *)GRPC_MDELEM_REF(grpc_mdelem{(uintptr_t)token}).payload; + : (void*)GRPC_MDELEM_REF(grpc_mdelem{(uintptr_t)token}).payload; } -static void lb_token_destroy(grpc_exec_ctx *exec_ctx, void *token) { +static void lb_token_destroy(grpc_exec_ctx* exec_ctx, void* token) { if (token != NULL) { GRPC_MDELEM_UNREF(exec_ctx, grpc_mdelem{(uintptr_t)token}); } } -static int lb_token_cmp(void *token1, void *token2) { +static int lb_token_cmp(void* token1, void* token2) { if (token1 > token2) return 1; if (token1 < token2) return -1; return 0; @@ -466,23 +466,23 @@ static int lb_token_cmp(void *token1, void *token2) { static const grpc_lb_user_data_vtable lb_token_vtable = { lb_token_copy, lb_token_destroy, lb_token_cmp}; -static void parse_server(const grpc_grpclb_server *server, - grpc_resolved_address *addr) { +static void parse_server(const grpc_grpclb_server* server, + grpc_resolved_address* addr) { memset(addr, 0, sizeof(*addr)); if (server->drop) return; const uint16_t netorder_port = htons((uint16_t)server->port); /* the addresses are given in binary format (a in(6)_addr struct) in * server->ip_address.bytes. */ - const grpc_grpclb_ip_address *ip = &server->ip_address; + const grpc_grpclb_ip_address* ip = &server->ip_address; if (ip->size == 4) { addr->len = sizeof(struct sockaddr_in); - struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr->addr; + struct sockaddr_in* addr4 = (struct sockaddr_in*)&addr->addr; addr4->sin_family = AF_INET; memcpy(&addr4->sin_addr, ip->bytes, ip->size); addr4->sin_port = netorder_port; } else if (ip->size == 16) { addr->len = sizeof(struct sockaddr_in6); - struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr->addr; + struct sockaddr_in6* addr6 = (struct sockaddr_in6*)&addr->addr; addr6->sin6_family = AF_INET6; memcpy(&addr6->sin6_addr, ip->bytes, ip->size); addr6->sin6_port = netorder_port; @@ -490,15 +490,15 @@ static void parse_server(const grpc_grpclb_server *server, } /* Returns addresses extracted from \a serverlist. */ -static grpc_lb_addresses *process_serverlist_locked( - grpc_exec_ctx *exec_ctx, const grpc_grpclb_serverlist *serverlist) { +static grpc_lb_addresses* process_serverlist_locked( + grpc_exec_ctx* exec_ctx, const grpc_grpclb_serverlist* serverlist) { size_t num_valid = 0; /* first pass: count how many are valid in order to allocate the necessary * memory in a single block */ for (size_t i = 0; i < serverlist->num_servers; ++i) { if (is_server_valid(serverlist->servers[i], i, true)) ++num_valid; } - grpc_lb_addresses *lb_addresses = + grpc_lb_addresses* lb_addresses = grpc_lb_addresses_create(num_valid, &lb_token_vtable); /* second pass: actually populate the addresses and LB tokens (aka user data * to the outside world) to be read by the RR policy during its creation. @@ -507,14 +507,14 @@ static grpc_lb_addresses *process_serverlist_locked( * incurr in an allocation due to the arbitrary number of server */ size_t addr_idx = 0; for (size_t sl_idx = 0; sl_idx < serverlist->num_servers; ++sl_idx) { - const grpc_grpclb_server *server = serverlist->servers[sl_idx]; + const grpc_grpclb_server* server = serverlist->servers[sl_idx]; if (!is_server_valid(serverlist->servers[sl_idx], sl_idx, false)) continue; GPR_ASSERT(addr_idx < num_valid); /* address processing */ grpc_resolved_address addr; parse_server(server, &addr); /* lb token processing */ - void *user_data; + void* user_data; if (server->has_load_balance_token) { const size_t lb_token_max_length = GPR_ARRAY_SIZE(server->load_balance_token); @@ -522,17 +522,17 @@ static grpc_lb_addresses *process_serverlist_locked( strnlen(server->load_balance_token, lb_token_max_length); grpc_slice lb_token_mdstr = grpc_slice_from_copied_buffer( server->load_balance_token, lb_token_length); - user_data = (void *)grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_LB_TOKEN, - lb_token_mdstr) + user_data = (void*)grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_LB_TOKEN, + lb_token_mdstr) .payload; } else { - char *uri = grpc_sockaddr_to_uri(&addr); + char* uri = grpc_sockaddr_to_uri(&addr); gpr_log(GPR_INFO, "Missing LB token for backend address '%s'. The empty token will " "be used instead", uri); gpr_free(uri); - user_data = (void *)GRPC_MDELEM_LB_TOKEN_EMPTY.payload; + user_data = (void*)GRPC_MDELEM_LB_TOKEN_EMPTY.payload; } grpc_lb_addresses_set_address(lb_addresses, addr_idx, &addr.addr, addr.len, @@ -545,8 +545,8 @@ static grpc_lb_addresses *process_serverlist_locked( } /* Returns the backend addresses extracted from the given addresses */ -static grpc_lb_addresses *extract_backend_addresses_locked( - grpc_exec_ctx *exec_ctx, const grpc_lb_addresses *addresses) { +static grpc_lb_addresses* extract_backend_addresses_locked( + grpc_exec_ctx* exec_ctx, const grpc_lb_addresses* addresses) { /* first pass: count the number of backend addresses */ size_t num_backends = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { @@ -555,24 +555,24 @@ static grpc_lb_addresses *extract_backend_addresses_locked( } } /* second pass: actually populate the addresses and (empty) LB tokens */ - grpc_lb_addresses *backend_addresses = + grpc_lb_addresses* backend_addresses = grpc_lb_addresses_create(num_backends, &lb_token_vtable); size_t num_copied = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (addresses->addresses[i].is_balancer) continue; - const grpc_resolved_address *addr = &addresses->addresses[i].address; + const grpc_resolved_address* addr = &addresses->addresses[i].address; grpc_lb_addresses_set_address(backend_addresses, num_copied, &addr->addr, addr->len, false /* is_balancer */, NULL /* balancer_name */, - (void *)GRPC_MDELEM_LB_TOKEN_EMPTY.payload); + (void*)GRPC_MDELEM_LB_TOKEN_EMPTY.payload); ++num_copied; } return backend_addresses; } static void update_lb_connectivity_status_locked( - grpc_exec_ctx *exec_ctx, glb_lb_policy *glb_policy, - grpc_connectivity_state rr_state, grpc_error *rr_state_error) { + grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, + grpc_connectivity_state rr_state, grpc_error* rr_state_error) { const grpc_connectivity_state curr_glb_state = grpc_connectivity_state_check(&glb_policy->state_tracker); @@ -620,7 +620,7 @@ static void update_lb_connectivity_status_locked( if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log( GPR_INFO, "Setting grpclb's state to %s from new RR policy %p state.", - grpc_connectivity_state_name(rr_state), (void *)glb_policy->rr_policy); + grpc_connectivity_state_name(rr_state), (void*)glb_policy->rr_policy); } grpc_connectivity_state_set(exec_ctx, &glb_policy->state_tracker, rr_state, rr_state_error, @@ -633,13 +633,13 @@ static void update_lb_connectivity_status_locked( * If \a force_async is true, then we will manually schedule the * completion callback even if the pick is available immediately. */ static bool pick_from_internal_rr_locked( - grpc_exec_ctx *exec_ctx, glb_lb_policy *glb_policy, - const grpc_lb_policy_pick_args *pick_args, bool force_async, - grpc_connected_subchannel **target, wrapped_rr_closure_arg *wc_arg) { + grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, + const grpc_lb_policy_pick_args* pick_args, bool force_async, + grpc_connected_subchannel** target, wrapped_rr_closure_arg* wc_arg) { // Check for drops if we are not using fallback backend addresses. if (glb_policy->serverlist != NULL) { // Look at the index into the serverlist to see if we should drop this call. - grpc_grpclb_server *server = + grpc_grpclb_server* server = glb_policy->serverlist->servers[glb_policy->serverlist_index++]; if (glb_policy->serverlist_index == glb_policy->serverlist->num_servers) { glb_policy->serverlist_index = 0; // Wrap-around. @@ -672,7 +672,7 @@ static bool pick_from_internal_rr_locked( // Pick via the RR policy. const bool pick_done = grpc_lb_policy_pick_locked( exec_ctx, wc_arg->rr_policy, pick_args, target, wc_arg->context, - (void **)&wc_arg->lb_token, &wc_arg->wrapper_closure); + (void**)&wc_arg->lb_token, &wc_arg->wrapper_closure); if (pick_done) { /* synchronous grpc_lb_policy_pick call. Unref the RR policy. */ if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { @@ -703,9 +703,9 @@ static bool pick_from_internal_rr_locked( return pick_done; } -static grpc_lb_policy_args *lb_policy_args_create(grpc_exec_ctx *exec_ctx, - glb_lb_policy *glb_policy) { - grpc_lb_addresses *addresses; +static grpc_lb_policy_args* lb_policy_args_create(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { + grpc_lb_addresses* addresses; if (glb_policy->serverlist != NULL) { GPR_ASSERT(glb_policy->serverlist->num_servers > 0); addresses = process_serverlist_locked(exec_ctx, glb_policy->serverlist); @@ -718,12 +718,12 @@ static grpc_lb_policy_args *lb_policy_args_create(grpc_exec_ctx *exec_ctx, addresses = grpc_lb_addresses_copy(glb_policy->fallback_backend_addresses); } GPR_ASSERT(addresses != NULL); - grpc_lb_policy_args *args = (grpc_lb_policy_args *)gpr_zalloc(sizeof(*args)); + grpc_lb_policy_args* args = (grpc_lb_policy_args*)gpr_zalloc(sizeof(*args)); args->client_channel_factory = glb_policy->cc_factory; args->combiner = glb_policy->base.combiner; // Replace the LB addresses in the channel args that we pass down to // the subchannel. - static const char *keys_to_remove[] = {GRPC_ARG_LB_ADDRESSES}; + static const char* keys_to_remove[] = {GRPC_ARG_LB_ADDRESSES}; const grpc_arg arg = grpc_lb_addresses_create_channel_arg(addresses); args->args = grpc_channel_args_copy_and_add_and_remove( glb_policy->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &arg, @@ -732,19 +732,19 @@ static grpc_lb_policy_args *lb_policy_args_create(grpc_exec_ctx *exec_ctx, return args; } -static void lb_policy_args_destroy(grpc_exec_ctx *exec_ctx, - grpc_lb_policy_args *args) { +static void lb_policy_args_destroy(grpc_exec_ctx* exec_ctx, + grpc_lb_policy_args* args) { grpc_channel_args_destroy(exec_ctx, args->args); gpr_free(args); } -static void glb_rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, - void *arg, grpc_error *error); -static void create_rr_locked(grpc_exec_ctx *exec_ctx, glb_lb_policy *glb_policy, - grpc_lb_policy_args *args) { +static void glb_rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error); +static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, + grpc_lb_policy_args* args) { GPR_ASSERT(glb_policy->rr_policy == NULL); - grpc_lb_policy *new_rr_policy = + grpc_lb_policy* new_rr_policy = grpc_lb_policy_create(exec_ctx, "round_robin", args); if (new_rr_policy == NULL) { gpr_log(GPR_ERROR, @@ -753,11 +753,11 @@ static void create_rr_locked(grpc_exec_ctx *exec_ctx, glb_lb_policy *glb_policy, "to be used. Future updates from the LB will attempt to create new " "instances.", (unsigned long)glb_policy->serverlist->num_servers, - (void *)glb_policy->rr_policy); + (void*)glb_policy->rr_policy); return; } glb_policy->rr_policy = new_rr_policy; - grpc_error *rr_state_error = NULL; + grpc_error* rr_state_error = NULL; const grpc_connectivity_state rr_state = grpc_lb_policy_check_connectivity_locked(exec_ctx, glb_policy->rr_policy, &rr_state_error); @@ -773,8 +773,8 @@ static void create_rr_locked(grpc_exec_ctx *exec_ctx, glb_lb_policy *glb_policy, /* Allocate the data for the tracking of the new RR policy's connectivity. * It'll be deallocated in glb_rr_connectivity_changed() */ - rr_connectivity_data *rr_connectivity = - (rr_connectivity_data *)gpr_zalloc(sizeof(rr_connectivity_data)); + rr_connectivity_data* rr_connectivity = + (rr_connectivity_data*)gpr_zalloc(sizeof(rr_connectivity_data)); GRPC_CLOSURE_INIT(&rr_connectivity->on_change, glb_rr_connectivity_changed_locked, rr_connectivity, grpc_combiner_scheduler(glb_policy->base.combiner)); @@ -789,7 +789,7 @@ static void create_rr_locked(grpc_exec_ctx *exec_ctx, glb_lb_policy *glb_policy, grpc_lb_policy_exit_idle_locked(exec_ctx, glb_policy->rr_policy); /* Update picks and pings in wait */ - pending_pick *pp; + pending_pick* pp; while ((pp = glb_policy->pending_picks)) { glb_policy->pending_picks = pp->next; GRPC_LB_POLICY_REF(glb_policy->rr_policy, "rr_handover_pending_pick"); @@ -798,14 +798,14 @@ static void create_rr_locked(grpc_exec_ctx *exec_ctx, glb_lb_policy *glb_policy, grpc_grpclb_client_stats_ref(glb_policy->client_stats); if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "Pending pick about to (async) PICK from %p", - (void *)glb_policy->rr_policy); + (void*)glb_policy->rr_policy); } pick_from_internal_rr_locked(exec_ctx, glb_policy, &pp->pick_args, true /* force_async */, pp->target, &pp->wrapped_on_complete_arg); } - pending_ping *pping; + pending_ping* pping; while ((pping = glb_policy->pending_pings)) { glb_policy->pending_pings = pping->next; GRPC_LB_POLICY_REF(glb_policy->rr_policy, "rr_handover_pending_ping"); @@ -820,31 +820,31 @@ static void create_rr_locked(grpc_exec_ctx *exec_ctx, glb_lb_policy *glb_policy, } /* glb_policy->rr_policy may be NULL (initial handover) */ -static void rr_handover_locked(grpc_exec_ctx *exec_ctx, - glb_lb_policy *glb_policy) { +static void rr_handover_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { if (glb_policy->shutting_down) return; - grpc_lb_policy_args *args = lb_policy_args_create(exec_ctx, glb_policy); + grpc_lb_policy_args* args = lb_policy_args_create(exec_ctx, glb_policy); GPR_ASSERT(args != NULL); if (glb_policy->rr_policy != NULL) { if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_DEBUG, "Updating Round Robin policy (%p)", - (void *)glb_policy->rr_policy); + (void*)glb_policy->rr_policy); } grpc_lb_policy_update_locked(exec_ctx, glb_policy->rr_policy, args); } else { create_rr_locked(exec_ctx, glb_policy, args); if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_DEBUG, "Created new Round Robin policy (%p)", - (void *)glb_policy->rr_policy); + (void*)glb_policy->rr_policy); } } lb_policy_args_destroy(exec_ctx, args); } -static void glb_rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, - void *arg, grpc_error *error) { - rr_connectivity_data *rr_connectivity = (rr_connectivity_data *)arg; - glb_lb_policy *glb_policy = rr_connectivity->glb_policy; +static void glb_rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { + rr_connectivity_data* rr_connectivity = (rr_connectivity_data*)arg; + glb_lb_policy* glb_policy = rr_connectivity->glb_policy; if (glb_policy->shutting_down) { GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "glb_rr_connectivity_cb"); @@ -872,22 +872,22 @@ static void glb_rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, &rr_connectivity->on_change); } -static void destroy_balancer_name(grpc_exec_ctx *exec_ctx, - void *balancer_name) { +static void destroy_balancer_name(grpc_exec_ctx* exec_ctx, + void* balancer_name) { gpr_free(balancer_name); } static grpc_slice_hash_table_entry targets_info_entry_create( - const char *address, const char *balancer_name) { + const char* address, const char* balancer_name) { grpc_slice_hash_table_entry entry; entry.key = grpc_slice_from_copied_string(address); entry.value = gpr_strdup(balancer_name); return entry; } -static int balancer_name_cmp_fn(void *a, void *b) { - const char *a_str = (const char *)a; - const char *b_str = (const char *)b; +static int balancer_name_cmp_fn(void* a, void* b) { + const char* a_str = (const char*)a; + const char* b_str = (const char*)b; return strcmp(a_str, b_str); } @@ -899,10 +899,10 @@ static int balancer_name_cmp_fn(void *a, void *b) { * - \a response_generator: in order to propagate updates from the resolver * above the grpclb policy. * - \a args: other args inherited from the grpclb policy. */ -static grpc_channel_args *build_lb_channel_args( - grpc_exec_ctx *exec_ctx, const grpc_lb_addresses *addresses, - grpc_fake_resolver_response_generator *response_generator, - const grpc_channel_args *args) { +static grpc_channel_args* build_lb_channel_args( + grpc_exec_ctx* exec_ctx, const grpc_lb_addresses* addresses, + grpc_fake_resolver_response_generator* response_generator, + const grpc_channel_args* args) { size_t num_grpclb_addrs = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (addresses->addresses[i].is_balancer) ++num_grpclb_addrs; @@ -911,11 +911,11 @@ static grpc_channel_args *build_lb_channel_args( * It's the resolver's responsibility to make sure this policy is only * instantiated and used in that case. Otherwise, something has gone wrong. */ GPR_ASSERT(num_grpclb_addrs > 0); - grpc_lb_addresses *lb_addresses = + grpc_lb_addresses* lb_addresses = grpc_lb_addresses_create(num_grpclb_addrs, NULL); - grpc_slice_hash_table_entry *targets_info_entries = - (grpc_slice_hash_table_entry *)gpr_zalloc(sizeof(*targets_info_entries) * - num_grpclb_addrs); + grpc_slice_hash_table_entry* targets_info_entries = + (grpc_slice_hash_table_entry*)gpr_zalloc(sizeof(*targets_info_entries) * + num_grpclb_addrs); size_t lb_addresses_idx = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { @@ -924,7 +924,7 @@ static grpc_channel_args *build_lb_channel_args( gpr_log(GPR_ERROR, "This LB policy doesn't support user data. It will be ignored"); } - char *addr_str; + char* addr_str; GPR_ASSERT(grpc_sockaddr_to_string( &addr_str, &addresses->addresses[i].address, true) > 0); targets_info_entries[lb_addresses_idx] = targets_info_entry_create( @@ -937,19 +937,19 @@ static grpc_channel_args *build_lb_channel_args( addresses->addresses[i].balancer_name, NULL /* user data */); } GPR_ASSERT(num_grpclb_addrs == lb_addresses_idx); - grpc_slice_hash_table *targets_info = + grpc_slice_hash_table* targets_info = grpc_slice_hash_table_create(num_grpclb_addrs, targets_info_entries, destroy_balancer_name, balancer_name_cmp_fn); gpr_free(targets_info_entries); - grpc_channel_args *lb_channel_args = + grpc_channel_args* lb_channel_args = grpc_lb_policy_grpclb_build_lb_channel_args(exec_ctx, targets_info, response_generator, args); grpc_arg lb_channel_addresses_arg = grpc_lb_addresses_create_channel_arg(lb_addresses); - grpc_channel_args *result = grpc_channel_args_copy_and_add( + grpc_channel_args* result = grpc_channel_args_copy_and_add( lb_channel_args, &lb_channel_addresses_arg, 1); grpc_slice_hash_table_unref(exec_ctx, targets_info); grpc_channel_args_destroy(exec_ctx, lb_channel_args); @@ -957,11 +957,11 @@ static grpc_channel_args *build_lb_channel_args( return result; } -static void glb_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { - glb_lb_policy *glb_policy = (glb_lb_policy *)pol; +static void glb_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { + glb_lb_policy* glb_policy = (glb_lb_policy*)pol; GPR_ASSERT(glb_policy->pending_picks == NULL); GPR_ASSERT(glb_policy->pending_pings == NULL); - gpr_free((void *)glb_policy->server_name); + gpr_free((void*)glb_policy->server_name); grpc_channel_args_destroy(exec_ctx, glb_policy->args); if (glb_policy->client_stats != NULL) { grpc_grpclb_client_stats_unref(glb_policy->client_stats); @@ -978,14 +978,14 @@ static void glb_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { gpr_free(glb_policy); } -static void glb_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { - glb_lb_policy *glb_policy = (glb_lb_policy *)pol; +static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { + glb_lb_policy* glb_policy = (glb_lb_policy*)pol; glb_policy->shutting_down = true; /* We need a copy of the lb_call pointer because we can't cancell the call * while holding glb_policy->mu: lb_on_server_status_received, invoked due to * the cancel, needs to acquire that same lock */ - grpc_call *lb_call = glb_policy->lb_call; + grpc_call* lb_call = glb_policy->lb_call; /* glb_policy->lb_call and this local lb_call must be consistent at this point * because glb_policy->lb_call is only assigned in lb_call_init_locked as part @@ -1004,9 +1004,9 @@ static void glb_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { glb_policy->fallback_timer_active = false; } - pending_pick *pp = glb_policy->pending_picks; + pending_pick* pp = glb_policy->pending_picks; glb_policy->pending_picks = NULL; - pending_ping *pping = glb_policy->pending_pings; + pending_ping* pping = glb_policy->pending_pings; glb_policy->pending_pings = NULL; if (glb_policy->rr_policy != NULL) { GRPC_LB_POLICY_UNREF(exec_ctx, glb_policy->rr_policy, "glb_shutdown"); @@ -1024,7 +1024,7 @@ static void glb_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Shutdown"), "glb_shutdown"); while (pp != NULL) { - pending_pick *next = pp->next; + pending_pick* next = pp->next; *pp->target = NULL; GRPC_CLOSURE_SCHED( exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, @@ -1034,7 +1034,7 @@ static void glb_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { } while (pping != NULL) { - pending_ping *next = pping->next; + pending_ping* next = pping->next; GRPC_CLOSURE_SCHED( exec_ctx, &pping->wrapped_notify_arg.wrapper_closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Shutdown")); @@ -1053,14 +1053,14 @@ static void glb_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { // - Otherwise, without an RR instance, picks stay pending at this policy's // level (grpclb), inside the glb_policy->pending_picks list. To cancel these, // we invoke the completion closure and set *target to NULL right here. -static void glb_cancel_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, - grpc_connected_subchannel **target, - grpc_error *error) { - glb_lb_policy *glb_policy = (glb_lb_policy *)pol; - pending_pick *pp = glb_policy->pending_picks; +static void glb_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + grpc_connected_subchannel** target, + grpc_error* error) { + glb_lb_policy* glb_policy = (glb_lb_policy*)pol; + pending_pick* pp = glb_policy->pending_picks; glb_policy->pending_picks = NULL; while (pp != NULL) { - pending_pick *next = pp->next; + pending_pick* next = pp->next; if (pp->target == target) { *target = NULL; GRPC_CLOSURE_SCHED(exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, @@ -1089,16 +1089,16 @@ static void glb_cancel_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, // - Otherwise, without an RR instance, picks stay pending at this policy's // level (grpclb), inside the glb_policy->pending_picks list. To cancel these, // we invoke the completion closure and set *target to NULL right here. -static void glb_cancel_picks_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *pol, +static void glb_cancel_picks_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, - grpc_error *error) { - glb_lb_policy *glb_policy = (glb_lb_policy *)pol; - pending_pick *pp = glb_policy->pending_picks; + grpc_error* error) { + glb_lb_policy* glb_policy = (glb_lb_policy*)pol; + pending_pick* pp = glb_policy->pending_picks; glb_policy->pending_picks = NULL; while (pp != NULL) { - pending_pick *next = pp->next; + pending_pick* next = pp->next; if ((pp->pick_args.initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { GRPC_CLOSURE_SCHED(exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, @@ -1118,12 +1118,12 @@ static void glb_cancel_picks_locked(grpc_exec_ctx *exec_ctx, GRPC_ERROR_UNREF(error); } -static void lb_on_fallback_timer_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error); -static void query_for_backends_locked(grpc_exec_ctx *exec_ctx, - glb_lb_policy *glb_policy); -static void start_picking_locked(grpc_exec_ctx *exec_ctx, - glb_lb_policy *glb_policy) { +static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); +static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy); +static void start_picking_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { /* start a timer to fall back */ if (glb_policy->lb_fallback_timeout_ms > 0 && glb_policy->serverlist == NULL && !glb_policy->fallback_timer_active) { @@ -1143,18 +1143,18 @@ static void start_picking_locked(grpc_exec_ctx *exec_ctx, query_for_backends_locked(exec_ctx, glb_policy); } -static void glb_exit_idle_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { - glb_lb_policy *glb_policy = (glb_lb_policy *)pol; +static void glb_exit_idle_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { + glb_lb_policy* glb_policy = (glb_lb_policy*)pol; if (!glb_policy->started_picking) { start_picking_locked(exec_ctx, glb_policy); } } -static int glb_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, - const grpc_lb_policy_pick_args *pick_args, - grpc_connected_subchannel **target, - grpc_call_context_element *context, void **user_data, - grpc_closure *on_complete) { +static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + const grpc_lb_policy_pick_args* pick_args, + grpc_connected_subchannel** target, + grpc_call_context_element* context, void** user_data, + grpc_closure* on_complete) { if (pick_args->lb_token_mdelem_storage == NULL) { *target = NULL; GRPC_CLOSURE_SCHED(exec_ctx, on_complete, @@ -1163,7 +1163,7 @@ static int glb_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, "won't work without it. Failing")); return 0; } - glb_lb_policy *glb_policy = (glb_lb_policy *)pol; + glb_lb_policy* glb_policy = (glb_lb_policy*)pol; bool pick_done = false; if (glb_policy->rr_policy != NULL) { const grpc_connectivity_state rr_connectivity_state = @@ -1178,7 +1178,7 @@ static int glb_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "grpclb %p NOT picking from from RR %p: RR conn state=%s", - (void *)glb_policy, (void *)glb_policy->rr_policy, + (void*)glb_policy, (void*)glb_policy->rr_policy, grpc_connectivity_state_name(rr_connectivity_state)); } add_pending_pick(&glb_policy->pending_picks, pick_args, target, context, @@ -1187,11 +1187,11 @@ static int glb_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, } else { // RR not in shutdown if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "grpclb %p about to PICK from RR %p", - (void *)glb_policy, (void *)glb_policy->rr_policy); + (void*)glb_policy, (void*)glb_policy->rr_policy); } GRPC_LB_POLICY_REF(glb_policy->rr_policy, "glb_pick"); - wrapped_rr_closure_arg *wc_arg = - (wrapped_rr_closure_arg *)gpr_zalloc(sizeof(wrapped_rr_closure_arg)); + wrapped_rr_closure_arg* wc_arg = + (wrapped_rr_closure_arg*)gpr_zalloc(sizeof(wrapped_rr_closure_arg)); GRPC_CLOSURE_INIT(&wc_arg->wrapper_closure, wrapped_rr_closure, wc_arg, grpc_schedule_on_exec_ctx); wc_arg->rr_policy = glb_policy->rr_policy; @@ -1213,7 +1213,7 @@ static int glb_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, gpr_log(GPR_DEBUG, "No RR policy in grpclb instance %p. Adding to grpclb's pending " "picks", - (void *)(glb_policy)); + (void*)(glb_policy)); } add_pending_pick(&glb_policy->pending_picks, pick_args, target, context, on_complete); @@ -1226,16 +1226,16 @@ static int glb_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, } static grpc_connectivity_state glb_check_connectivity_locked( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, - grpc_error **connectivity_error) { - glb_lb_policy *glb_policy = (glb_lb_policy *)pol; + grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + grpc_error** connectivity_error) { + glb_lb_policy* glb_policy = (glb_lb_policy*)pol; return grpc_connectivity_state_get(&glb_policy->state_tracker, connectivity_error); } -static void glb_ping_one_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, - grpc_closure *closure) { - glb_lb_policy *glb_policy = (glb_lb_policy *)pol; +static void glb_ping_one_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + grpc_closure* closure) { + glb_lb_policy* glb_policy = (glb_lb_policy*)pol; if (glb_policy->rr_policy) { grpc_lb_policy_ping_one_locked(exec_ctx, glb_policy->rr_policy, closure); } else { @@ -1246,23 +1246,23 @@ static void glb_ping_one_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, } } -static void glb_notify_on_state_change_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *pol, - grpc_connectivity_state *current, - grpc_closure *notify) { - glb_lb_policy *glb_policy = (glb_lb_policy *)pol; +static void glb_notify_on_state_change_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* pol, + grpc_connectivity_state* current, + grpc_closure* notify) { + glb_lb_policy* glb_policy = (glb_lb_policy*)pol; grpc_connectivity_state_notify_on_state_change( exec_ctx, &glb_policy->state_tracker, current, notify); } -static void lb_call_on_retry_timer_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - glb_lb_policy *glb_policy = (glb_lb_policy *)arg; +static void lb_call_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + glb_lb_policy* glb_policy = (glb_lb_policy*)arg; glb_policy->retry_timer_active = false; if (!glb_policy->shutting_down && error == GRPC_ERROR_NONE) { if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "Restaring call to LB server (grpclb %p)", - (void *)glb_policy); + (void*)glb_policy); } GPR_ASSERT(glb_policy->lb_call == NULL); query_for_backends_locked(exec_ctx, glb_policy); @@ -1270,8 +1270,8 @@ static void lb_call_on_retry_timer_locked(grpc_exec_ctx *exec_ctx, void *arg, GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "grpclb_retry_timer"); } -static void maybe_restart_lb_call(grpc_exec_ctx *exec_ctx, - glb_lb_policy *glb_policy) { +static void maybe_restart_lb_call(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { if (glb_policy->started_picking && glb_policy->updating_lb_call) { if (glb_policy->retry_timer_active) { grpc_timer_cancel(exec_ctx, &glb_policy->lb_call_retry_timer); @@ -1285,7 +1285,7 @@ static void maybe_restart_lb_call(grpc_exec_ctx *exec_ctx, .next_attempt_start_time; if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_DEBUG, "Connection to LB server lost (grpclb: %p)...", - (void *)glb_policy); + (void*)glb_policy); grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); if (timeout > 0) { gpr_log(GPR_DEBUG, "... retry_timer_active in %" PRIdPTR "ms.", @@ -1306,11 +1306,11 @@ static void maybe_restart_lb_call(grpc_exec_ctx *exec_ctx, "lb_on_server_status_received_locked"); } -static void send_client_load_report_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error); +static void send_client_load_report_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); -static void schedule_next_client_load_report(grpc_exec_ctx *exec_ctx, - glb_lb_policy *glb_policy) { +static void schedule_next_client_load_report(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { const grpc_millis next_client_load_report_time = grpc_exec_ctx_now(exec_ctx) + glb_policy->client_stats_report_interval; GRPC_CLOSURE_INIT(&glb_policy->client_load_report_closure, @@ -1321,9 +1321,9 @@ static void schedule_next_client_load_report(grpc_exec_ctx *exec_ctx, &glb_policy->client_load_report_closure); } -static void client_load_report_done_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - glb_lb_policy *glb_policy = (glb_lb_policy *)arg; +static void client_load_report_done_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + glb_lb_policy* glb_policy = (glb_lb_policy*)arg; grpc_byte_buffer_destroy(glb_policy->client_load_report_payload); glb_policy->client_load_report_payload = NULL; if (error != GRPC_ERROR_NONE || glb_policy->lb_call == NULL) { @@ -1335,9 +1335,9 @@ static void client_load_report_done_locked(grpc_exec_ctx *exec_ctx, void *arg, schedule_next_client_load_report(exec_ctx, glb_policy); } -static bool load_report_counters_are_zero(grpc_grpclb_request *request) { - grpc_grpclb_dropped_call_counts *drop_entries = - (grpc_grpclb_dropped_call_counts *) +static bool load_report_counters_are_zero(grpc_grpclb_request* request) { + grpc_grpclb_dropped_call_counts* drop_entries = + (grpc_grpclb_dropped_call_counts*) request->client_stats.calls_finished_with_drop.arg; return request->client_stats.num_calls_started == 0 && request->client_stats.num_calls_finished == 0 && @@ -1347,9 +1347,9 @@ static bool load_report_counters_are_zero(grpc_grpclb_request *request) { (drop_entries == NULL || drop_entries->num_entries == 0); } -static void send_client_load_report_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - glb_lb_policy *glb_policy = (glb_lb_policy *)arg; +static void send_client_load_report_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + glb_lb_policy* glb_policy = (glb_lb_policy*)arg; if (error == GRPC_ERROR_CANCELLED || glb_policy->lb_call == NULL) { glb_policy->client_load_report_timer_pending = false; GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, @@ -1361,7 +1361,7 @@ static void send_client_load_report_locked(grpc_exec_ctx *exec_ctx, void *arg, } // Construct message payload. GPR_ASSERT(glb_policy->client_load_report_payload == NULL); - grpc_grpclb_request *request = + grpc_grpclb_request* request = grpc_grpclb_load_report_request_create_locked(glb_policy->client_stats); // Skip client load report if the counters were all zero in the last // report and they are still zero in this one. @@ -1397,12 +1397,12 @@ static void send_client_load_report_locked(grpc_exec_ctx *exec_ctx, void *arg, } } -static void lb_on_server_status_received_locked(grpc_exec_ctx *exec_ctx, - void *arg, grpc_error *error); -static void lb_on_response_received_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error); -static void lb_call_init_locked(grpc_exec_ctx *exec_ctx, - glb_lb_policy *glb_policy) { +static void lb_on_server_status_received_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error); +static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); +static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { GPR_ASSERT(glb_policy->server_name != NULL); GPR_ASSERT(glb_policy->server_name[0] != '\0'); GPR_ASSERT(glb_policy->lb_call == NULL); @@ -1431,7 +1431,7 @@ static void lb_call_init_locked(grpc_exec_ctx *exec_ctx, grpc_metadata_array_init(&glb_policy->lb_initial_metadata_recv); grpc_metadata_array_init(&glb_policy->lb_trailing_metadata_recv); - grpc_grpclb_request *request = + grpc_grpclb_request* request = grpc_grpclb_request_create(glb_policy->server_name); grpc_slice request_payload_slice = grpc_grpclb_request_encode(request); glb_policy->lb_request_payload = @@ -1457,8 +1457,8 @@ static void lb_call_init_locked(grpc_exec_ctx *exec_ctx, glb_policy->last_client_load_report_counters_were_zero = false; } -static void lb_call_destroy_locked(grpc_exec_ctx *exec_ctx, - glb_lb_policy *glb_policy) { +static void lb_call_destroy_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { GPR_ASSERT(glb_policy->lb_call != NULL); grpc_call_unref(glb_policy->lb_call); glb_policy->lb_call = NULL; @@ -1477,8 +1477,8 @@ static void lb_call_destroy_locked(grpc_exec_ctx *exec_ctx, /* * Auxiliary functions and LB client callbacks. */ -static void query_for_backends_locked(grpc_exec_ctx *exec_ctx, - glb_lb_policy *glb_policy) { +static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy) { GPR_ASSERT(glb_policy->lb_channel != NULL); if (glb_policy->shutting_down) return; @@ -1487,8 +1487,8 @@ static void query_for_backends_locked(grpc_exec_ctx *exec_ctx, if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "Query for backends (grpclb: %p, lb_channel: %p, lb_call: %p)", - (void *)glb_policy, (void *)glb_policy->lb_channel, - (void *)glb_policy->lb_call); + (void*)glb_policy, (void*)glb_policy->lb_channel, + (void*)glb_policy->lb_call); } GPR_ASSERT(glb_policy->lb_call != NULL); @@ -1496,7 +1496,7 @@ static void query_for_backends_locked(grpc_exec_ctx *exec_ctx, grpc_op ops[3]; memset(ops, 0, sizeof(ops)); - grpc_op *op = ops; + grpc_op* op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op->flags = 0; @@ -1552,12 +1552,12 @@ static void query_for_backends_locked(grpc_exec_ctx *exec_ctx, GPR_ASSERT(GRPC_CALL_OK == call_error); } -static void lb_on_response_received_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - glb_lb_policy *glb_policy = (glb_lb_policy *)arg; +static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + glb_lb_policy* glb_policy = (glb_lb_policy*)arg; grpc_op ops[2]; memset(ops, 0, sizeof(ops)); - grpc_op *op = ops; + grpc_op* op = ops; if (glb_policy->lb_response_payload != NULL) { grpc_backoff_reset(&glb_policy->lb_call_backoff_state); /* Received data from the LB server. Look inside @@ -1568,7 +1568,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx *exec_ctx, void *arg, grpc_byte_buffer_reader_destroy(&bbr); grpc_byte_buffer_destroy(glb_policy->lb_response_payload); - grpc_grpclb_initial_response *response = NULL; + grpc_grpclb_initial_response* response = NULL; if (!glb_policy->seen_initial_response && (response = grpc_grpclb_initial_response_parse(response_slice)) != NULL) { @@ -1596,7 +1596,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx *exec_ctx, void *arg, grpc_grpclb_initial_response_destroy(response); glb_policy->seen_initial_response = true; } else { - grpc_grpclb_serverlist *serverlist = + grpc_grpclb_serverlist* serverlist = grpc_grpclb_response_parse_serverlist(response_slice); if (serverlist != NULL) { GPR_ASSERT(glb_policy->lb_call != NULL); @@ -1606,7 +1606,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx *exec_ctx, void *arg, for (size_t i = 0; i < serverlist->num_servers; ++i) { grpc_resolved_address addr; parse_server(serverlist->servers[i], &addr); - char *ipport; + char* ipport; grpc_sockaddr_to_string(&ipport, &addr, false); gpr_log(GPR_INFO, "Serverlist[%lu]: %s", (unsigned long)i, ipport); gpr_free(ipport); @@ -1679,9 +1679,9 @@ static void lb_on_response_received_locked(grpc_exec_ctx *exec_ctx, void *arg, } } -static void lb_on_fallback_timer_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - glb_lb_policy *glb_policy = (glb_lb_policy *)arg; +static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + glb_lb_policy* glb_policy = (glb_lb_policy*)arg; glb_policy->fallback_timer_active = false; /* If we receive a serverlist after the timer fires but before this callback * actually runs, don't fall back. */ @@ -1690,7 +1690,7 @@ static void lb_on_fallback_timer_locked(grpc_exec_ctx *exec_ctx, void *arg, if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "Falling back to use backends from resolver (grpclb %p)", - (void *)glb_policy); + (void*)glb_policy); } GPR_ASSERT(glb_policy->fallback_backend_addresses != NULL); rr_handover_locked(exec_ctx, glb_policy); @@ -1700,18 +1700,18 @@ static void lb_on_fallback_timer_locked(grpc_exec_ctx *exec_ctx, void *arg, "grpclb_fallback_timer"); } -static void lb_on_server_status_received_locked(grpc_exec_ctx *exec_ctx, - void *arg, grpc_error *error) { - glb_lb_policy *glb_policy = (glb_lb_policy *)arg; +static void lb_on_server_status_received_locked(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error) { + glb_lb_policy* glb_policy = (glb_lb_policy*)arg; GPR_ASSERT(glb_policy->lb_call != NULL); if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { - char *status_details = + char* status_details = grpc_slice_to_c_string(glb_policy->lb_call_status_details); gpr_log(GPR_INFO, "Status from LB server received. Status = %d, Details = '%s', " "(call: %p), error %p", glb_policy->lb_call_status, status_details, - (void *)glb_policy->lb_call, (void *)error); + (void*)glb_policy->lb_call, (void*)error); gpr_free(status_details); } /* We need to perform cleanups no matter what. */ @@ -1724,9 +1724,9 @@ static void lb_on_server_status_received_locked(grpc_exec_ctx *exec_ctx, } } -static void fallback_update_locked(grpc_exec_ctx *exec_ctx, - glb_lb_policy *glb_policy, - const grpc_lb_addresses *addresses) { +static void fallback_update_locked(grpc_exec_ctx* exec_ctx, + glb_lb_policy* glb_policy, + const grpc_lb_addresses* addresses) { GPR_ASSERT(glb_policy->fallback_backend_addresses != NULL); grpc_lb_addresses_destroy(exec_ctx, glb_policy->fallback_backend_addresses); glb_policy->fallback_backend_addresses = @@ -1737,10 +1737,10 @@ static void fallback_update_locked(grpc_exec_ctx *exec_ctx, } } -static void glb_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - const grpc_lb_policy_args *args) { - glb_lb_policy *glb_policy = (glb_lb_policy *)policy; - const grpc_arg *arg = +static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + const grpc_lb_policy_args* args) { + glb_lb_policy* glb_policy = (glb_lb_policy*)policy; + const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); if (arg == NULL || arg->type != GRPC_ARG_POINTER) { if (glb_policy->lb_channel == NULL) { @@ -1755,12 +1755,12 @@ static void glb_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, gpr_log(GPR_ERROR, "No valid LB addresses channel arg for grpclb %p update, " "ignoring.", - (void *)glb_policy); + (void*)glb_policy); } return; } - const grpc_lb_addresses *addresses = - (const grpc_lb_addresses *)arg->value.pointer.p; + const grpc_lb_addresses* addresses = + (const grpc_lb_addresses*)arg->value.pointer.p; // If a non-empty serverlist hasn't been received from the balancer, // propagate the update to fallback_backend_addresses. if (glb_policy->serverlist == NULL) { @@ -1769,7 +1769,7 @@ static void glb_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, GPR_ASSERT(glb_policy->lb_channel != NULL); // Propagate updates to the LB channel (pick_first) through the fake // resolver. - grpc_channel_args *lb_channel_args = build_lb_channel_args( + grpc_channel_args* lb_channel_args = build_lb_channel_args( exec_ctx, addresses, glb_policy->response_generator, args->args); grpc_fake_resolver_response_generator_set_response( exec_ctx, glb_policy->response_generator, lb_channel_args); @@ -1779,7 +1779,7 @@ static void glb_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, if (!glb_policy->watching_lb_channel) { glb_policy->lb_channel_connectivity = grpc_channel_check_connectivity_state( glb_policy->lb_channel, true /* try to connect */); - grpc_channel_element *client_channel_elem = grpc_channel_stack_last_element( + grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element( grpc_channel_get_channel_stack(glb_policy->lb_channel)); GPR_ASSERT(client_channel_elem->filter == &grpc_client_channel_filter); glb_policy->watching_lb_channel = true; @@ -1796,10 +1796,10 @@ static void glb_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, // Invoked as part of the update process. It continues watching the LB channel // until it shuts down or becomes READY. It's invoked even if the LB channel // stayed READY throughout the update (for example if the update is identical). -static void glb_lb_channel_on_connectivity_changed_cb(grpc_exec_ctx *exec_ctx, - void *arg, - grpc_error *error) { - glb_lb_policy *glb_policy = (glb_lb_policy *)arg; +static void glb_lb_channel_on_connectivity_changed_cb(grpc_exec_ctx* exec_ctx, + void* arg, + grpc_error* error) { + glb_lb_policy* glb_policy = (glb_lb_policy*)arg; if (glb_policy->shutting_down) goto done; // Re-initialize the lb_call. This should also take care of updating the // embedded RR policy. Note that the current RR policy, if any, will stay in @@ -1808,7 +1808,7 @@ static void glb_lb_channel_on_connectivity_changed_cb(grpc_exec_ctx *exec_ctx, case GRPC_CHANNEL_CONNECTING: case GRPC_CHANNEL_TRANSIENT_FAILURE: { /* resub. */ - grpc_channel_element *client_channel_elem = + grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element( grpc_channel_get_channel_stack(glb_policy->lb_channel)); GPR_ASSERT(client_channel_elem->filter == &grpc_client_channel_filter); @@ -1860,29 +1860,29 @@ static const grpc_lb_policy_vtable glb_lb_policy_vtable = { glb_notify_on_state_change_locked, glb_update_locked}; -static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, - grpc_lb_policy_factory *factory, - grpc_lb_policy_args *args) { +static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, + grpc_lb_policy_factory* factory, + grpc_lb_policy_args* args) { /* Count the number of gRPC-LB addresses. There must be at least one. */ - const grpc_arg *arg = + const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); if (arg == NULL || arg->type != GRPC_ARG_POINTER) { return NULL; } - grpc_lb_addresses *addresses = (grpc_lb_addresses *)arg->value.pointer.p; + grpc_lb_addresses* addresses = (grpc_lb_addresses*)arg->value.pointer.p; size_t num_grpclb_addrs = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (addresses->addresses[i].is_balancer) ++num_grpclb_addrs; } if (num_grpclb_addrs == 0) return NULL; - glb_lb_policy *glb_policy = (glb_lb_policy *)gpr_zalloc(sizeof(*glb_policy)); + glb_lb_policy* glb_policy = (glb_lb_policy*)gpr_zalloc(sizeof(*glb_policy)); /* Get server name. */ arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_URI); GPR_ASSERT(arg != NULL); GPR_ASSERT(arg->type == GRPC_ARG_STRING); - grpc_uri *uri = grpc_uri_parse(exec_ctx, arg->value.string, true); + grpc_uri* uri = grpc_uri_parse(exec_ctx, arg->value.string, true); GPR_ASSERT(uri->path[0] != '\0'); glb_policy->server_name = gpr_strdup(uri->path[0] == '/' ? uri->path + 1 : uri->path); @@ -1906,8 +1906,8 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, // Make sure that GRPC_ARG_LB_POLICY_NAME is set in channel args, // since we use this to trigger the client_load_reporting filter. grpc_arg new_arg = grpc_channel_arg_string_create( - (char *)GRPC_ARG_LB_POLICY_NAME, (char *)"grpclb"); - static const char *args_to_remove[] = {GRPC_ARG_LB_POLICY_NAME}; + (char*)GRPC_ARG_LB_POLICY_NAME, (char*)"grpclb"); + static const char* args_to_remove[] = {GRPC_ARG_LB_POLICY_NAME}; glb_policy->args = grpc_channel_args_copy_and_add_and_remove( args->args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), &new_arg, 1); @@ -1919,9 +1919,9 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, /* Create a client channel over them to communicate with a LB service */ glb_policy->response_generator = grpc_fake_resolver_response_generator_create(); - grpc_channel_args *lb_channel_args = build_lb_channel_args( + grpc_channel_args* lb_channel_args = build_lb_channel_args( exec_ctx, addresses, glb_policy->response_generator, args->args); - char *uri_str; + char* uri_str; gpr_asprintf(&uri_str, "fake:///%s", glb_policy->server_name); glb_policy->lb_channel = grpc_lb_policy_grpclb_create_lb_channel( exec_ctx, uri_str, args->client_channel_factory, lb_channel_args); @@ -1932,7 +1932,7 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, grpc_channel_args_destroy(exec_ctx, lb_channel_args); gpr_free(uri_str); if (glb_policy->lb_channel == NULL) { - gpr_free((void *)glb_policy->server_name); + gpr_free((void*)glb_policy->server_name); grpc_channel_args_destroy(exec_ctx, glb_policy->args); gpr_free(glb_policy); return NULL; @@ -1947,16 +1947,16 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx, return &glb_policy->base; } -static void glb_factory_ref(grpc_lb_policy_factory *factory) {} +static void glb_factory_ref(grpc_lb_policy_factory* factory) {} -static void glb_factory_unref(grpc_lb_policy_factory *factory) {} +static void glb_factory_unref(grpc_lb_policy_factory* factory) {} static const grpc_lb_policy_factory_vtable glb_factory_vtable = { glb_factory_ref, glb_factory_unref, glb_create, "grpclb"}; static grpc_lb_policy_factory glb_lb_policy_factory = {&glb_factory_vtable}; -grpc_lb_policy_factory *grpc_glb_lb_factory_create() { +grpc_lb_policy_factory* grpc_glb_lb_factory_create() { return &glb_lb_policy_factory; } @@ -1964,15 +1964,15 @@ grpc_lb_policy_factory *grpc_glb_lb_factory_create() { // Only add client_load_reporting filter if the grpclb LB policy is used. static bool maybe_add_client_load_reporting_filter( - grpc_exec_ctx *exec_ctx, grpc_channel_stack_builder *builder, void *arg) { - const grpc_channel_args *args = + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { + const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); - const grpc_arg *channel_arg = + const grpc_arg* channel_arg = grpc_channel_args_find(args, GRPC_ARG_LB_POLICY_NAME); if (channel_arg != NULL && channel_arg->type == GRPC_ARG_STRING && strcmp(channel_arg->value.string, "grpclb") == 0) { return grpc_channel_stack_builder_append_filter( - builder, (const grpc_channel_filter *)arg, NULL, NULL); + builder, (const grpc_channel_filter*)arg, NULL, NULL); } return true; } @@ -1986,7 +1986,7 @@ extern "C" void grpc_lb_policy_grpclb_init() { grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, maybe_add_client_load_reporting_filter, - (void *)&grpc_client_load_reporting_filter); + (void*)&grpc_client_load_reporting_filter); } extern "C" void grpc_lb_policy_grpclb_shutdown() {} diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h index 15c8a680b7..b6135a4768 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h @@ -28,7 +28,7 @@ extern "C" { /** Returns a load balancing factory for the glb policy, which tries to connect * to a load balancing server to decide the next successfully connected * subchannel to pick. */ -grpc_lb_policy_factory *grpc_glb_lb_factory_create(); +grpc_lb_policy_factory* grpc_glb_lb_factory_create(); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc index f2967182e2..aacaec197d 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc @@ -25,20 +25,20 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/support/string.h" -grpc_channel *grpc_lb_policy_grpclb_create_lb_channel( - grpc_exec_ctx *exec_ctx, const char *lb_service_target_addresses, - grpc_client_channel_factory *client_channel_factory, - grpc_channel_args *args) { - grpc_channel *lb_channel = grpc_client_channel_factory_create_channel( +grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( + grpc_exec_ctx* exec_ctx, const char* lb_service_target_addresses, + grpc_client_channel_factory* client_channel_factory, + grpc_channel_args* args) { + grpc_channel* lb_channel = grpc_client_channel_factory_create_channel( exec_ctx, client_channel_factory, lb_service_target_addresses, GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, args); return lb_channel; } -grpc_channel_args *grpc_lb_policy_grpclb_build_lb_channel_args( - grpc_exec_ctx *exec_ctx, grpc_slice_hash_table *targets_info, - grpc_fake_resolver_response_generator *response_generator, - const grpc_channel_args *args) { +grpc_channel_args* grpc_lb_policy_grpclb_build_lb_channel_args( + grpc_exec_ctx* exec_ctx, grpc_slice_hash_table* targets_info, + grpc_fake_resolver_response_generator* response_generator, + const grpc_channel_args* args) { const grpc_arg to_add[] = { grpc_fake_resolver_response_generator_arg(response_generator)}; /* We remove: @@ -62,7 +62,7 @@ grpc_channel_args *grpc_lb_policy_grpclb_build_lb_channel_args( * * - The fake resolver generator, because we are replacing it with the one * from the grpclb policy, used to propagate updates to the LB channel. */ - static const char *keys_to_remove[] = { + static const char* keys_to_remove[] = { GRPC_ARG_LB_POLICY_NAME, GRPC_ARG_LB_ADDRESSES, GRPC_ARG_SERVER_URI, GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR}; return grpc_channel_args_copy_and_add_and_remove( diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h index e8599d1f51..39cbf53428 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h @@ -34,19 +34,19 @@ extern "C" { * from resolving the LB service's name (eg, ipv4:10.0.0.1:1234,10.2.3.4:9876). * \a client_channel_factory will be used for the creation of the LB channel, * alongside the channel args passed in \a args. */ -grpc_channel *grpc_lb_policy_grpclb_create_lb_channel( - grpc_exec_ctx *exec_ctx, const char *lb_service_target_addresses, - grpc_client_channel_factory *client_channel_factory, - grpc_channel_args *args); +grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( + grpc_exec_ctx* exec_ctx, const char* lb_service_target_addresses, + grpc_client_channel_factory* client_channel_factory, + grpc_channel_args* args); -grpc_channel_args *grpc_lb_policy_grpclb_build_lb_channel_args( - grpc_exec_ctx *exec_ctx, grpc_slice_hash_table *targets_info, - grpc_fake_resolver_response_generator *response_generator, - const grpc_channel_args *args); +grpc_channel_args* grpc_lb_policy_grpclb_build_lb_channel_args( + grpc_exec_ctx* exec_ctx, grpc_slice_hash_table* targets_info, + grpc_fake_resolver_response_generator* response_generator, + const grpc_channel_args* args); #ifdef __cplusplus } #endif #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CHANNEL_H \ - */ + */ diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc index 2681b2a079..2dcf29fe0e 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc @@ -28,19 +28,19 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/support/string.h" -grpc_channel *grpc_lb_policy_grpclb_create_lb_channel( - grpc_exec_ctx *exec_ctx, const char *lb_service_target_addresses, - grpc_client_channel_factory *client_channel_factory, - grpc_channel_args *args) { - grpc_channel_args *new_args = args; - grpc_channel_credentials *channel_credentials = +grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( + grpc_exec_ctx* exec_ctx, const char* lb_service_target_addresses, + grpc_client_channel_factory* client_channel_factory, + grpc_channel_args* args) { + grpc_channel_args* new_args = args; + grpc_channel_credentials* channel_credentials = grpc_channel_credentials_find_in_args(args); if (channel_credentials != NULL) { /* Substitute the channel credentials with a version without call * credentials: the load balancer is not necessarily trusted to handle * bearer token credentials */ - static const char *keys_to_remove[] = {GRPC_ARG_CHANNEL_CREDENTIALS}; - grpc_channel_credentials *creds_sans_call_creds = + static const char* keys_to_remove[] = {GRPC_ARG_CHANNEL_CREDENTIALS}; + grpc_channel_credentials* creds_sans_call_creds = grpc_channel_credentials_duplicate_without_call_credentials( channel_credentials); GPR_ASSERT(creds_sans_call_creds != NULL); @@ -52,7 +52,7 @@ grpc_channel *grpc_lb_policy_grpclb_create_lb_channel( GPR_ARRAY_SIZE(args_to_add)); grpc_channel_credentials_unref(exec_ctx, creds_sans_call_creds); } - grpc_channel *lb_channel = grpc_client_channel_factory_create_channel( + grpc_channel* lb_channel = grpc_client_channel_factory_create_channel( exec_ctx, client_channel_factory, lb_service_target_addresses, GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, new_args); if (channel_credentials != NULL) { @@ -61,10 +61,10 @@ grpc_channel *grpc_lb_policy_grpclb_create_lb_channel( return lb_channel; } -grpc_channel_args *grpc_lb_policy_grpclb_build_lb_channel_args( - grpc_exec_ctx *exec_ctx, grpc_slice_hash_table *targets_info, - grpc_fake_resolver_response_generator *response_generator, - const grpc_channel_args *args) { +grpc_channel_args* grpc_lb_policy_grpclb_build_lb_channel_args( + grpc_exec_ctx* exec_ctx, grpc_slice_hash_table* targets_info, + grpc_fake_resolver_response_generator* response_generator, + const grpc_channel_args* args) { const grpc_arg to_add[] = { grpc_lb_targets_info_create_channel_arg(targets_info), grpc_fake_resolver_response_generator_arg(response_generator)}; @@ -89,7 +89,7 @@ grpc_channel_args *grpc_lb_policy_grpclb_build_lb_channel_args( * * - The fake resolver generator, because we are replacing it with the one * from the grpclb policy, used to propagate updates to the LB channel. */ - static const char *keys_to_remove[] = { + static const char* keys_to_remove[] = { GRPC_ARG_LB_POLICY_NAME, GRPC_ARG_LB_ADDRESSES, GRPC_ARG_SERVER_URI, GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR}; /* Add the targets info table to be used for secure naming */ diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h index b38c076f38..ce88cf9ee4 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h @@ -70,4 +70,4 @@ void grpc_grpclb_dropped_call_counts_destroy( #endif #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CLIENT_STATS_H \ - */ + */ diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc index 4d5fb2081c..87d7336b0c 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc @@ -23,9 +23,9 @@ #include <grpc/support/alloc.h> /* invoked once for every Server in ServerList */ -static bool count_serverlist(pb_istream_t *stream, const pb_field_t *field, - void **arg) { - grpc_grpclb_serverlist *sl = (grpc_grpclb_serverlist *)*arg; +static bool count_serverlist(pb_istream_t* stream, const pb_field_t* field, + void** arg) { + grpc_grpclb_serverlist* sl = (grpc_grpclb_serverlist*)*arg; grpc_grpclb_server server; if (!pb_decode(stream, grpc_lb_v1_Server_fields, &server)) { gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream)); @@ -40,16 +40,16 @@ typedef struct decode_serverlist_arg { * which index of the serverlist are we currently decoding */ size_t decoding_idx; /* The decoded serverlist */ - grpc_grpclb_serverlist *serverlist; + grpc_grpclb_serverlist* serverlist; } decode_serverlist_arg; /* invoked once for every Server in ServerList */ -static bool decode_serverlist(pb_istream_t *stream, const pb_field_t *field, - void **arg) { - decode_serverlist_arg *dec_arg = (decode_serverlist_arg *)*arg; +static bool decode_serverlist(pb_istream_t* stream, const pb_field_t* field, + void** arg) { + decode_serverlist_arg* dec_arg = (decode_serverlist_arg*)*arg; GPR_ASSERT(dec_arg->serverlist->num_servers >= dec_arg->decoding_idx); - grpc_grpclb_server *server = - (grpc_grpclb_server *)gpr_zalloc(sizeof(grpc_grpclb_server)); + grpc_grpclb_server* server = + (grpc_grpclb_server*)gpr_zalloc(sizeof(grpc_grpclb_server)); if (!pb_decode(stream, grpc_lb_v1_Server_fields, server)) { gpr_free(server); gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream)); @@ -59,9 +59,9 @@ static bool decode_serverlist(pb_istream_t *stream, const pb_field_t *field, return true; } -grpc_grpclb_request *grpc_grpclb_request_create(const char *lb_service_name) { - grpc_grpclb_request *req = - (grpc_grpclb_request *)gpr_malloc(sizeof(grpc_grpclb_request)); +grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name) { + grpc_grpclb_request* req = + (grpc_grpclb_request*)gpr_malloc(sizeof(grpc_grpclb_request)); req->has_client_stats = false; req->has_initial_request = true; req->initial_request.has_name = true; @@ -71,24 +71,24 @@ grpc_grpclb_request *grpc_grpclb_request_create(const char *lb_service_name) { } static void populate_timestamp(gpr_timespec timestamp, - struct _grpc_lb_v1_Timestamp *timestamp_pb) { + struct _grpc_lb_v1_Timestamp* timestamp_pb) { timestamp_pb->has_seconds = true; timestamp_pb->seconds = timestamp.tv_sec; timestamp_pb->has_nanos = true; timestamp_pb->nanos = timestamp.tv_nsec; } -static bool encode_string(pb_ostream_t *stream, const pb_field_t *field, - void *const *arg) { - char *str = (char *)*arg; +static bool encode_string(pb_ostream_t* stream, const pb_field_t* field, + void* const* arg) { + char* str = (char*)*arg; if (!pb_encode_tag_for_field(stream, field)) return false; - return pb_encode_string(stream, (uint8_t *)str, strlen(str)); + return pb_encode_string(stream, (uint8_t*)str, strlen(str)); } -static bool encode_drops(pb_ostream_t *stream, const pb_field_t *field, - void *const *arg) { - grpc_grpclb_dropped_call_counts *drop_entries = - (grpc_grpclb_dropped_call_counts *)*arg; +static bool encode_drops(pb_ostream_t* stream, const pb_field_t* field, + void* const* arg) { + grpc_grpclb_dropped_call_counts* drop_entries = + (grpc_grpclb_dropped_call_counts*)*arg; if (drop_entries == NULL) return true; for (size_t i = 0; i < drop_entries->num_entries; ++i) { if (!pb_encode_tag_for_field(stream, field)) return false; @@ -105,10 +105,10 @@ static bool encode_drops(pb_ostream_t *stream, const pb_field_t *field, return true; } -grpc_grpclb_request *grpc_grpclb_load_report_request_create_locked( - grpc_grpclb_client_stats *client_stats) { - grpc_grpclb_request *req = - (grpc_grpclb_request *)gpr_zalloc(sizeof(grpc_grpclb_request)); +grpc_grpclb_request* grpc_grpclb_load_report_request_create_locked( + grpc_grpclb_client_stats* client_stats) { + grpc_grpclb_request* req = + (grpc_grpclb_request*)gpr_zalloc(sizeof(grpc_grpclb_request)); req->has_client_stats = true; req->client_stats.has_timestamp = true; populate_timestamp(gpr_now(GPR_CLOCK_REALTIME), &req->client_stats.timestamp); @@ -123,12 +123,12 @@ grpc_grpclb_request *grpc_grpclb_load_report_request_create_locked( &req->client_stats.num_calls_finished, &req->client_stats.num_calls_finished_with_client_failed_to_send, &req->client_stats.num_calls_finished_known_received, - (grpc_grpclb_dropped_call_counts **)&req->client_stats + (grpc_grpclb_dropped_call_counts**)&req->client_stats .calls_finished_with_drop.arg); return req; } -grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request *request) { +grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request) { size_t encoded_length; pb_ostream_t sizestream; pb_ostream_t outputstream; @@ -145,10 +145,10 @@ grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request *request) { return slice; } -void grpc_grpclb_request_destroy(grpc_grpclb_request *request) { +void grpc_grpclb_request_destroy(grpc_grpclb_request* request) { if (request->has_client_stats) { - grpc_grpclb_dropped_call_counts *drop_entries = - (grpc_grpclb_dropped_call_counts *) + grpc_grpclb_dropped_call_counts* drop_entries = + (grpc_grpclb_dropped_call_counts*) request->client_stats.calls_finished_with_drop.arg; grpc_grpclb_dropped_call_counts_destroy(drop_entries); } @@ -156,7 +156,7 @@ void grpc_grpclb_request_destroy(grpc_grpclb_request *request) { } typedef grpc_lb_v1_LoadBalanceResponse grpc_grpclb_response; -grpc_grpclb_initial_response *grpc_grpclb_initial_response_parse( +grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse( grpc_slice encoded_grpc_grpclb_response) { pb_istream_t stream = pb_istream_from_buffer(GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response), @@ -170,8 +170,8 @@ grpc_grpclb_initial_response *grpc_grpclb_initial_response_parse( if (!res.has_initial_response) return NULL; - grpc_grpclb_initial_response *initial_res = - (grpc_grpclb_initial_response *)gpr_malloc( + grpc_grpclb_initial_response* initial_res = + (grpc_grpclb_initial_response*)gpr_malloc( sizeof(grpc_grpclb_initial_response)); memcpy(initial_res, &res.initial_response, sizeof(grpc_grpclb_initial_response)); @@ -179,14 +179,14 @@ grpc_grpclb_initial_response *grpc_grpclb_initial_response_parse( return initial_res; } -grpc_grpclb_serverlist *grpc_grpclb_response_parse_serverlist( +grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( grpc_slice encoded_grpc_grpclb_response) { pb_istream_t stream = pb_istream_from_buffer(GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response), GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response)); pb_istream_t stream_at_start = stream; - grpc_grpclb_serverlist *sl = - (grpc_grpclb_serverlist *)gpr_zalloc(sizeof(grpc_grpclb_serverlist)); + grpc_grpclb_serverlist* sl = + (grpc_grpclb_serverlist*)gpr_zalloc(sizeof(grpc_grpclb_serverlist)); grpc_grpclb_response res; memset(&res, 0, sizeof(grpc_grpclb_response)); // First pass: count number of servers. @@ -200,8 +200,8 @@ grpc_grpclb_serverlist *grpc_grpclb_response_parse_serverlist( } // Second pass: populate servers. if (sl->num_servers > 0) { - sl->servers = (grpc_grpclb_server **)gpr_zalloc( - sizeof(grpc_grpclb_server *) * sl->num_servers); + sl->servers = (grpc_grpclb_server**)gpr_zalloc(sizeof(grpc_grpclb_server*) * + sl->num_servers); decode_serverlist_arg decode_arg; memset(&decode_arg, 0, sizeof(decode_arg)); decode_arg.serverlist = sl; @@ -221,7 +221,7 @@ grpc_grpclb_serverlist *grpc_grpclb_response_parse_serverlist( return sl; } -void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist *serverlist) { +void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist) { if (serverlist == NULL) { return; } @@ -232,25 +232,25 @@ void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist *serverlist) { gpr_free(serverlist); } -grpc_grpclb_serverlist *grpc_grpclb_serverlist_copy( - const grpc_grpclb_serverlist *sl) { - grpc_grpclb_serverlist *copy = - (grpc_grpclb_serverlist *)gpr_zalloc(sizeof(grpc_grpclb_serverlist)); +grpc_grpclb_serverlist* grpc_grpclb_serverlist_copy( + const grpc_grpclb_serverlist* sl) { + grpc_grpclb_serverlist* copy = + (grpc_grpclb_serverlist*)gpr_zalloc(sizeof(grpc_grpclb_serverlist)); copy->num_servers = sl->num_servers; memcpy(©->expiration_interval, &sl->expiration_interval, sizeof(grpc_grpclb_duration)); - copy->servers = (grpc_grpclb_server **)gpr_malloc( - sizeof(grpc_grpclb_server *) * sl->num_servers); + copy->servers = (grpc_grpclb_server**)gpr_malloc(sizeof(grpc_grpclb_server*) * + sl->num_servers); for (size_t i = 0; i < sl->num_servers; i++) { copy->servers[i] = - (grpc_grpclb_server *)gpr_malloc(sizeof(grpc_grpclb_server)); + (grpc_grpclb_server*)gpr_malloc(sizeof(grpc_grpclb_server)); memcpy(copy->servers[i], sl->servers[i], sizeof(grpc_grpclb_server)); } return copy; } -bool grpc_grpclb_serverlist_equals(const grpc_grpclb_serverlist *lhs, - const grpc_grpclb_serverlist *rhs) { +bool grpc_grpclb_serverlist_equals(const grpc_grpclb_serverlist* lhs, + const grpc_grpclb_serverlist* rhs) { if (lhs == NULL || rhs == NULL) { return false; } @@ -269,13 +269,13 @@ bool grpc_grpclb_serverlist_equals(const grpc_grpclb_serverlist *lhs, return true; } -bool grpc_grpclb_server_equals(const grpc_grpclb_server *lhs, - const grpc_grpclb_server *rhs) { +bool grpc_grpclb_server_equals(const grpc_grpclb_server* lhs, + const grpc_grpclb_server* rhs) { return memcmp(lhs, rhs, sizeof(grpc_grpclb_server)) == 0; } -int grpc_grpclb_duration_compare(const grpc_grpclb_duration *lhs, - const grpc_grpclb_duration *rhs) { +int grpc_grpclb_duration_compare(const grpc_grpclb_duration* lhs, + const grpc_grpclb_duration* rhs) { GPR_ASSERT(lhs && rhs); if (lhs->has_seconds && rhs->has_seconds) { if (lhs->seconds < rhs->seconds) return -1; @@ -299,13 +299,13 @@ int grpc_grpclb_duration_compare(const grpc_grpclb_duration *lhs, return 0; } -grpc_millis grpc_grpclb_duration_to_millis(grpc_grpclb_duration *duration_pb) { +grpc_millis grpc_grpclb_duration_to_millis(grpc_grpclb_duration* duration_pb) { return (grpc_millis)( (duration_pb->has_seconds ? duration_pb->seconds : 0) * GPR_MS_PER_SEC + (duration_pb->has_nanos ? duration_pb->nanos : 0) / GPR_NS_PER_MS); } void grpc_grpclb_initial_response_destroy( - grpc_grpclb_initial_response *response) { + grpc_grpclb_initial_response* response) { gpr_free(response); } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h index 56b9c096d0..138012c63a 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h @@ -37,59 +37,59 @@ typedef grpc_lb_v1_InitialLoadBalanceResponse grpc_grpclb_initial_response; typedef grpc_lb_v1_Server grpc_grpclb_server; typedef grpc_lb_v1_Duration grpc_grpclb_duration; typedef struct { - grpc_grpclb_server **servers; + grpc_grpclb_server** servers; size_t num_servers; grpc_grpclb_duration expiration_interval; } grpc_grpclb_serverlist; /** Create a request for a gRPC LB service under \a lb_service_name */ -grpc_grpclb_request *grpc_grpclb_request_create(const char *lb_service_name); -grpc_grpclb_request *grpc_grpclb_load_report_request_create_locked( - grpc_grpclb_client_stats *client_stats); +grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name); +grpc_grpclb_request* grpc_grpclb_load_report_request_create_locked( + grpc_grpclb_client_stats* client_stats); /** Protocol Buffers v3-encode \a request */ -grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request *request); +grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request); /** Destroy \a request */ -void grpc_grpclb_request_destroy(grpc_grpclb_request *request); +void grpc_grpclb_request_destroy(grpc_grpclb_request* request); /** Parse (ie, decode) the bytes in \a encoded_grpc_grpclb_response as a \a * grpc_grpclb_initial_response */ -grpc_grpclb_initial_response *grpc_grpclb_initial_response_parse( +grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse( grpc_slice encoded_grpc_grpclb_response); /** Parse the list of servers from an encoded \a grpc_grpclb_response */ -grpc_grpclb_serverlist *grpc_grpclb_response_parse_serverlist( +grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( grpc_slice encoded_grpc_grpclb_response); /** Return a copy of \a sl. The caller is responsible for calling \a * grpc_grpclb_destroy_serverlist on the returned copy. */ -grpc_grpclb_serverlist *grpc_grpclb_serverlist_copy( - const grpc_grpclb_serverlist *sl); +grpc_grpclb_serverlist* grpc_grpclb_serverlist_copy( + const grpc_grpclb_serverlist* sl); -bool grpc_grpclb_serverlist_equals(const grpc_grpclb_serverlist *lhs, - const grpc_grpclb_serverlist *rhs); +bool grpc_grpclb_serverlist_equals(const grpc_grpclb_serverlist* lhs, + const grpc_grpclb_serverlist* rhs); -bool grpc_grpclb_server_equals(const grpc_grpclb_server *lhs, - const grpc_grpclb_server *rhs); +bool grpc_grpclb_server_equals(const grpc_grpclb_server* lhs, + const grpc_grpclb_server* rhs); /** Destroy \a serverlist */ -void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist *serverlist); +void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist); /** Compare \a lhs against \a rhs and return 0 if \a lhs and \a rhs are equal, * < 0 if \a lhs represents a duration shorter than \a rhs and > 0 otherwise */ -int grpc_grpclb_duration_compare(const grpc_grpclb_duration *lhs, - const grpc_grpclb_duration *rhs); +int grpc_grpclb_duration_compare(const grpc_grpclb_duration* lhs, + const grpc_grpclb_duration* rhs); -grpc_millis grpc_grpclb_duration_to_millis(grpc_grpclb_duration *duration_pb); +grpc_millis grpc_grpclb_duration_to_millis(grpc_grpclb_duration* duration_pb); /** Destroy \a initial_response */ void grpc_grpclb_initial_response_destroy( - grpc_grpclb_initial_response *response); + grpc_grpclb_initial_response* response); #ifdef __cplusplus } #endif #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_LOAD_BALANCER_API_H \ - */ + */ diff --git a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc index f0c66c68e1..125a4186aa 100644 --- a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +++ b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc @@ -33,33 +33,33 @@ grpc_tracer_flag grpc_lb_pick_first_trace = GRPC_TRACER_INITIALIZER(false, "pick_first"); typedef struct pending_pick { - struct pending_pick *next; + struct pending_pick* next; uint32_t initial_metadata_flags; - grpc_connected_subchannel **target; - grpc_closure *on_complete; + grpc_connected_subchannel** target; + grpc_closure* on_complete; } pending_pick; typedef struct { /** base policy: must be first */ grpc_lb_policy base; /** all our subchannels */ - grpc_lb_subchannel_list *subchannel_list; + grpc_lb_subchannel_list* subchannel_list; /** latest pending subchannel list */ - grpc_lb_subchannel_list *latest_pending_subchannel_list; + grpc_lb_subchannel_list* latest_pending_subchannel_list; /** selected subchannel in \a subchannel_list */ - grpc_lb_subchannel_data *selected; + grpc_lb_subchannel_data* selected; /** have we started picking? */ bool started_picking; /** are we shut down? */ bool shutdown; /** list of picks that are waiting on connectivity */ - pending_pick *pending_picks; + pending_pick* pending_picks; /** our connectivity state tracker */ grpc_connectivity_state_tracker state_tracker; } pick_first_lb_policy; -static void pf_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { - pick_first_lb_policy *p = (pick_first_lb_policy *)pol; +static void pf_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { + pick_first_lb_policy* p = (pick_first_lb_policy*)pol; GPR_ASSERT(p->subchannel_list == NULL); GPR_ASSERT(p->latest_pending_subchannel_list == NULL); GPR_ASSERT(p->pending_picks == NULL); @@ -67,17 +67,17 @@ static void pf_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { gpr_free(p); grpc_subchannel_index_unref(); if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { - gpr_log(GPR_DEBUG, "Pick First %p destroyed.", (void *)p); + gpr_log(GPR_DEBUG, "Pick First %p destroyed.", (void*)p); } } -static void shutdown_locked(grpc_exec_ctx *exec_ctx, pick_first_lb_policy *p, - grpc_error *error) { +static void shutdown_locked(grpc_exec_ctx* exec_ctx, pick_first_lb_policy* p, + grpc_error* error) { if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { gpr_log(GPR_DEBUG, "Pick First %p Shutting down", p); } p->shutdown = true; - pending_pick *pp; + pending_pick* pp; while ((pp = p->pending_picks) != NULL) { p->pending_picks = pp->next; *pp->target = NULL; @@ -100,19 +100,19 @@ static void shutdown_locked(grpc_exec_ctx *exec_ctx, pick_first_lb_policy *p, GRPC_ERROR_UNREF(error); } -static void pf_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { - shutdown_locked(exec_ctx, (pick_first_lb_policy *)pol, +static void pf_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { + shutdown_locked(exec_ctx, (pick_first_lb_policy*)pol, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel shutdown")); } -static void pf_cancel_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, - grpc_connected_subchannel **target, - grpc_error *error) { - pick_first_lb_policy *p = (pick_first_lb_policy *)pol; - pending_pick *pp = p->pending_picks; +static void pf_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + grpc_connected_subchannel** target, + grpc_error* error) { + pick_first_lb_policy* p = (pick_first_lb_policy*)pol; + pending_pick* pp = p->pending_picks; p->pending_picks = NULL; while (pp != NULL) { - pending_pick *next = pp->next; + pending_pick* next = pp->next; if (pp->target == target) { *target = NULL; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, @@ -128,15 +128,15 @@ static void pf_cancel_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, GRPC_ERROR_UNREF(error); } -static void pf_cancel_picks_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, +static void pf_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, - grpc_error *error) { - pick_first_lb_policy *p = (pick_first_lb_policy *)pol; - pending_pick *pp = p->pending_picks; + grpc_error* error) { + pick_first_lb_policy* p = (pick_first_lb_policy*)pol; + pending_pick* pp = p->pending_picks; p->pending_picks = NULL; while (pp != NULL) { - pending_pick *next = pp->next; + pending_pick* next = pp->next; if ((pp->initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, @@ -152,8 +152,8 @@ static void pf_cancel_picks_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, GRPC_ERROR_UNREF(error); } -static void start_picking_locked(grpc_exec_ctx *exec_ctx, - pick_first_lb_policy *p) { +static void start_picking_locked(grpc_exec_ctx* exec_ctx, + pick_first_lb_policy* p) { p->started_picking = true; if (p->subchannel_list != NULL && p->subchannel_list->num_subchannels > 0) { p->subchannel_list->checking_subchannel = 0; @@ -164,19 +164,19 @@ static void start_picking_locked(grpc_exec_ctx *exec_ctx, } } -static void pf_exit_idle_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { - pick_first_lb_policy *p = (pick_first_lb_policy *)pol; +static void pf_exit_idle_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { + pick_first_lb_policy* p = (pick_first_lb_policy*)pol; if (!p->started_picking) { start_picking_locked(exec_ctx, p); } } -static int pf_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, - const grpc_lb_policy_pick_args *pick_args, - grpc_connected_subchannel **target, - grpc_call_context_element *context, void **user_data, - grpc_closure *on_complete) { - pick_first_lb_policy *p = (pick_first_lb_policy *)pol; +static int pf_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + const grpc_lb_policy_pick_args* pick_args, + grpc_connected_subchannel** target, + grpc_call_context_element* context, void** user_data, + grpc_closure* on_complete) { + pick_first_lb_policy* p = (pick_first_lb_policy*)pol; // If we have a selected subchannel already, return synchronously. if (p->selected != NULL) { *target = GRPC_CONNECTED_SUBCHANNEL_REF(p->selected->connected_subchannel, @@ -187,7 +187,7 @@ static int pf_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, if (!p->started_picking) { start_picking_locked(exec_ctx, p); } - pending_pick *pp = (pending_pick *)gpr_malloc(sizeof(*pp)); + pending_pick* pp = (pending_pick*)gpr_malloc(sizeof(*pp)); pp->next = p->pending_picks; pp->target = target; pp->initial_metadata_flags = pick_args->initial_metadata_flags; @@ -196,10 +196,10 @@ static int pf_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, return 0; } -static void destroy_unselected_subchannels_locked(grpc_exec_ctx *exec_ctx, - pick_first_lb_policy *p) { +static void destroy_unselected_subchannels_locked(grpc_exec_ctx* exec_ctx, + pick_first_lb_policy* p) { for (size_t i = 0; i < p->subchannel_list->num_subchannels; ++i) { - grpc_lb_subchannel_data *sd = &p->subchannel_list->subchannels[i]; + grpc_lb_subchannel_data* sd = &p->subchannel_list->subchannels[i]; if (p->selected != sd) { grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "selected_different_subchannel"); @@ -208,23 +208,23 @@ static void destroy_unselected_subchannels_locked(grpc_exec_ctx *exec_ctx, } static grpc_connectivity_state pf_check_connectivity_locked( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, grpc_error **error) { - pick_first_lb_policy *p = (pick_first_lb_policy *)pol; + grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error** error) { + pick_first_lb_policy* p = (pick_first_lb_policy*)pol; return grpc_connectivity_state_get(&p->state_tracker, error); } -static void pf_notify_on_state_change_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *pol, - grpc_connectivity_state *current, - grpc_closure *notify) { - pick_first_lb_policy *p = (pick_first_lb_policy *)pol; +static void pf_notify_on_state_change_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* pol, + grpc_connectivity_state* current, + grpc_closure* notify) { + pick_first_lb_policy* p = (pick_first_lb_policy*)pol; grpc_connectivity_state_notify_on_state_change(exec_ctx, &p->state_tracker, current, notify); } -static void pf_ping_one_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, - grpc_closure *closure) { - pick_first_lb_policy *p = (pick_first_lb_policy *)pol; +static void pf_ping_one_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + grpc_closure* closure) { + pick_first_lb_policy* p = (pick_first_lb_policy*)pol; if (p->selected) { grpc_connected_subchannel_ping(exec_ctx, p->selected->connected_subchannel, closure); @@ -234,13 +234,13 @@ static void pf_ping_one_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, } } -static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error); +static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); -static void pf_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - const grpc_lb_policy_args *args) { - pick_first_lb_policy *p = (pick_first_lb_policy *)policy; - const grpc_arg *arg = +static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + const grpc_lb_policy_args* args) { + pick_first_lb_policy* p = (pick_first_lb_policy*)policy; + const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); if (arg == NULL || arg->type != GRPC_ARG_POINTER) { if (p->subchannel_list == NULL) { @@ -254,17 +254,17 @@ static void pf_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, gpr_log(GPR_ERROR, "No valid LB addresses channel arg for Pick First %p update, " "ignoring.", - (void *)p); + (void*)p); } return; } - const grpc_lb_addresses *addresses = - (const grpc_lb_addresses *)arg->value.pointer.p; + const grpc_lb_addresses* addresses = + (const grpc_lb_addresses*)arg->value.pointer.p; if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { gpr_log(GPR_INFO, "Pick First %p received update with %lu addresses", - (void *)p, (unsigned long)addresses->num_addresses); + (void*)p, (unsigned long)addresses->num_addresses); } - grpc_lb_subchannel_list *subchannel_list = grpc_lb_subchannel_list_create( + grpc_lb_subchannel_list* subchannel_list = grpc_lb_subchannel_list_create( exec_ctx, &p->base, &grpc_lb_pick_first_trace, addresses, args, pf_connectivity_changed_locked); if (subchannel_list->num_subchannels == 0) { @@ -294,7 +294,7 @@ static void pf_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, // We do have a selected subchannel. // Check if it's present in the new list. If so, we're done. for (size_t i = 0; i < subchannel_list->num_subchannels; ++i) { - grpc_lb_subchannel_data *sd = &subchannel_list->subchannels[i]; + grpc_lb_subchannel_data* sd = &subchannel_list->subchannels[i]; if (sd->subchannel == p->selected->subchannel) { // The currently selected subchannel is in the update: we are done. if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { @@ -339,8 +339,8 @@ static void pf_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, gpr_log(GPR_DEBUG, "Pick First %p Shutting down latest pending subchannel list " "%p, about to be replaced by newer latest %p", - (void *)p, (void *)p->latest_pending_subchannel_list, - (void *)subchannel_list); + (void*)p, (void*)p->latest_pending_subchannel_list, + (void*)subchannel_list); } grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->latest_pending_subchannel_list, @@ -358,19 +358,19 @@ static void pf_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, } } -static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_lb_subchannel_data *sd = (grpc_lb_subchannel_data *)arg; - pick_first_lb_policy *p = (pick_first_lb_policy *)sd->subchannel_list->policy; +static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_lb_subchannel_data* sd = (grpc_lb_subchannel_data*)arg; + pick_first_lb_policy* p = (pick_first_lb_policy*)sd->subchannel_list->policy; if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { gpr_log(GPR_DEBUG, "Pick First %p connectivity changed for subchannel %p (%" PRIuPTR " of %" PRIuPTR "), subchannel_list %p: state=%s p->shutdown=%d " "sd->subchannel_list->shutting_down=%d error=%s", - (void *)p, (void *)sd->subchannel, + (void*)p, (void*)sd->subchannel, sd->subchannel_list->checking_subchannel, - sd->subchannel_list->num_subchannels, (void *)sd->subchannel_list, + sd->subchannel_list->num_subchannels, (void*)sd->subchannel_list, grpc_connectivity_state_name(sd->pending_connectivity_state_unsafe), p->shutdown, sd->subchannel_list->shutting_down, grpc_error_string(error)); @@ -465,13 +465,13 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, "connected"); p->selected = sd; if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { - gpr_log(GPR_INFO, "Pick First %p selected subchannel %p", (void *)p, - (void *)sd->subchannel); + gpr_log(GPR_INFO, "Pick First %p selected subchannel %p", (void*)p, + (void*)sd->subchannel); } // Drop all other subchannels, since we are now connected. destroy_unselected_subchannels_locked(exec_ctx, p); // Update any calls that were waiting for a pick. - pending_pick *pp; + pending_pick* pp; while ((pp = p->pending_picks)) { p->pending_picks = pp->next; *pp->target = GRPC_CONNECTED_SUBCHANNEL_REF( @@ -479,7 +479,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { gpr_log(GPR_INFO, "Servicing pending pick with selected subchannel %p", - (void *)p->selected); + (void*)p->selected); } GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_NONE); gpr_free(pp); @@ -530,7 +530,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "pf_candidate_shutdown"); // Advance to next subchannel and check its state. - grpc_lb_subchannel_data *original_sd = sd; + grpc_lb_subchannel_data* original_sd = sd; do { sd->subchannel_list->checking_subchannel = (sd->subchannel_list->checking_subchannel + 1) % @@ -578,17 +578,17 @@ static const grpc_lb_policy_vtable pick_first_lb_policy_vtable = { pf_notify_on_state_change_locked, pf_update_locked}; -static void pick_first_factory_ref(grpc_lb_policy_factory *factory) {} +static void pick_first_factory_ref(grpc_lb_policy_factory* factory) {} -static void pick_first_factory_unref(grpc_lb_policy_factory *factory) {} +static void pick_first_factory_unref(grpc_lb_policy_factory* factory) {} -static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, - grpc_lb_policy_factory *factory, - grpc_lb_policy_args *args) { +static grpc_lb_policy* create_pick_first(grpc_exec_ctx* exec_ctx, + grpc_lb_policy_factory* factory, + grpc_lb_policy_args* args) { GPR_ASSERT(args->client_channel_factory != NULL); - pick_first_lb_policy *p = (pick_first_lb_policy *)gpr_zalloc(sizeof(*p)); + pick_first_lb_policy* p = (pick_first_lb_policy*)gpr_zalloc(sizeof(*p)); if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { - gpr_log(GPR_DEBUG, "Pick First %p created.", (void *)p); + gpr_log(GPR_DEBUG, "Pick First %p created.", (void*)p); } pf_update_locked(exec_ctx, &p->base, args); grpc_lb_policy_init(&p->base, &pick_first_lb_policy_vtable, args->combiner); @@ -603,7 +603,7 @@ static const grpc_lb_policy_factory_vtable pick_first_factory_vtable = { static grpc_lb_policy_factory pick_first_lb_policy_factory = { &pick_first_factory_vtable}; -static grpc_lb_policy_factory *pick_first_lb_factory_create() { +static grpc_lb_policy_factory* pick_first_lb_factory_create() { return &pick_first_lb_policy_factory; } diff --git a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc index fae40e378b..df235922c8 100644 --- a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +++ b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc @@ -46,12 +46,12 @@ grpc_tracer_flag grpc_lb_round_robin_trace = * * Once a pick is available, \a target is updated and \a on_complete called. */ typedef struct pending_pick { - struct pending_pick *next; + struct pending_pick* next; /* output argument where to store the pick()ed user_data. It'll be NULL if no * such data is present or there's an error (the definite test for errors is * \a target being NULL). */ - void **user_data; + void** user_data; /* bitmask passed to pick() and used for selective cancelling. See * grpc_lb_policy_cancel_picks() */ @@ -59,24 +59,24 @@ typedef struct pending_pick { /* output argument where to store the pick()ed connected subchannel, or NULL * upon error. */ - grpc_connected_subchannel **target; + grpc_connected_subchannel** target; /* to be invoked once the pick() has completed (regardless of success) */ - grpc_closure *on_complete; + grpc_closure* on_complete; } pending_pick; typedef struct round_robin_lb_policy { /** base policy: must be first */ grpc_lb_policy base; - grpc_lb_subchannel_list *subchannel_list; + grpc_lb_subchannel_list* subchannel_list; /** have we started picking? */ bool started_picking; /** are we shutting down? */ bool shutdown; /** List of picks that are waiting on connectivity */ - pending_pick *pending_picks; + pending_pick* pending_picks; /** our connectivity state tracker */ grpc_connectivity_state_tracker state_tracker; @@ -89,7 +89,7 @@ typedef struct round_robin_lb_policy { * lists if they equal \a latest_pending_subchannel_list. In other words, * racing callbacks that reference outdated subchannel lists won't perform any * update. */ - grpc_lb_subchannel_list *latest_pending_subchannel_list; + grpc_lb_subchannel_list* latest_pending_subchannel_list; } round_robin_lb_policy; /** Returns the index into p->subchannel_list->subchannels of the next @@ -99,13 +99,13 @@ typedef struct round_robin_lb_policy { * Note that this function does *not* update p->last_ready_subchannel_index. * The caller must do that if it returns a pick. */ static size_t get_next_ready_subchannel_index_locked( - const round_robin_lb_policy *p) { + const round_robin_lb_policy* p) { GPR_ASSERT(p->subchannel_list != NULL); if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { gpr_log(GPR_INFO, "[RR %p] getting next ready subchannel (out of %lu), " "last_ready_subchannel_index=%lu", - (void *)p, (unsigned long)p->subchannel_list->num_subchannels, + (void*)p, (unsigned long)p->subchannel_list->num_subchannels, (unsigned long)p->last_ready_subchannel_index); } for (size_t i = 0; i < p->subchannel_list->num_subchannels; ++i) { @@ -116,8 +116,8 @@ static size_t get_next_ready_subchannel_index_locked( GPR_DEBUG, "[RR %p] checking subchannel %p, subchannel_list %p, index %lu: " "state=%s", - (void *)p, (void *)p->subchannel_list->subchannels[index].subchannel, - (void *)p->subchannel_list, (unsigned long)index, + (void*)p, (void*)p->subchannel_list->subchannels[index].subchannel, + (void*)p->subchannel_list, (unsigned long)index, grpc_connectivity_state_name( p->subchannel_list->subchannels[index].curr_connectivity_state)); } @@ -127,40 +127,39 @@ static size_t get_next_ready_subchannel_index_locked( gpr_log(GPR_DEBUG, "[RR %p] found next ready subchannel (%p) at index %lu of " "subchannel_list %p", - (void *)p, - (void *)p->subchannel_list->subchannels[index].subchannel, - (unsigned long)index, (void *)p->subchannel_list); + (void*)p, + (void*)p->subchannel_list->subchannels[index].subchannel, + (unsigned long)index, (void*)p->subchannel_list); } return index; } } if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { - gpr_log(GPR_DEBUG, "[RR %p] no subchannels in ready state", (void *)p); + gpr_log(GPR_DEBUG, "[RR %p] no subchannels in ready state", (void*)p); } return p->subchannel_list->num_subchannels; } // Sets p->last_ready_subchannel_index to last_ready_index. -static void update_last_ready_subchannel_index_locked(round_robin_lb_policy *p, +static void update_last_ready_subchannel_index_locked(round_robin_lb_policy* p, size_t last_ready_index) { GPR_ASSERT(last_ready_index < p->subchannel_list->num_subchannels); p->last_ready_subchannel_index = last_ready_index; if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { - gpr_log( - GPR_DEBUG, - "[RR %p] setting last_ready_subchannel_index=%lu (SC %p, CSC %p)", - (void *)p, (unsigned long)last_ready_index, - (void *)p->subchannel_list->subchannels[last_ready_index].subchannel, - (void *)p->subchannel_list->subchannels[last_ready_index] - .connected_subchannel); + gpr_log(GPR_DEBUG, + "[RR %p] setting last_ready_subchannel_index=%lu (SC %p, CSC %p)", + (void*)p, (unsigned long)last_ready_index, + (void*)p->subchannel_list->subchannels[last_ready_index].subchannel, + (void*)p->subchannel_list->subchannels[last_ready_index] + .connected_subchannel); } } -static void rr_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { - round_robin_lb_policy *p = (round_robin_lb_policy *)pol; +static void rr_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { + round_robin_lb_policy* p = (round_robin_lb_policy*)pol; if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { gpr_log(GPR_DEBUG, "[RR %p] Destroying Round Robin policy at %p", - (void *)pol, (void *)pol); + (void*)pol, (void*)pol); } GPR_ASSERT(p->subchannel_list == NULL); GPR_ASSERT(p->latest_pending_subchannel_list == NULL); @@ -169,13 +168,13 @@ static void rr_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { gpr_free(p); } -static void shutdown_locked(grpc_exec_ctx *exec_ctx, round_robin_lb_policy *p, - grpc_error *error) { +static void shutdown_locked(grpc_exec_ctx* exec_ctx, round_robin_lb_policy* p, + grpc_error* error) { if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { gpr_log(GPR_DEBUG, "[RR %p] Shutting down", p); } p->shutdown = true; - pending_pick *pp; + pending_pick* pp; while ((pp = p->pending_picks) != NULL) { p->pending_picks = pp->next; *pp->target = NULL; @@ -199,20 +198,20 @@ static void shutdown_locked(grpc_exec_ctx *exec_ctx, round_robin_lb_policy *p, GRPC_ERROR_UNREF(error); } -static void rr_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { - round_robin_lb_policy *p = (round_robin_lb_policy *)pol; +static void rr_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { + round_robin_lb_policy* p = (round_robin_lb_policy*)pol; shutdown_locked(exec_ctx, p, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Shutdown")); } -static void rr_cancel_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, - grpc_connected_subchannel **target, - grpc_error *error) { - round_robin_lb_policy *p = (round_robin_lb_policy *)pol; - pending_pick *pp = p->pending_picks; +static void rr_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + grpc_connected_subchannel** target, + grpc_error* error) { + round_robin_lb_policy* p = (round_robin_lb_policy*)pol; + pending_pick* pp = p->pending_picks; p->pending_picks = NULL; while (pp != NULL) { - pending_pick *next = pp->next; + pending_pick* next = pp->next; if (pp->target == target) { *target = NULL; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, @@ -228,15 +227,15 @@ static void rr_cancel_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, GRPC_ERROR_UNREF(error); } -static void rr_cancel_picks_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, +static void rr_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, uint32_t initial_metadata_flags_mask, uint32_t initial_metadata_flags_eq, - grpc_error *error) { - round_robin_lb_policy *p = (round_robin_lb_policy *)pol; - pending_pick *pp = p->pending_picks; + grpc_error* error) { + round_robin_lb_policy* p = (round_robin_lb_policy*)pol; + pending_pick* pp = p->pending_picks; p->pending_picks = NULL; while (pp != NULL) { - pending_pick *next = pp->next; + pending_pick* next = pp->next; if ((pp->initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { *pp->target = NULL; @@ -253,8 +252,8 @@ static void rr_cancel_picks_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, GRPC_ERROR_UNREF(error); } -static void start_picking_locked(grpc_exec_ctx *exec_ctx, - round_robin_lb_policy *p) { +static void start_picking_locked(grpc_exec_ctx* exec_ctx, + round_robin_lb_policy* p) { p->started_picking = true; for (size_t i = 0; i < p->subchannel_list->num_subchannels; i++) { grpc_lb_subchannel_list_ref_for_connectivity_watch(p->subchannel_list, @@ -264,21 +263,21 @@ static void start_picking_locked(grpc_exec_ctx *exec_ctx, } } -static void rr_exit_idle_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { - round_robin_lb_policy *p = (round_robin_lb_policy *)pol; +static void rr_exit_idle_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { + round_robin_lb_policy* p = (round_robin_lb_policy*)pol; if (!p->started_picking) { start_picking_locked(exec_ctx, p); } } -static int rr_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, - const grpc_lb_policy_pick_args *pick_args, - grpc_connected_subchannel **target, - grpc_call_context_element *context, void **user_data, - grpc_closure *on_complete) { - round_robin_lb_policy *p = (round_robin_lb_policy *)pol; +static int rr_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + const grpc_lb_policy_pick_args* pick_args, + grpc_connected_subchannel** target, + grpc_call_context_element* context, void** user_data, + grpc_closure* on_complete) { + round_robin_lb_policy* p = (round_robin_lb_policy*)pol; if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { - gpr_log(GPR_INFO, "[RR %p] Trying to pick (shutdown: %d)", (void *)pol, + gpr_log(GPR_INFO, "[RR %p] Trying to pick (shutdown: %d)", (void*)pol, p->shutdown); } GPR_ASSERT(!p->shutdown); @@ -286,7 +285,7 @@ static int rr_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, const size_t next_ready_index = get_next_ready_subchannel_index_locked(p); if (next_ready_index < p->subchannel_list->num_subchannels) { /* readily available, report right away */ - grpc_lb_subchannel_data *sd = + grpc_lb_subchannel_data* sd = &p->subchannel_list->subchannels[next_ready_index]; *target = GRPC_CONNECTED_SUBCHANNEL_REF(sd->connected_subchannel, "rr_picked"); @@ -298,8 +297,8 @@ static int rr_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, GPR_DEBUG, "[RR %p] Picked target <-- Subchannel %p (connected %p) (sl %p, " "index %lu)", - (void *)p, (void *)sd->subchannel, (void *)*target, - (void *)sd->subchannel_list, (unsigned long)next_ready_index); + (void*)p, (void*)sd->subchannel, (void*)*target, + (void*)sd->subchannel_list, (unsigned long)next_ready_index); } /* only advance the last picked pointer if the selection was used */ update_last_ready_subchannel_index_locked(p, next_ready_index); @@ -310,7 +309,7 @@ static int rr_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, if (!p->started_picking) { start_picking_locked(exec_ctx, p); } - pending_pick *pp = (pending_pick *)gpr_malloc(sizeof(*pp)); + pending_pick* pp = (pending_pick*)gpr_malloc(sizeof(*pp)); pp->next = p->pending_picks; pp->target = target; pp->on_complete = on_complete; @@ -320,8 +319,8 @@ static int rr_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, return 0; } -static void update_state_counters_locked(grpc_lb_subchannel_data *sd) { - grpc_lb_subchannel_list *subchannel_list = sd->subchannel_list; +static void update_state_counters_locked(grpc_lb_subchannel_data* sd) { + grpc_lb_subchannel_list* subchannel_list = sd->subchannel_list; if (sd->prev_connectivity_state == GRPC_CHANNEL_READY) { GPR_ASSERT(subchannel_list->num_ready > 0); --subchannel_list->num_ready; @@ -353,7 +352,7 @@ static void update_state_counters_locked(grpc_lb_subchannel_data *sd) { * used upon policy transition to TRANSIENT_FAILURE or SHUTDOWN. Returns the * connectivity status set. */ static grpc_connectivity_state update_lb_connectivity_status_locked( - grpc_exec_ctx *exec_ctx, grpc_lb_subchannel_data *sd, grpc_error *error) { + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd, grpc_error* error) { /* In priority order. The first rule to match terminates the search (ie, if we * are on rule n, all previous rules were unfulfilled). * @@ -375,8 +374,8 @@ static grpc_connectivity_state update_lb_connectivity_status_locked( * CHECK: p->num_idle == p->subchannel_list->num_subchannels. */ grpc_connectivity_state new_state = sd->curr_connectivity_state; - grpc_lb_subchannel_list *subchannel_list = sd->subchannel_list; - round_robin_lb_policy *p = (round_robin_lb_policy *)subchannel_list->policy; + grpc_lb_subchannel_list* subchannel_list = sd->subchannel_list; + round_robin_lb_policy* p = (round_robin_lb_policy*)subchannel_list->policy; if (subchannel_list->num_ready > 0) { /* 1) READY */ grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_READY, GRPC_ERROR_NONE, "rr_ready"); @@ -397,7 +396,7 @@ static grpc_connectivity_state update_lb_connectivity_status_locked( if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { gpr_log(GPR_INFO, "[RR %p] Shutting down: all subchannels have gone into shutdown", - (void *)p); + (void*)p); } } else if (subchannel_list->num_transient_failures == p->subchannel_list->num_subchannels) { /* 4) TRANSIENT_FAILURE */ @@ -415,18 +414,18 @@ static grpc_connectivity_state update_lb_connectivity_status_locked( return new_state; } -static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_lb_subchannel_data *sd = (grpc_lb_subchannel_data *)arg; - round_robin_lb_policy *p = - (round_robin_lb_policy *)sd->subchannel_list->policy; +static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_lb_subchannel_data* sd = (grpc_lb_subchannel_data*)arg; + round_robin_lb_policy* p = + (round_robin_lb_policy*)sd->subchannel_list->policy; if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { gpr_log( GPR_DEBUG, "[RR %p] connectivity changed for subchannel %p, subchannel_list %p: " "prev_state=%s new_state=%s p->shutdown=%d " "sd->subchannel_list->shutting_down=%d error=%s", - (void *)p, (void *)sd->subchannel, (void *)sd->subchannel_list, + (void*)p, (void*)sd->subchannel, (void*)sd->subchannel_list, grpc_connectivity_state_name(sd->prev_connectivity_state), grpc_connectivity_state_name(sd->pending_connectivity_state_unsafe), p->shutdown, sd->subchannel_list->shutting_down, @@ -493,8 +492,8 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, gpr_log(GPR_DEBUG, "[RR %p] phasing out subchannel list %p (size %lu) in favor " "of %p (size %lu)", - (void *)p, (void *)p->subchannel_list, num_subchannels, - (void *)sd->subchannel_list, num_subchannels); + (void*)p, (void*)p->subchannel_list, num_subchannels, + (void*)sd->subchannel_list, num_subchannels); } if (p->subchannel_list != NULL) { // dispose of the current subchannel_list @@ -509,14 +508,14 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, * p->pending_picks. This preemtively replicates rr_pick()'s actions. */ const size_t next_ready_index = get_next_ready_subchannel_index_locked(p); GPR_ASSERT(next_ready_index < p->subchannel_list->num_subchannels); - grpc_lb_subchannel_data *selected = + grpc_lb_subchannel_data* selected = &p->subchannel_list->subchannels[next_ready_index]; if (p->pending_picks != NULL) { // if the selected subchannel is going to be used for the pending // picks, update the last picked pointer update_last_ready_subchannel_index_locked(p, next_ready_index); } - pending_pick *pp; + pending_pick* pp; while ((pp = p->pending_picks)) { p->pending_picks = pp->next; *pp->target = GRPC_CONNECTED_SUBCHANNEL_REF( @@ -528,8 +527,8 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, gpr_log(GPR_DEBUG, "[RR %p] Fulfilling pending pick. Target <-- subchannel %p " "(subchannel_list %p, index %lu)", - (void *)p, (void *)selected->subchannel, - (void *)p->subchannel_list, (unsigned long)next_ready_index); + (void*)p, (void*)selected->subchannel, + (void*)p->subchannel_list, (unsigned long)next_ready_index); } GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_NONE); gpr_free(pp); @@ -541,41 +540,42 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, } static grpc_connectivity_state rr_check_connectivity_locked( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, grpc_error **error) { - round_robin_lb_policy *p = (round_robin_lb_policy *)pol; + grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error** error) { + round_robin_lb_policy* p = (round_robin_lb_policy*)pol; return grpc_connectivity_state_get(&p->state_tracker, error); } -static void rr_notify_on_state_change_locked(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *pol, - grpc_connectivity_state *current, - grpc_closure *notify) { - round_robin_lb_policy *p = (round_robin_lb_policy *)pol; +static void rr_notify_on_state_change_locked(grpc_exec_ctx* exec_ctx, + grpc_lb_policy* pol, + grpc_connectivity_state* current, + grpc_closure* notify) { + round_robin_lb_policy* p = (round_robin_lb_policy*)pol; grpc_connectivity_state_notify_on_state_change(exec_ctx, &p->state_tracker, current, notify); } -static void rr_ping_one_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, - grpc_closure *closure) { - round_robin_lb_policy *p = (round_robin_lb_policy *)pol; +static void rr_ping_one_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, + grpc_closure* closure) { + round_robin_lb_policy* p = (round_robin_lb_policy*)pol; const size_t next_ready_index = get_next_ready_subchannel_index_locked(p); if (next_ready_index < p->subchannel_list->num_subchannels) { - grpc_lb_subchannel_data *selected = + grpc_lb_subchannel_data* selected = &p->subchannel_list->subchannels[next_ready_index]; - grpc_connected_subchannel *target = GRPC_CONNECTED_SUBCHANNEL_REF( + grpc_connected_subchannel* target = GRPC_CONNECTED_SUBCHANNEL_REF( selected->connected_subchannel, "rr_ping"); grpc_connected_subchannel_ping(exec_ctx, target, closure); GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, target, "rr_ping"); } else { - GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Round Robin not connected")); + GRPC_CLOSURE_SCHED( + exec_ctx, closure, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Round Robin not connected")); } } -static void rr_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - const grpc_lb_policy_args *args) { - round_robin_lb_policy *p = (round_robin_lb_policy *)policy; - const grpc_arg *arg = +static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, + const grpc_lb_policy_args* args) { + round_robin_lb_policy* p = (round_robin_lb_policy*)policy; + const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); if (arg == NULL || arg->type != GRPC_ARG_POINTER) { gpr_log(GPR_ERROR, "[RR %p] update provided no addresses; ignoring", p); @@ -589,12 +589,12 @@ static void rr_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, } return; } - grpc_lb_addresses *addresses = (grpc_lb_addresses *)arg->value.pointer.p; + grpc_lb_addresses* addresses = (grpc_lb_addresses*)arg->value.pointer.p; if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { gpr_log(GPR_DEBUG, "[RR %p] received update with %" PRIuPTR " addresses", p, addresses->num_addresses); } - grpc_lb_subchannel_list *subchannel_list = grpc_lb_subchannel_list_create( + grpc_lb_subchannel_list* subchannel_list = grpc_lb_subchannel_list_create( exec_ctx, &p->base, &grpc_lb_round_robin_trace, addresses, args, rr_connectivity_changed_locked); if (subchannel_list->num_subchannels == 0) { @@ -615,8 +615,8 @@ static void rr_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, gpr_log(GPR_DEBUG, "[RR %p] Shutting down latest pending subchannel list %p, " "about to be replaced by newer latest %p", - (void *)p, (void *)p->latest_pending_subchannel_list, - (void *)subchannel_list); + (void*)p, (void*)p->latest_pending_subchannel_list, + (void*)subchannel_list); } grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->latest_pending_subchannel_list, "sl_outdated"); @@ -655,22 +655,22 @@ static const grpc_lb_policy_vtable round_robin_lb_policy_vtable = { rr_notify_on_state_change_locked, rr_update_locked}; -static void round_robin_factory_ref(grpc_lb_policy_factory *factory) {} +static void round_robin_factory_ref(grpc_lb_policy_factory* factory) {} -static void round_robin_factory_unref(grpc_lb_policy_factory *factory) {} +static void round_robin_factory_unref(grpc_lb_policy_factory* factory) {} -static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx, - grpc_lb_policy_factory *factory, - grpc_lb_policy_args *args) { +static grpc_lb_policy* round_robin_create(grpc_exec_ctx* exec_ctx, + grpc_lb_policy_factory* factory, + grpc_lb_policy_args* args) { GPR_ASSERT(args->client_channel_factory != NULL); - round_robin_lb_policy *p = (round_robin_lb_policy *)gpr_zalloc(sizeof(*p)); + round_robin_lb_policy* p = (round_robin_lb_policy*)gpr_zalloc(sizeof(*p)); grpc_lb_policy_init(&p->base, &round_robin_lb_policy_vtable, args->combiner); grpc_subchannel_index_ref(); grpc_connectivity_state_init(&p->state_tracker, GRPC_CHANNEL_IDLE, "round_robin"); rr_update_locked(exec_ctx, &p->base, args); if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { - gpr_log(GPR_DEBUG, "[RR %p] Created with %lu subchannels", (void *)p, + gpr_log(GPR_DEBUG, "[RR %p] Created with %lu subchannels", (void*)p, (unsigned long)p->subchannel_list->num_subchannels); } return &p->base; @@ -683,7 +683,7 @@ static const grpc_lb_policy_factory_vtable round_robin_factory_vtable = { static grpc_lb_policy_factory round_robin_lb_policy_factory = { &round_robin_factory_vtable}; -static grpc_lb_policy_factory *round_robin_lb_factory_create() { +static grpc_lb_policy_factory* round_robin_lb_factory_create() { return &round_robin_lb_policy_factory; } diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc index 08ea4f480b..db38ef5305 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc @@ -28,17 +28,18 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/transport/connectivity_state.h" -void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx *exec_ctx, - grpc_lb_subchannel_data *sd, - const char *reason) { +void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, + grpc_lb_subchannel_data* sd, + const char* reason) { if (sd->subchannel != NULL) { if (GRPC_TRACER_ON(*sd->subchannel_list->tracer)) { - gpr_log( - GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR - " of %" PRIuPTR " (subchannel %p): unreffing subchannel", - sd->subchannel_list->tracer->name, sd->subchannel_list->policy, - sd->subchannel_list, (size_t)(sd - sd->subchannel_list->subchannels), - sd->subchannel_list->num_subchannels, sd->subchannel); + gpr_log(GPR_DEBUG, + "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR + " (subchannel %p): unreffing subchannel", + sd->subchannel_list->tracer->name, sd->subchannel_list->policy, + sd->subchannel_list, + (size_t)(sd - sd->subchannel_list->subchannels), + sd->subchannel_list->num_subchannels, sd->subchannel); } GRPC_SUBCHANNEL_UNREF(exec_ctx, sd->subchannel, reason); sd->subchannel = NULL; @@ -56,7 +57,7 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx *exec_ctx, } void grpc_lb_subchannel_data_start_connectivity_watch( - grpc_exec_ctx *exec_ctx, grpc_lb_subchannel_data *sd) { + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd) { if (GRPC_TRACER_ON(*sd->subchannel_list->tracer)) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR @@ -74,25 +75,26 @@ void grpc_lb_subchannel_data_start_connectivity_watch( } void grpc_lb_subchannel_data_stop_connectivity_watch( - grpc_exec_ctx *exec_ctx, grpc_lb_subchannel_data *sd) { + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd) { if (GRPC_TRACER_ON(*sd->subchannel_list->tracer)) { - gpr_log( - GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR - " (subchannel %p): stopping connectivity watch", - sd->subchannel_list->tracer->name, sd->subchannel_list->policy, - sd->subchannel_list, (size_t)(sd - sd->subchannel_list->subchannels), - sd->subchannel_list->num_subchannels, sd->subchannel); + gpr_log(GPR_DEBUG, + "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR + " (subchannel %p): stopping connectivity watch", + sd->subchannel_list->tracer->name, sd->subchannel_list->policy, + sd->subchannel_list, + (size_t)(sd - sd->subchannel_list->subchannels), + sd->subchannel_list->num_subchannels, sd->subchannel); } GPR_ASSERT(sd->connectivity_notification_pending); sd->connectivity_notification_pending = false; } -grpc_lb_subchannel_list *grpc_lb_subchannel_list_create( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *p, grpc_tracer_flag *tracer, - const grpc_lb_addresses *addresses, const grpc_lb_policy_args *args, +grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( + grpc_exec_ctx* exec_ctx, grpc_lb_policy* p, grpc_tracer_flag* tracer, + const grpc_lb_addresses* addresses, const grpc_lb_policy_args* args, grpc_iomgr_cb_func connectivity_changed_cb) { - grpc_lb_subchannel_list *subchannel_list = - (grpc_lb_subchannel_list *)gpr_zalloc(sizeof(*subchannel_list)); + grpc_lb_subchannel_list* subchannel_list = + (grpc_lb_subchannel_list*)gpr_zalloc(sizeof(*subchannel_list)); if (GRPC_TRACER_ON(*tracer)) { gpr_log(GPR_DEBUG, "[%s %p] Creating subchannel list %p for %" PRIuPTR " subchannels", @@ -101,11 +103,11 @@ grpc_lb_subchannel_list *grpc_lb_subchannel_list_create( subchannel_list->policy = p; subchannel_list->tracer = tracer; gpr_ref_init(&subchannel_list->refcount, 1); - subchannel_list->subchannels = (grpc_lb_subchannel_data *)gpr_zalloc( + subchannel_list->subchannels = (grpc_lb_subchannel_data*)gpr_zalloc( sizeof(grpc_lb_subchannel_data) * addresses->num_addresses); // We need to remove the LB addresses in order to be able to compare the // subchannel keys of subchannels from a different batch of addresses. - static const char *keys_to_remove[] = {GRPC_ARG_SUBCHANNEL_ADDRESS, + static const char* keys_to_remove[] = {GRPC_ARG_SUBCHANNEL_ADDRESS, GRPC_ARG_LB_ADDRESSES}; // Create a subchannel for each address. grpc_subchannel_args sc_args; @@ -116,18 +118,18 @@ grpc_lb_subchannel_list *grpc_lb_subchannel_list_create( memset(&sc_args, 0, sizeof(grpc_subchannel_args)); grpc_arg addr_arg = grpc_create_subchannel_address_arg(&addresses->addresses[i].address); - grpc_channel_args *new_args = grpc_channel_args_copy_and_add_and_remove( + grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove( args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &addr_arg, 1); gpr_free(addr_arg.value.string); sc_args.args = new_args; - grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( + grpc_subchannel* subchannel = grpc_client_channel_factory_create_subchannel( exec_ctx, args->client_channel_factory, &sc_args); grpc_channel_args_destroy(exec_ctx, new_args); if (subchannel == NULL) { // Subchannel could not be created. if (GRPC_TRACER_ON(*tracer)) { - char *address_uri = + char* address_uri = grpc_sockaddr_to_uri(&addresses->addresses[i].address); gpr_log(GPR_DEBUG, "[%s %p] could not create subchannel for address uri %s, " @@ -138,15 +140,16 @@ grpc_lb_subchannel_list *grpc_lb_subchannel_list_create( continue; } if (GRPC_TRACER_ON(*tracer)) { - char *address_uri = + char* address_uri = grpc_sockaddr_to_uri(&addresses->addresses[i].address); - gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR - ": Created subchannel %p for address uri %s", + gpr_log(GPR_DEBUG, + "[%s %p] subchannel list %p index %" PRIuPTR + ": Created subchannel %p for address uri %s", tracer->name, p, subchannel_list, subchannel_index, subchannel, address_uri); gpr_free(address_uri); } - grpc_lb_subchannel_data *sd = + grpc_lb_subchannel_data* sd = &subchannel_list->subchannels[subchannel_index++]; sd->subchannel_list = subchannel_list; sd->subchannel = subchannel; @@ -169,15 +172,15 @@ grpc_lb_subchannel_list *grpc_lb_subchannel_list_create( return subchannel_list; } -static void subchannel_list_destroy(grpc_exec_ctx *exec_ctx, - grpc_lb_subchannel_list *subchannel_list) { +static void subchannel_list_destroy(grpc_exec_ctx* exec_ctx, + grpc_lb_subchannel_list* subchannel_list) { if (GRPC_TRACER_ON(*subchannel_list->tracer)) { gpr_log(GPR_DEBUG, "[%s %p] Destroying subchannel_list %p", subchannel_list->tracer->name, subchannel_list->policy, subchannel_list); } for (size_t i = 0; i < subchannel_list->num_subchannels; i++) { - grpc_lb_subchannel_data *sd = &subchannel_list->subchannels[i]; + grpc_lb_subchannel_data* sd = &subchannel_list->subchannels[i]; grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, "subchannel_list_destroy"); } @@ -185,8 +188,8 @@ static void subchannel_list_destroy(grpc_exec_ctx *exec_ctx, gpr_free(subchannel_list); } -void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list *subchannel_list, - const char *reason) { +void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list* subchannel_list, + const char* reason) { gpr_ref_non_zero(&subchannel_list->refcount); if (GRPC_TRACER_ON(*subchannel_list->tracer)) { const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count); @@ -197,9 +200,9 @@ void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list *subchannel_list, } } -void grpc_lb_subchannel_list_unref(grpc_exec_ctx *exec_ctx, - grpc_lb_subchannel_list *subchannel_list, - const char *reason) { +void grpc_lb_subchannel_list_unref(grpc_exec_ctx* exec_ctx, + grpc_lb_subchannel_list* subchannel_list, + const char* reason) { const bool done = gpr_unref(&subchannel_list->refcount); if (GRPC_TRACER_ON(*subchannel_list->tracer)) { const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count); @@ -214,35 +217,36 @@ void grpc_lb_subchannel_list_unref(grpc_exec_ctx *exec_ctx, } void grpc_lb_subchannel_list_ref_for_connectivity_watch( - grpc_lb_subchannel_list *subchannel_list, const char *reason) { + grpc_lb_subchannel_list* subchannel_list, const char* reason) { GRPC_LB_POLICY_WEAK_REF(subchannel_list->policy, reason); grpc_lb_subchannel_list_ref(subchannel_list, reason); } void grpc_lb_subchannel_list_unref_for_connectivity_watch( - grpc_exec_ctx *exec_ctx, grpc_lb_subchannel_list *subchannel_list, - const char *reason) { + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, + const char* reason) { GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, subchannel_list->policy, reason); grpc_lb_subchannel_list_unref(exec_ctx, subchannel_list, reason); } static void subchannel_data_cancel_connectivity_watch( - grpc_exec_ctx *exec_ctx, grpc_lb_subchannel_data *sd, const char *reason) { + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd, const char* reason) { if (GRPC_TRACER_ON(*sd->subchannel_list->tracer)) { - gpr_log( - GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR - " (subchannel %p): canceling connectivity watch (%s)", - sd->subchannel_list->tracer->name, sd->subchannel_list->policy, - sd->subchannel_list, (size_t)(sd - sd->subchannel_list->subchannels), - sd->subchannel_list->num_subchannels, sd->subchannel, reason); + gpr_log(GPR_DEBUG, + "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR + " (subchannel %p): canceling connectivity watch (%s)", + sd->subchannel_list->tracer->name, sd->subchannel_list->policy, + sd->subchannel_list, + (size_t)(sd - sd->subchannel_list->subchannels), + sd->subchannel_list->num_subchannels, sd->subchannel, reason); } grpc_subchannel_notify_on_state_change(exec_ctx, sd->subchannel, NULL, NULL, &sd->connectivity_changed_closure); } void grpc_lb_subchannel_list_shutdown_and_unref( - grpc_exec_ctx *exec_ctx, grpc_lb_subchannel_list *subchannel_list, - const char *reason) { + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, + const char* reason) { if (GRPC_TRACER_ON(*subchannel_list->tracer)) { gpr_log(GPR_DEBUG, "[%s %p] Shutting down subchannel_list %p (%s)", subchannel_list->tracer->name, subchannel_list->policy, @@ -251,7 +255,7 @@ void grpc_lb_subchannel_list_shutdown_and_unref( GPR_ASSERT(!subchannel_list->shutting_down); subchannel_list->shutting_down = true; for (size_t i = 0; i < subchannel_list->num_subchannels; i++) { - grpc_lb_subchannel_data *sd = &subchannel_list->subchannels[i]; + grpc_lb_subchannel_data* sd = &subchannel_list->subchannels[i]; // If there's a pending notification for this subchannel, cancel it; // the callback is responsible for unreffing the subchannel. // Otherwise, unref the subchannel directly. diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h index 9d5984260f..e18ad490e8 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h @@ -44,10 +44,10 @@ typedef struct grpc_lb_subchannel_list grpc_lb_subchannel_list; typedef struct { /** backpointer to owning subchannel list */ - grpc_lb_subchannel_list *subchannel_list; + grpc_lb_subchannel_list* subchannel_list; /** subchannel itself */ - grpc_subchannel *subchannel; - grpc_connected_subchannel *connected_subchannel; + grpc_subchannel* subchannel; + grpc_connected_subchannel* connected_subchannel; /** Is a connectivity notification pending? */ bool connectivity_notification_pending; /** notification that connectivity has changed on subchannel */ @@ -63,36 +63,36 @@ typedef struct { * \a connectivity_changed_closure. */ grpc_connectivity_state pending_connectivity_state_unsafe; /** the subchannel's target user data */ - void *user_data; + void* user_data; /** vtable to operate over \a user_data */ - const grpc_lb_user_data_vtable *user_data_vtable; + const grpc_lb_user_data_vtable* user_data_vtable; } grpc_lb_subchannel_data; /// Unrefs the subchannel contained in sd. -void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx *exec_ctx, - grpc_lb_subchannel_data *sd, - const char *reason); +void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, + grpc_lb_subchannel_data* sd, + const char* reason); /// Starts watching the connectivity state of the subchannel. /// The connectivity_changed_cb callback must invoke either /// grpc_lb_subchannel_data_stop_connectivity_watch() or again call /// grpc_lb_subchannel_data_start_connectivity_watch(). void grpc_lb_subchannel_data_start_connectivity_watch( - grpc_exec_ctx *exec_ctx, grpc_lb_subchannel_data *sd); + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd); /// Stops watching the connectivity state of the subchannel. void grpc_lb_subchannel_data_stop_connectivity_watch( - grpc_exec_ctx *exec_ctx, grpc_lb_subchannel_data *sd); + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd); struct grpc_lb_subchannel_list { /** backpointer to owning policy */ - grpc_lb_policy *policy; + grpc_lb_policy* policy; - grpc_tracer_flag *tracer; + grpc_tracer_flag* tracer; /** all our subchannels */ size_t num_subchannels; - grpc_lb_subchannel_data *subchannels; + grpc_lb_subchannel_data* subchannels; /** Index into subchannels of the one we're currently checking. * Used when connecting to subchannels serially instead of in parallel. */ @@ -120,31 +120,31 @@ struct grpc_lb_subchannel_list { bool shutting_down; }; -grpc_lb_subchannel_list *grpc_lb_subchannel_list_create( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *p, grpc_tracer_flag *tracer, - const grpc_lb_addresses *addresses, const grpc_lb_policy_args *args, +grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( + grpc_exec_ctx* exec_ctx, grpc_lb_policy* p, grpc_tracer_flag* tracer, + const grpc_lb_addresses* addresses, const grpc_lb_policy_args* args, grpc_iomgr_cb_func connectivity_changed_cb); -void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list *subchannel_list, - const char *reason); +void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list* subchannel_list, + const char* reason); -void grpc_lb_subchannel_list_unref(grpc_exec_ctx *exec_ctx, - grpc_lb_subchannel_list *subchannel_list, - const char *reason); +void grpc_lb_subchannel_list_unref(grpc_exec_ctx* exec_ctx, + grpc_lb_subchannel_list* subchannel_list, + const char* reason); /// Takes and releases refs needed for a connectivity notification. /// This includes a ref to subchannel_list and a weak ref to the LB policy. void grpc_lb_subchannel_list_ref_for_connectivity_watch( - grpc_lb_subchannel_list *subchannel_list, const char *reason); + grpc_lb_subchannel_list* subchannel_list, const char* reason); void grpc_lb_subchannel_list_unref_for_connectivity_watch( - grpc_exec_ctx *exec_ctx, grpc_lb_subchannel_list *subchannel_list, - const char *reason); + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, + const char* reason); /// Mark subchannel_list as discarded. Unsubscribes all its subchannels. The /// connectivity state notification callback will ultimately unref it. void grpc_lb_subchannel_list_shutdown_and_unref( - grpc_exec_ctx *exec_ctx, grpc_lb_subchannel_list *subchannel_list, - const char *reason); + grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, + const char* reason); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/lb_policy_factory.h b/src/core/ext/filters/client_channel/lb_policy_factory.h index 8790ffdda3..360a42b177 100644 --- a/src/core/ext/filters/client_channel/lb_policy_factory.h +++ b/src/core/ext/filters/client_channel/lb_policy_factory.h @@ -37,7 +37,7 @@ typedef struct grpc_lb_policy_factory grpc_lb_policy_factory; typedef struct grpc_lb_policy_factory_vtable grpc_lb_policy_factory_vtable; struct grpc_lb_policy_factory { - const grpc_lb_policy_factory_vtable *vtable; + const grpc_lb_policy_factory_vtable* vtable; }; /** A resolved address alongside any LB related information associated with it. @@ -48,91 +48,91 @@ struct grpc_lb_policy_factory { typedef struct grpc_lb_address { grpc_resolved_address address; bool is_balancer; - char *balancer_name; /* For secure naming. */ - void *user_data; + char* balancer_name; /* For secure naming. */ + void* user_data; } grpc_lb_address; typedef struct grpc_lb_user_data_vtable { - void *(*copy)(void *); - void (*destroy)(grpc_exec_ctx *exec_ctx, void *); - int (*cmp)(void *, void *); + void* (*copy)(void*); + void (*destroy)(grpc_exec_ctx* exec_ctx, void*); + int (*cmp)(void*, void*); } grpc_lb_user_data_vtable; typedef struct grpc_lb_addresses { size_t num_addresses; - grpc_lb_address *addresses; - const grpc_lb_user_data_vtable *user_data_vtable; + grpc_lb_address* addresses; + const grpc_lb_user_data_vtable* user_data_vtable; } grpc_lb_addresses; /** Returns a grpc_addresses struct with enough space for \a num_addresses addresses. The \a user_data_vtable argument may be NULL if no user data will be added. */ -grpc_lb_addresses *grpc_lb_addresses_create( - size_t num_addresses, const grpc_lb_user_data_vtable *user_data_vtable); +grpc_lb_addresses* grpc_lb_addresses_create( + size_t num_addresses, const grpc_lb_user_data_vtable* user_data_vtable); /** Creates a copy of \a addresses. */ -grpc_lb_addresses *grpc_lb_addresses_copy(const grpc_lb_addresses *addresses); +grpc_lb_addresses* grpc_lb_addresses_copy(const grpc_lb_addresses* addresses); /** Sets the value of the address at index \a index of \a addresses. * \a address is a socket address of length \a address_len. * Takes ownership of \a balancer_name. */ -void grpc_lb_addresses_set_address(grpc_lb_addresses *addresses, size_t index, - const void *address, size_t address_len, - bool is_balancer, const char *balancer_name, - void *user_data); +void grpc_lb_addresses_set_address(grpc_lb_addresses* addresses, size_t index, + const void* address, size_t address_len, + bool is_balancer, const char* balancer_name, + void* user_data); /** Sets the value of the address at index \a index of \a addresses from \a uri. * Returns true upon success, false otherwise. Takes ownership of \a * balancer_name. */ -bool grpc_lb_addresses_set_address_from_uri(grpc_lb_addresses *addresses, - size_t index, const grpc_uri *uri, +bool grpc_lb_addresses_set_address_from_uri(grpc_lb_addresses* addresses, + size_t index, const grpc_uri* uri, bool is_balancer, - const char *balancer_name, - void *user_data); + const char* balancer_name, + void* user_data); /** Compares \a addresses1 and \a addresses2. */ -int grpc_lb_addresses_cmp(const grpc_lb_addresses *addresses1, - const grpc_lb_addresses *addresses2); +int grpc_lb_addresses_cmp(const grpc_lb_addresses* addresses1, + const grpc_lb_addresses* addresses2); /** Destroys \a addresses. */ -void grpc_lb_addresses_destroy(grpc_exec_ctx *exec_ctx, - grpc_lb_addresses *addresses); +void grpc_lb_addresses_destroy(grpc_exec_ctx* exec_ctx, + grpc_lb_addresses* addresses); /** Returns a channel arg containing \a addresses. */ grpc_arg grpc_lb_addresses_create_channel_arg( - const grpc_lb_addresses *addresses); + const grpc_lb_addresses* addresses); /** Returns the \a grpc_lb_addresses instance in \a channel_args or NULL */ -grpc_lb_addresses *grpc_lb_addresses_find_channel_arg( - const grpc_channel_args *channel_args); +grpc_lb_addresses* grpc_lb_addresses_find_channel_arg( + const grpc_channel_args* channel_args); /** Arguments passed to LB policies. */ struct grpc_lb_policy_args { - grpc_client_channel_factory *client_channel_factory; - grpc_channel_args *args; - grpc_combiner *combiner; + grpc_client_channel_factory* client_channel_factory; + grpc_channel_args* args; + grpc_combiner* combiner; }; struct grpc_lb_policy_factory_vtable { - void (*ref)(grpc_lb_policy_factory *factory); - void (*unref)(grpc_lb_policy_factory *factory); + void (*ref)(grpc_lb_policy_factory* factory); + void (*unref)(grpc_lb_policy_factory* factory); /** Implementation of grpc_lb_policy_factory_create_lb_policy */ - grpc_lb_policy *(*create_lb_policy)(grpc_exec_ctx *exec_ctx, - grpc_lb_policy_factory *factory, - grpc_lb_policy_args *args); + grpc_lb_policy* (*create_lb_policy)(grpc_exec_ctx* exec_ctx, + grpc_lb_policy_factory* factory, + grpc_lb_policy_args* args); /** Name for the LB policy this factory implements */ - const char *name; + const char* name; }; -void grpc_lb_policy_factory_ref(grpc_lb_policy_factory *factory); -void grpc_lb_policy_factory_unref(grpc_lb_policy_factory *factory); +void grpc_lb_policy_factory_ref(grpc_lb_policy_factory* factory); +void grpc_lb_policy_factory_unref(grpc_lb_policy_factory* factory); /** Create a lb_policy instance. */ -grpc_lb_policy *grpc_lb_policy_factory_create_lb_policy( - grpc_exec_ctx *exec_ctx, grpc_lb_policy_factory *factory, - grpc_lb_policy_args *args); +grpc_lb_policy* grpc_lb_policy_factory_create_lb_policy( + grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, + grpc_lb_policy_args* args); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/lb_policy_registry.cc b/src/core/ext/filters/client_channel/lb_policy_registry.cc index f2460f8304..7b0a926a1b 100644 --- a/src/core/ext/filters/client_channel/lb_policy_registry.cc +++ b/src/core/ext/filters/client_channel/lb_policy_registry.cc @@ -24,7 +24,7 @@ #define MAX_POLICIES 10 -static grpc_lb_policy_factory *g_all_of_the_lb_policies[MAX_POLICIES]; +static grpc_lb_policy_factory* g_all_of_the_lb_policies[MAX_POLICIES]; static int g_number_of_lb_policies = 0; void grpc_lb_policy_registry_init(void) { g_number_of_lb_policies = 0; } @@ -36,7 +36,7 @@ void grpc_lb_policy_registry_shutdown(void) { } } -void grpc_register_lb_policy(grpc_lb_policy_factory *factory) { +void grpc_register_lb_policy(grpc_lb_policy_factory* factory) { int i; for (i = 0; i < g_number_of_lb_policies; i++) { GPR_ASSERT(0 != gpr_stricmp(factory->vtable->name, @@ -47,7 +47,7 @@ void grpc_register_lb_policy(grpc_lb_policy_factory *factory) { g_all_of_the_lb_policies[g_number_of_lb_policies++] = factory; } -static grpc_lb_policy_factory *lookup_factory(const char *name) { +static grpc_lb_policy_factory* lookup_factory(const char* name) { int i; if (name == NULL) return NULL; @@ -61,10 +61,10 @@ static grpc_lb_policy_factory *lookup_factory(const char *name) { return NULL; } -grpc_lb_policy *grpc_lb_policy_create(grpc_exec_ctx *exec_ctx, const char *name, - grpc_lb_policy_args *args) { - grpc_lb_policy_factory *factory = lookup_factory(name); - grpc_lb_policy *lb_policy = +grpc_lb_policy* grpc_lb_policy_create(grpc_exec_ctx* exec_ctx, const char* name, + grpc_lb_policy_args* args) { + grpc_lb_policy_factory* factory = lookup_factory(name); + grpc_lb_policy* lb_policy = grpc_lb_policy_factory_create_lb_policy(exec_ctx, factory, args); return lb_policy; } diff --git a/src/core/ext/filters/client_channel/lb_policy_registry.h b/src/core/ext/filters/client_channel/lb_policy_registry.h index 55154cb02a..055f751b57 100644 --- a/src/core/ext/filters/client_channel/lb_policy_registry.h +++ b/src/core/ext/filters/client_channel/lb_policy_registry.h @@ -32,14 +32,14 @@ void grpc_lb_policy_registry_init(void); void grpc_lb_policy_registry_shutdown(void); /** Register a LB policy factory. */ -void grpc_register_lb_policy(grpc_lb_policy_factory *factory); +void grpc_register_lb_policy(grpc_lb_policy_factory* factory); /** Create a \a grpc_lb_policy instance. * * If \a name is NULL, the default factory from \a grpc_lb_policy_registry_init * will be returned. */ -grpc_lb_policy *grpc_lb_policy_create(grpc_exec_ctx *exec_ctx, const char *name, - grpc_lb_policy_args *args); +grpc_lb_policy* grpc_lb_policy_create(grpc_exec_ctx* exec_ctx, const char* name, + grpc_lb_policy_args* args); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/parse_address.cc b/src/core/ext/filters/client_channel/parse_address.cc index 2152b5a1e9..6cf77f13bc 100644 --- a/src/core/ext/filters/client_channel/parse_address.cc +++ b/src/core/ext/filters/client_channel/parse_address.cc @@ -33,13 +33,13 @@ #ifdef GRPC_HAVE_UNIX_SOCKET -bool grpc_parse_unix(const grpc_uri *uri, - grpc_resolved_address *resolved_addr) { +bool grpc_parse_unix(const grpc_uri* uri, + grpc_resolved_address* resolved_addr) { if (strcmp("unix", uri->scheme) != 0) { gpr_log(GPR_ERROR, "Expected 'unix' scheme, got '%s'", uri->scheme); return false; } - struct sockaddr_un *un = (struct sockaddr_un *)resolved_addr->addr; + struct sockaddr_un* un = (struct sockaddr_un*)resolved_addr->addr; const size_t maxlen = sizeof(un->sun_path); const size_t path_len = strnlen(uri->path, maxlen); if (path_len == maxlen) return false; @@ -51,24 +51,24 @@ bool grpc_parse_unix(const grpc_uri *uri, #else /* GRPC_HAVE_UNIX_SOCKET */ -bool grpc_parse_unix(const grpc_uri *uri, - grpc_resolved_address *resolved_addr) { +bool grpc_parse_unix(const grpc_uri* uri, + grpc_resolved_address* resolved_addr) { abort(); } #endif /* GRPC_HAVE_UNIX_SOCKET */ -bool grpc_parse_ipv4_hostport(const char *hostport, grpc_resolved_address *addr, +bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr, bool log_errors) { bool success = false; // Split host and port. - char *host; - char *port; + char* host; + char* port; if (!gpr_split_host_port(hostport, &host, &port)) return false; // Parse IP address. memset(addr, 0, sizeof(*addr)); addr->len = sizeof(struct sockaddr_in); - struct sockaddr_in *in = (struct sockaddr_in *)addr->addr; + struct sockaddr_in* in = (struct sockaddr_in*)addr->addr; in->sin_family = AF_INET; if (inet_pton(AF_INET, host, &in->sin_addr) == 0) { if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host); @@ -92,32 +92,32 @@ done: return success; } -bool grpc_parse_ipv4(const grpc_uri *uri, - grpc_resolved_address *resolved_addr) { +bool grpc_parse_ipv4(const grpc_uri* uri, + grpc_resolved_address* resolved_addr) { if (strcmp("ipv4", uri->scheme) != 0) { gpr_log(GPR_ERROR, "Expected 'ipv4' scheme, got '%s'", uri->scheme); return false; } - const char *host_port = uri->path; + const char* host_port = uri->path; if (*host_port == '/') ++host_port; return grpc_parse_ipv4_hostport(host_port, resolved_addr, true /* log_errors */); } -bool grpc_parse_ipv6_hostport(const char *hostport, grpc_resolved_address *addr, +bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, bool log_errors) { bool success = false; // Split host and port. - char *host; - char *port; + char* host; + char* port; if (!gpr_split_host_port(hostport, &host, &port)) return false; // Parse IP address. memset(addr, 0, sizeof(*addr)); addr->len = sizeof(struct sockaddr_in6); - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr->addr; + struct sockaddr_in6* in6 = (struct sockaddr_in6*)addr->addr; in6->sin6_family = AF_INET6; // Handle the RFC6874 syntax for IPv6 zone identifiers. - char *host_end = (char *)gpr_memrchr(host, '%', strlen(host)); + char* host_end = (char*)gpr_memrchr(host, '%', strlen(host)); if (host_end != NULL) { GPR_ASSERT(host_end >= host); char host_without_scope[INET6_ADDRSTRLEN]; @@ -161,19 +161,19 @@ done: return success; } -bool grpc_parse_ipv6(const grpc_uri *uri, - grpc_resolved_address *resolved_addr) { +bool grpc_parse_ipv6(const grpc_uri* uri, + grpc_resolved_address* resolved_addr) { if (strcmp("ipv6", uri->scheme) != 0) { gpr_log(GPR_ERROR, "Expected 'ipv6' scheme, got '%s'", uri->scheme); return false; } - const char *host_port = uri->path; + const char* host_port = uri->path; if (*host_port == '/') ++host_port; return grpc_parse_ipv6_hostport(host_port, resolved_addr, true /* log_errors */); } -bool grpc_parse_uri(const grpc_uri *uri, grpc_resolved_address *resolved_addr) { +bool grpc_parse_uri(const grpc_uri* uri, grpc_resolved_address* resolved_addr) { if (strcmp("unix", uri->scheme) == 0) { return grpc_parse_unix(uri, resolved_addr); } else if (strcmp("ipv4", uri->scheme) == 0) { diff --git a/src/core/ext/filters/client_channel/parse_address.h b/src/core/ext/filters/client_channel/parse_address.h index 27d06a1cb3..b45859f9a2 100644 --- a/src/core/ext/filters/client_channel/parse_address.h +++ b/src/core/ext/filters/client_channel/parse_address.h @@ -30,23 +30,23 @@ extern "C" { /** Populate \a resolved_addr from \a uri, whose path is expected to contain a * unix socket path. Returns true upon success. */ -bool grpc_parse_unix(const grpc_uri *uri, grpc_resolved_address *resolved_addr); +bool grpc_parse_unix(const grpc_uri* uri, grpc_resolved_address* resolved_addr); /** Populate \a resolved_addr from \a uri, whose path is expected to contain an * IPv4 host:port pair. Returns true upon success. */ -bool grpc_parse_ipv4(const grpc_uri *uri, grpc_resolved_address *resolved_addr); +bool grpc_parse_ipv4(const grpc_uri* uri, grpc_resolved_address* resolved_addr); /** Populate \a resolved_addr from \a uri, whose path is expected to contain an * IPv6 host:port pair. Returns true upon success. */ -bool grpc_parse_ipv6(const grpc_uri *uri, grpc_resolved_address *resolved_addr); +bool grpc_parse_ipv6(const grpc_uri* uri, grpc_resolved_address* resolved_addr); /** Populate \a resolved_addr from \a uri. Returns true upon success. */ -bool grpc_parse_uri(const grpc_uri *uri, grpc_resolved_address *resolved_addr); +bool grpc_parse_uri(const grpc_uri* uri, grpc_resolved_address* resolved_addr); /** Parse bare IPv4 or IPv6 "IP:port" strings. */ -bool grpc_parse_ipv4_hostport(const char *hostport, grpc_resolved_address *addr, +bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr, bool log_errors); -bool grpc_parse_ipv6_hostport(const char *hostport, grpc_resolved_address *addr, +bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, bool log_errors); #ifdef __cplusplus diff --git a/src/core/ext/filters/client_channel/resolver.cc b/src/core/ext/filters/client_channel/resolver.cc index 8401504fcf..7e84b98cb9 100644 --- a/src/core/ext/filters/client_channel/resolver.cc +++ b/src/core/ext/filters/client_channel/resolver.cc @@ -24,17 +24,17 @@ grpc_tracer_flag grpc_trace_resolver_refcount = GRPC_TRACER_INITIALIZER(false, "resolver_refcount"); #endif -void grpc_resolver_init(grpc_resolver *resolver, - const grpc_resolver_vtable *vtable, - grpc_combiner *combiner) { +void grpc_resolver_init(grpc_resolver* resolver, + const grpc_resolver_vtable* vtable, + grpc_combiner* combiner) { resolver->vtable = vtable; resolver->combiner = GRPC_COMBINER_REF(combiner, "resolver"); gpr_ref_init(&resolver->refs, 1); } #ifndef NDEBUG -void grpc_resolver_ref(grpc_resolver *resolver, const char *file, int line, - const char *reason) { +void grpc_resolver_ref(grpc_resolver* resolver, const char* file, int line, + const char* reason) { if (GRPC_TRACER_ON(grpc_trace_resolver_refcount)) { gpr_atm old_refs = gpr_atm_no_barrier_load(&resolver->refs.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -42,14 +42,14 @@ void grpc_resolver_ref(grpc_resolver *resolver, const char *file, int line, old_refs, old_refs + 1, reason); } #else -void grpc_resolver_ref(grpc_resolver *resolver) { +void grpc_resolver_ref(grpc_resolver* resolver) { #endif gpr_ref(&resolver->refs); } #ifndef NDEBUG -void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - const char *file, int line, const char *reason) { +void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, + const char* file, int line, const char* reason) { if (GRPC_TRACER_ON(grpc_trace_resolver_refcount)) { gpr_atm old_refs = gpr_atm_no_barrier_load(&resolver->refs.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -57,27 +57,27 @@ void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, old_refs, old_refs - 1, reason); } #else -void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver) { +void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver) { #endif if (gpr_unref(&resolver->refs)) { - grpc_combiner *combiner = resolver->combiner; + grpc_combiner* combiner = resolver->combiner; resolver->vtable->destroy(exec_ctx, resolver); GRPC_COMBINER_UNREF(exec_ctx, combiner, "resolver"); } } -void grpc_resolver_shutdown_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver) { +void grpc_resolver_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { resolver->vtable->shutdown_locked(exec_ctx, resolver); } -void grpc_resolver_channel_saw_error_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver) { +void grpc_resolver_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { resolver->vtable->channel_saw_error_locked(exec_ctx, resolver); } -void grpc_resolver_next_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_channel_args **result, - grpc_closure *on_complete) { +void grpc_resolver_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, + grpc_channel_args** result, + grpc_closure* on_complete) { resolver->vtable->next_locked(exec_ctx, resolver, result, on_complete); } diff --git a/src/core/ext/filters/client_channel/resolver.h b/src/core/ext/filters/client_channel/resolver.h index 73fbbbbc3b..a0eb0bcfdf 100644 --- a/src/core/ext/filters/client_channel/resolver.h +++ b/src/core/ext/filters/client_channel/resolver.h @@ -35,49 +35,49 @@ extern grpc_tracer_flag grpc_trace_resolver_refcount; /** \a grpc_resolver provides \a grpc_channel_args objects to its caller */ struct grpc_resolver { - const grpc_resolver_vtable *vtable; + const grpc_resolver_vtable* vtable; gpr_refcount refs; - grpc_combiner *combiner; + grpc_combiner* combiner; }; struct grpc_resolver_vtable { - void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); - void (*shutdown_locked)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); - void (*channel_saw_error_locked)(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver); - void (*next_locked)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_channel_args **result, grpc_closure *on_complete); + void (*destroy)(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver); + void (*shutdown_locked)(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver); + void (*channel_saw_error_locked)(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver); + void (*next_locked)(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, + grpc_channel_args** result, grpc_closure* on_complete); }; #ifndef NDEBUG #define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p), __FILE__, __LINE__, (r)) #define GRPC_RESOLVER_UNREF(e, p, r) \ grpc_resolver_unref((e), (p), __FILE__, __LINE__, (r)) -void grpc_resolver_ref(grpc_resolver *policy, const char *file, int line, - const char *reason); -void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *policy, - const char *file, int line, const char *reason); +void grpc_resolver_ref(grpc_resolver* policy, const char* file, int line, + const char* reason); +void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* policy, + const char* file, int line, const char* reason); #else #define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p)) #define GRPC_RESOLVER_UNREF(e, p, r) grpc_resolver_unref((e), (p)) -void grpc_resolver_ref(grpc_resolver *policy); -void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *policy); +void grpc_resolver_ref(grpc_resolver* policy); +void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* policy); #endif -void grpc_resolver_init(grpc_resolver *resolver, - const grpc_resolver_vtable *vtable, - grpc_combiner *combiner); +void grpc_resolver_init(grpc_resolver* resolver, + const grpc_resolver_vtable* vtable, + grpc_combiner* combiner); -void grpc_resolver_shutdown_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver); +void grpc_resolver_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver); /** Notification that the channel has seen an error on some address. Can be used as a hint that re-resolution is desirable soon. Must be called from the combiner passed as a resolver_arg at construction time.*/ -void grpc_resolver_channel_saw_error_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver); +void grpc_resolver_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver); /** Get the next result from the resolver. Expected to set \a *result with new channel args and then schedule \a on_complete for execution. @@ -87,9 +87,9 @@ void grpc_resolver_channel_saw_error_locked(grpc_exec_ctx *exec_ctx, Must be called from the combiner passed as a resolver_arg at construction time.*/ -void grpc_resolver_next_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_channel_args **result, - grpc_closure *on_complete); +void grpc_resolver_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, + grpc_channel_args** result, + grpc_closure* on_complete); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index a1ddaee499..76f08281f7 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -53,38 +53,38 @@ typedef struct { /** base class: must be first */ grpc_resolver base; /** DNS server to use (if not system default) */ - char *dns_server; + char* dns_server; /** name to resolve (usually the same as target_name) */ - char *name_to_resolve; + char* name_to_resolve; /** default port to use */ - char *default_port; + char* default_port; /** channel args. */ - grpc_channel_args *channel_args; + grpc_channel_args* channel_args; /** whether to request the service config */ bool request_service_config; /** pollset_set to drive the name resolution process */ - grpc_pollset_set *interested_parties; + grpc_pollset_set* interested_parties; /** Closures used by the combiner */ grpc_closure dns_ares_on_retry_timer_locked; grpc_closure dns_ares_on_resolved_locked; /** Combiner guarding the rest of the state */ - grpc_combiner *combiner; + grpc_combiner* combiner; /** are we currently resolving? */ bool resolving; /** the pending resolving request */ - grpc_ares_request *pending_request; + grpc_ares_request* pending_request; /** which version of the result have we published? */ int published_version; /** which version of the result is current? */ int resolved_version; /** pending next completion, or NULL */ - grpc_closure *next_completion; + grpc_closure* next_completion; /** target result address for next completion */ - grpc_channel_args **target_result; + grpc_channel_args** target_result; /** current (fully resolved) result */ - grpc_channel_args *resolved_result; + grpc_channel_args* resolved_result; /** retry timer */ bool have_retry_timer; grpc_timer retry_timer; @@ -92,32 +92,32 @@ typedef struct { grpc_backoff backoff_state; /** currently resolving addresses */ - grpc_lb_addresses *lb_addresses; + grpc_lb_addresses* lb_addresses; /** currently resolving service config */ - char *service_config_json; + char* service_config_json; } ares_dns_resolver; -static void dns_ares_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *r); +static void dns_ares_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* r); -static void dns_ares_start_resolving_locked(grpc_exec_ctx *exec_ctx, - ares_dns_resolver *r); -static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, - ares_dns_resolver *r); +static void dns_ares_start_resolving_locked(grpc_exec_ctx* exec_ctx, + ares_dns_resolver* r); +static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + ares_dns_resolver* r); -static void dns_ares_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *r); -static void dns_ares_channel_saw_error_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *r); -static void dns_ares_next_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *r, - grpc_channel_args **target_result, - grpc_closure *on_complete); +static void dns_ares_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r); +static void dns_ares_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* r); +static void dns_ares_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r, + grpc_channel_args** target_result, + grpc_closure* on_complete); static const grpc_resolver_vtable dns_ares_resolver_vtable = { dns_ares_destroy, dns_ares_shutdown_locked, dns_ares_channel_saw_error_locked, dns_ares_next_locked}; -static void dns_ares_shutdown_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver) { - ares_dns_resolver *r = (ares_dns_resolver *)resolver; +static void dns_ares_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { + ares_dns_resolver* r = (ares_dns_resolver*)resolver; if (r->have_retry_timer) { grpc_timer_cancel(exec_ctx, &r->retry_timer); } @@ -133,18 +133,18 @@ static void dns_ares_shutdown_locked(grpc_exec_ctx *exec_ctx, } } -static void dns_ares_channel_saw_error_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver) { - ares_dns_resolver *r = (ares_dns_resolver *)resolver; +static void dns_ares_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { + ares_dns_resolver* r = (ares_dns_resolver*)resolver; if (!r->resolving) { grpc_backoff_reset(&r->backoff_state); dns_ares_start_resolving_locked(exec_ctx, r); } } -static void dns_ares_on_retry_timer_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - ares_dns_resolver *r = (ares_dns_resolver *)arg; +static void dns_ares_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + ares_dns_resolver* r = (ares_dns_resolver*)arg; r->have_retry_timer = false; if (error == GRPC_ERROR_NONE) { if (!r->resolving) { @@ -154,8 +154,8 @@ static void dns_ares_on_retry_timer_locked(grpc_exec_ctx *exec_ctx, void *arg, GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "retry-timer"); } -static bool value_in_json_array(grpc_json *array, const char *value) { - for (grpc_json *entry = array->child; entry != NULL; entry = entry->next) { +static bool value_in_json_array(grpc_json* array, const char* value) { + for (grpc_json* entry = array->child; entry != NULL; entry = entry->next) { if (entry->type == GRPC_JSON_STRING && strcmp(entry->value, value) == 0) { return true; } @@ -163,21 +163,21 @@ static bool value_in_json_array(grpc_json *array, const char *value) { return false; } -static char *choose_service_config(char *service_config_choice_json) { - grpc_json *choices_json = grpc_json_parse_string(service_config_choice_json); +static char* choose_service_config(char* service_config_choice_json) { + grpc_json* choices_json = grpc_json_parse_string(service_config_choice_json); if (choices_json == NULL || choices_json->type != GRPC_JSON_ARRAY) { gpr_log(GPR_ERROR, "cannot parse service config JSON string"); return NULL; } - char *service_config = NULL; - for (grpc_json *choice = choices_json->child; choice != NULL; + char* service_config = NULL; + for (grpc_json* choice = choices_json->child; choice != NULL; choice = choice->next) { if (choice->type != GRPC_JSON_OBJECT) { gpr_log(GPR_ERROR, "cannot parse service config JSON string"); break; } - grpc_json *service_config_json = NULL; - for (grpc_json *field = choice->child; field != NULL; field = field->next) { + grpc_json* service_config_json = NULL; + for (grpc_json* field = choice->child; field != NULL; field = field->next) { // Check client language, if specified. if (strcmp(field->key, "clientLanguage") == 0) { if (field->type != GRPC_JSON_ARRAY || @@ -188,7 +188,7 @@ static char *choose_service_config(char *service_config_choice_json) { } // Check client hostname, if specified. if (strcmp(field->key, "clientHostname") == 0) { - char *hostname = grpc_gethostname(); + char* hostname = grpc_gethostname(); if (hostname == NULL || field->type != GRPC_JSON_ARRAY || !value_in_json_array(field, hostname)) { service_config_json = NULL; @@ -225,22 +225,22 @@ static char *choose_service_config(char *service_config_choice_json) { return service_config; } -static void dns_ares_on_resolved_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - ares_dns_resolver *r = (ares_dns_resolver *)arg; - grpc_channel_args *result = NULL; +static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + ares_dns_resolver* r = (ares_dns_resolver*)arg; + grpc_channel_args* result = NULL; GPR_ASSERT(r->resolving); r->resolving = false; r->pending_request = NULL; if (r->lb_addresses != NULL) { - static const char *args_to_remove[2]; + static const char* args_to_remove[2]; size_t num_args_to_remove = 0; grpc_arg new_args[3]; size_t num_args_to_add = 0; new_args[num_args_to_add++] = grpc_lb_addresses_create_channel_arg(r->lb_addresses); - grpc_service_config *service_config = NULL; - char *service_config_string = NULL; + grpc_service_config* service_config = NULL; + char* service_config_string = NULL; if (r->service_config_json != NULL) { service_config_string = choose_service_config(r->service_config_json); gpr_free(r->service_config_json); @@ -249,15 +249,15 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx *exec_ctx, void *arg, service_config_string); args_to_remove[num_args_to_remove++] = GRPC_ARG_SERVICE_CONFIG; new_args[num_args_to_add++] = grpc_channel_arg_string_create( - (char *)GRPC_ARG_SERVICE_CONFIG, service_config_string); + (char*)GRPC_ARG_SERVICE_CONFIG, service_config_string); service_config = grpc_service_config_create(service_config_string); if (service_config != NULL) { - const char *lb_policy_name = + const char* lb_policy_name = grpc_service_config_get_lb_policy_name(service_config); if (lb_policy_name != NULL) { args_to_remove[num_args_to_remove++] = GRPC_ARG_LB_POLICY_NAME; new_args[num_args_to_add++] = grpc_channel_arg_string_create( - (char *)GRPC_ARG_LB_POLICY_NAME, (char *)lb_policy_name); + (char*)GRPC_ARG_LB_POLICY_NAME, (char*)lb_policy_name); } } } @@ -269,7 +269,7 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx *exec_ctx, void *arg, gpr_free(service_config_string); grpc_lb_addresses_destroy(exec_ctx, r->lb_addresses); } else { - const char *msg = grpc_error_string(error); + const char* msg = grpc_error_string(error); gpr_log(GPR_DEBUG, "dns resolution failed: %s", msg); grpc_millis next_try = grpc_backoff_step(exec_ctx, &r->backoff_state).next_attempt_start_time; @@ -296,12 +296,12 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx *exec_ctx, void *arg, GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "dns-resolving"); } -static void dns_ares_next_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver, - grpc_channel_args **target_result, - grpc_closure *on_complete) { +static void dns_ares_next_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver, + grpc_channel_args** target_result, + grpc_closure* on_complete) { gpr_log(GPR_DEBUG, "dns_ares_next is called."); - ares_dns_resolver *r = (ares_dns_resolver *)resolver; + ares_dns_resolver* r = (ares_dns_resolver*)resolver; GPR_ASSERT(!r->next_completion); r->next_completion = on_complete; r->target_result = target_result; @@ -313,8 +313,8 @@ static void dns_ares_next_locked(grpc_exec_ctx *exec_ctx, } } -static void dns_ares_start_resolving_locked(grpc_exec_ctx *exec_ctx, - ares_dns_resolver *r) { +static void dns_ares_start_resolving_locked(grpc_exec_ctx* exec_ctx, + ares_dns_resolver* r) { GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GPR_ASSERT(!r->resolving); r->resolving = true; @@ -327,8 +327,8 @@ static void dns_ares_start_resolving_locked(grpc_exec_ctx *exec_ctx, r->request_service_config ? &r->service_config_json : NULL); } -static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, - ares_dns_resolver *r) { +static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + ares_dns_resolver* r) { if (r->next_completion != NULL && r->resolved_version != r->published_version) { *r->target_result = r->resolved_result == NULL @@ -341,9 +341,9 @@ static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, } } -static void dns_ares_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { +static void dns_ares_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { gpr_log(GPR_DEBUG, "dns_ares_destroy"); - ares_dns_resolver *r = (ares_dns_resolver *)gr; + ares_dns_resolver* r = (ares_dns_resolver*)gr; if (r->resolved_result != NULL) { grpc_channel_args_destroy(exec_ctx, r->resolved_result); } @@ -355,15 +355,15 @@ static void dns_ares_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { gpr_free(r); } -static grpc_resolver *dns_ares_create(grpc_exec_ctx *exec_ctx, - grpc_resolver_args *args, - const char *default_port) { +static grpc_resolver* dns_ares_create(grpc_exec_ctx* exec_ctx, + grpc_resolver_args* args, + const char* default_port) { /* Get name from args. */ - const char *path = args->uri->path; + const char* path = args->uri->path; if (path[0] == '/') ++path; /* Create resolver. */ - ares_dns_resolver *r = - (ares_dns_resolver *)gpr_zalloc(sizeof(ares_dns_resolver)); + ares_dns_resolver* r = + (ares_dns_resolver*)gpr_zalloc(sizeof(ares_dns_resolver)); grpc_resolver_init(&r->base, &dns_ares_resolver_vtable, args->combiner); if (0 != strcmp(args->uri->authority, "")) { r->dns_server = gpr_strdup(args->uri->authority); @@ -371,7 +371,7 @@ static grpc_resolver *dns_ares_create(grpc_exec_ctx *exec_ctx, r->name_to_resolve = gpr_strdup(path); r->default_port = gpr_strdup(default_port); r->channel_args = grpc_channel_args_copy(args->args); - const grpc_arg *arg = grpc_channel_args_find( + const grpc_arg* arg = grpc_channel_args_find( r->channel_args, GRPC_ARG_SERVICE_CONFIG_DISABLE_RESOLUTION); r->request_service_config = !grpc_channel_arg_get_integer( arg, (grpc_integer_options){false, false, true}); @@ -398,19 +398,19 @@ static grpc_resolver *dns_ares_create(grpc_exec_ctx *exec_ctx, * FACTORY */ -static void dns_ares_factory_ref(grpc_resolver_factory *factory) {} +static void dns_ares_factory_ref(grpc_resolver_factory* factory) {} -static void dns_ares_factory_unref(grpc_resolver_factory *factory) {} +static void dns_ares_factory_unref(grpc_resolver_factory* factory) {} -static grpc_resolver *dns_factory_create_resolver( - grpc_exec_ctx *exec_ctx, grpc_resolver_factory *factory, - grpc_resolver_args *args) { +static grpc_resolver* dns_factory_create_resolver( + grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, + grpc_resolver_args* args) { return dns_ares_create(exec_ctx, args, "https"); } -static char *dns_ares_factory_get_default_host_name( - grpc_resolver_factory *factory, grpc_uri *uri) { - const char *path = uri->path; +static char* dns_ares_factory_get_default_host_name( + grpc_resolver_factory* factory, grpc_uri* uri) { + const char* path = uri->path; if (path[0] == '/') ++path; return gpr_strdup(path); } @@ -420,16 +420,16 @@ static const grpc_resolver_factory_vtable dns_ares_factory_vtable = { dns_ares_factory_get_default_host_name, "dns"}; static grpc_resolver_factory dns_resolver_factory = {&dns_ares_factory_vtable}; -static grpc_resolver_factory *dns_ares_resolver_factory_create() { +static grpc_resolver_factory* dns_ares_resolver_factory_create() { return &dns_resolver_factory; } extern "C" void grpc_resolver_dns_ares_init(void) { - char *resolver = gpr_getenv("GRPC_DNS_RESOLVER"); + char* resolver = gpr_getenv("GRPC_DNS_RESOLVER"); /* TODO(zyc): Turn on c-ares based resolver by default after the address sorter and the CNAME support are added. */ if (resolver != NULL && gpr_stricmp(resolver, "ares") == 0) { - grpc_error *error = grpc_ares_init(); + grpc_error* error = grpc_ares_init(); if (error != GRPC_ERROR_NONE) { GRPC_LOG_IF_ERROR("ares_library_init() failed", error); return; @@ -441,7 +441,7 @@ extern "C" void grpc_resolver_dns_ares_init(void) { } extern "C" void grpc_resolver_dns_ares_shutdown(void) { - char *resolver = gpr_getenv("GRPC_DNS_RESOLVER"); + char* resolver = gpr_getenv("GRPC_DNS_RESOLVER"); if (resolver != NULL && gpr_stricmp(resolver, "ares") == 0) { grpc_ares_cleanup(); } diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h index 3d4309f2fa..a5fb1f10e1 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h @@ -31,31 +31,31 @@ typedef struct grpc_ares_ev_driver grpc_ares_ev_driver; /* Start \a ev_driver. It will keep working until all IO on its ares_channel is done, or grpc_ares_ev_driver_destroy() is called. It may notify the callbacks bound to its ares_channel when necessary. */ -void grpc_ares_ev_driver_start(grpc_exec_ctx *exec_ctx, - grpc_ares_ev_driver *ev_driver); +void grpc_ares_ev_driver_start(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver); /* Returns the ares_channel owned by \a ev_driver. To bind a c-ares query to \a ev_driver, use the ares_channel owned by \a ev_driver as the arg of the query. */ -ares_channel *grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver *ev_driver); +ares_channel* grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver* ev_driver); /* Creates a new grpc_ares_ev_driver. Returns GRPC_ERROR_NONE if \a ev_driver is created successfully. */ -grpc_error *grpc_ares_ev_driver_create(grpc_ares_ev_driver **ev_driver, - grpc_pollset_set *pollset_set); +grpc_error* grpc_ares_ev_driver_create(grpc_ares_ev_driver** ev_driver, + grpc_pollset_set* pollset_set); /* Destroys \a ev_driver asynchronously. Pending lookups made on \a ev_driver will be cancelled and their on_done callbacks will be invoked with a status of ARES_ECANCELLED. */ -void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver *ev_driver); +void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver* ev_driver); /* Shutdown all the grpc_fds used by \a ev_driver */ -void grpc_ares_ev_driver_shutdown(grpc_exec_ctx *exec_ctx, - grpc_ares_ev_driver *ev_driver); +void grpc_ares_ev_driver_shutdown(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver); #ifdef __cplusplus } #endif #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H \ - */ + */ diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc index c30cc93b6f..2bb98c1a3f 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc @@ -37,7 +37,7 @@ typedef struct fd_node { /** the owner of this fd node */ - grpc_ares_ev_driver *ev_driver; + grpc_ares_ev_driver* ev_driver; /** a closure wrapping on_readable_cb, which should be invoked when the grpc_fd in this node becomes readable. */ grpc_closure read_closure; @@ -45,12 +45,12 @@ typedef struct fd_node { grpc_fd in this node becomes writable. */ grpc_closure write_closure; /** next fd node in the list */ - struct fd_node *next; + struct fd_node* next; /** mutex guarding the rest of the state */ gpr_mu mu; /** the grpc_fd owned by this fd node */ - grpc_fd *fd; + grpc_fd* fd; /** if the readable closure has been registered */ bool readable_registered; /** if the writable closure has been registered */ @@ -63,31 +63,31 @@ struct grpc_ares_ev_driver { /** the ares_channel owned by this event driver */ ares_channel channel; /** pollset set for driving the IO events of the channel */ - grpc_pollset_set *pollset_set; + grpc_pollset_set* pollset_set; /** refcount of the event driver */ gpr_refcount refs; /** mutex guarding the rest of the state */ gpr_mu mu; /** a list of grpc_fd that this event driver is currently using. */ - fd_node *fds; + fd_node* fds; /** is this event driver currently working? */ bool working; /** is this event driver being shut down */ bool shutting_down; }; -static void grpc_ares_notify_on_event_locked(grpc_exec_ctx *exec_ctx, - grpc_ares_ev_driver *ev_driver); +static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver); -static grpc_ares_ev_driver *grpc_ares_ev_driver_ref( - grpc_ares_ev_driver *ev_driver) { +static grpc_ares_ev_driver* grpc_ares_ev_driver_ref( + grpc_ares_ev_driver* ev_driver) { gpr_log(GPR_DEBUG, "Ref ev_driver %" PRIuPTR, (uintptr_t)ev_driver); gpr_ref(&ev_driver->refs); return ev_driver; } -static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver *ev_driver) { +static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver* ev_driver) { gpr_log(GPR_DEBUG, "Unref ev_driver %" PRIuPTR, (uintptr_t)ev_driver); if (gpr_unref(&ev_driver->refs)) { gpr_log(GPR_DEBUG, "destroy ev_driver %" PRIuPTR, (uintptr_t)ev_driver); @@ -98,7 +98,7 @@ static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver *ev_driver) { } } -static void fd_node_destroy(grpc_exec_ctx *exec_ctx, fd_node *fdn) { +static void fd_node_destroy(grpc_exec_ctx* exec_ctx, fd_node* fdn) { gpr_log(GPR_DEBUG, "delete fd: %d", grpc_fd_wrapped_fd(fdn->fd)); GPR_ASSERT(!fdn->readable_registered); GPR_ASSERT(!fdn->writable_registered); @@ -111,29 +111,30 @@ static void fd_node_destroy(grpc_exec_ctx *exec_ctx, fd_node *fdn) { gpr_free(fdn); } -static void fd_node_shutdown(grpc_exec_ctx *exec_ctx, fd_node *fdn) { +static void fd_node_shutdown(grpc_exec_ctx* exec_ctx, fd_node* fdn) { gpr_mu_lock(&fdn->mu); fdn->shutting_down = true; if (!fdn->readable_registered && !fdn->writable_registered) { gpr_mu_unlock(&fdn->mu); fd_node_destroy(exec_ctx, fdn); } else { - grpc_fd_shutdown(exec_ctx, fdn->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "c-ares fd shutdown")); + grpc_fd_shutdown( + exec_ctx, fdn->fd, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("c-ares fd shutdown")); gpr_mu_unlock(&fdn->mu); } } -grpc_error *grpc_ares_ev_driver_create(grpc_ares_ev_driver **ev_driver, - grpc_pollset_set *pollset_set) { - *ev_driver = (grpc_ares_ev_driver *)gpr_malloc(sizeof(grpc_ares_ev_driver)); +grpc_error* grpc_ares_ev_driver_create(grpc_ares_ev_driver** ev_driver, + grpc_pollset_set* pollset_set) { + *ev_driver = (grpc_ares_ev_driver*)gpr_malloc(sizeof(grpc_ares_ev_driver)); int status = ares_init(&(*ev_driver)->channel); gpr_log(GPR_DEBUG, "grpc_ares_ev_driver_create"); if (status != ARES_SUCCESS) { - char *err_msg; + char* err_msg; gpr_asprintf(&err_msg, "Failed to init ares channel. C-ares error: %s", ares_strerror(status)); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(err_msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(err_msg); gpr_free(err_msg); gpr_free(*ev_driver); return err; @@ -147,7 +148,7 @@ grpc_error *grpc_ares_ev_driver_create(grpc_ares_ev_driver **ev_driver, return GRPC_ERROR_NONE; } -void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver *ev_driver) { +void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver* ev_driver) { // It's not safe to shut down remaining fds here directly, becauses // ares_host_callback does not provide an exec_ctx. We mark the event driver // as being shut down. If the event driver is working, @@ -159,14 +160,15 @@ void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver *ev_driver) { grpc_ares_ev_driver_unref(ev_driver); } -void grpc_ares_ev_driver_shutdown(grpc_exec_ctx *exec_ctx, - grpc_ares_ev_driver *ev_driver) { +void grpc_ares_ev_driver_shutdown(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver) { gpr_mu_lock(&ev_driver->mu); ev_driver->shutting_down = true; - fd_node *fn = ev_driver->fds; + fd_node* fn = ev_driver->fds; while (fn != NULL) { - grpc_fd_shutdown(exec_ctx, fn->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "grpc_ares_ev_driver_shutdown")); + grpc_fd_shutdown( + exec_ctx, fn->fd, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("grpc_ares_ev_driver_shutdown")); fn = fn->next; } gpr_mu_unlock(&ev_driver->mu); @@ -174,13 +176,13 @@ void grpc_ares_ev_driver_shutdown(grpc_exec_ctx *exec_ctx, // Search fd in the fd_node list head. This is an O(n) search, the max possible // value of n is ARES_GETSOCK_MAXNUM (16). n is typically 1 - 2 in our tests. -static fd_node *pop_fd_node(fd_node **head, int fd) { +static fd_node* pop_fd_node(fd_node** head, int fd) { fd_node dummy_head; dummy_head.next = *head; - fd_node *node = &dummy_head; + fd_node* node = &dummy_head; while (node->next != NULL) { if (grpc_fd_wrapped_fd(node->next->fd) == fd) { - fd_node *ret = node->next; + fd_node* ret = node->next; node->next = node->next->next; *head = dummy_head.next; return ret; @@ -191,16 +193,16 @@ static fd_node *pop_fd_node(fd_node **head, int fd) { } /* Check if \a fd is still readable */ -static bool grpc_ares_is_fd_still_readable(grpc_ares_ev_driver *ev_driver, +static bool grpc_ares_is_fd_still_readable(grpc_ares_ev_driver* ev_driver, int fd) { size_t bytes_available = 0; return ioctl(fd, FIONREAD, &bytes_available) == 0 && bytes_available > 0; } -static void on_readable_cb(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - fd_node *fdn = (fd_node *)arg; - grpc_ares_ev_driver *ev_driver = fdn->ev_driver; +static void on_readable_cb(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + fd_node* fdn = (fd_node*)arg; + grpc_ares_ev_driver* ev_driver = fdn->ev_driver; gpr_mu_lock(&fdn->mu); const int fd = grpc_fd_wrapped_fd(fdn->fd); fdn->readable_registered = false; @@ -232,10 +234,10 @@ static void on_readable_cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_ares_ev_driver_unref(ev_driver); } -static void on_writable_cb(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - fd_node *fdn = (fd_node *)arg; - grpc_ares_ev_driver *ev_driver = fdn->ev_driver; +static void on_writable_cb(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + fd_node* fdn = (fd_node*)arg; + grpc_ares_ev_driver* ev_driver = fdn->ev_driver; gpr_mu_lock(&fdn->mu); const int fd = grpc_fd_wrapped_fd(fdn->fd); fdn->writable_registered = false; @@ -265,15 +267,15 @@ static void on_writable_cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_ares_ev_driver_unref(ev_driver); } -ares_channel *grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver *ev_driver) { +ares_channel* grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver* ev_driver) { return &ev_driver->channel; } // Get the file descriptors used by the ev_driver's ares channel, register // driver_closure with these filedescriptors. -static void grpc_ares_notify_on_event_locked(grpc_exec_ctx *exec_ctx, - grpc_ares_ev_driver *ev_driver) { - fd_node *new_list = NULL; +static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver) { + fd_node* new_list = NULL; if (!ev_driver->shutting_down) { ares_socket_t socks[ARES_GETSOCK_MAXNUM]; int socks_bitmask = @@ -281,12 +283,12 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx *exec_ctx, for (size_t i = 0; i < ARES_GETSOCK_MAXNUM; i++) { if (ARES_GETSOCK_READABLE(socks_bitmask, i) || ARES_GETSOCK_WRITABLE(socks_bitmask, i)) { - fd_node *fdn = pop_fd_node(&ev_driver->fds, socks[i]); + fd_node* fdn = pop_fd_node(&ev_driver->fds, socks[i]); // Create a new fd_node if sock[i] is not in the fd_node list. if (fdn == NULL) { - char *fd_name; + char* fd_name; gpr_asprintf(&fd_name, "ares_ev_driver-%" PRIuPTR, i); - fdn = (fd_node *)gpr_malloc(sizeof(fd_node)); + fdn = (fd_node*)gpr_malloc(sizeof(fd_node)); gpr_log(GPR_DEBUG, "new fd: %d", socks[i]); fdn->fd = grpc_fd_create(socks[i], fd_name); fdn->ev_driver = ev_driver; @@ -331,7 +333,7 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx *exec_ctx, // are therefore no longer in use, so they can be shut down and removed from // the list. while (ev_driver->fds != NULL) { - fd_node *cur = ev_driver->fds; + fd_node* cur = ev_driver->fds; ev_driver->fds = ev_driver->fds->next; fd_node_shutdown(exec_ctx, cur); } @@ -343,8 +345,8 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx *exec_ctx, } } -void grpc_ares_ev_driver_start(grpc_exec_ctx *exec_ctx, - grpc_ares_ev_driver *ev_driver) { +void grpc_ares_ev_driver_start(grpc_exec_ctx* exec_ctx, + grpc_ares_ev_driver* ev_driver) { gpr_mu_lock(&ev_driver->mu); if (!ev_driver->working) { ev_driver->working = true; diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc index 04379975e1..9408b9d81d 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -51,13 +51,13 @@ struct grpc_ares_request { struct ares_addr_port_node dns_server_addr; /** following members are set in grpc_resolve_address_ares_impl */ /** closure to call when the request completes */ - grpc_closure *on_done; + grpc_closure* on_done; /** the pointer to receive the resolved addresses */ - grpc_lb_addresses **lb_addrs_out; + grpc_lb_addresses** lb_addrs_out; /** the pointer to receive the service config in JSON */ - char **service_config_json_out; + char** service_config_json_out; /** the evernt driver used by this request */ - grpc_ares_ev_driver *ev_driver; + grpc_ares_ev_driver* ev_driver; /** number of ongoing queries */ gpr_refcount pending_queries; @@ -66,15 +66,15 @@ struct grpc_ares_request { /** is there at least one successful query, set in on_done_cb */ bool success; /** the errors explaining the request failure, set in on_done_cb */ - grpc_error *error; + grpc_error* error; }; typedef struct grpc_ares_hostbyname_request { /** following members are set in create_hostbyname_request */ /** the top-level request instance */ - grpc_ares_request *parent_request; + grpc_ares_request* parent_request; /** host to resolve, parsed from the name to resolve */ - char *host; + char* host; /** port to fill in sockaddr_in, parsed from the name to resolve */ uint16_t port; /** is it a grpclb address */ @@ -83,7 +83,7 @@ typedef struct grpc_ares_hostbyname_request { static void do_basic_init(void) { gpr_mu_init(&g_init_mu); } -static uint16_t strhtons(const char *port) { +static uint16_t strhtons(const char* port) { if (strcmp(port, "http") == 0) { return htons(80); } else if (strcmp(port, "https") == 0) { @@ -92,12 +92,12 @@ static uint16_t strhtons(const char *port) { return htons((unsigned short)atoi(port)); } -static void grpc_ares_request_ref(grpc_ares_request *r) { +static void grpc_ares_request_ref(grpc_ares_request* r) { gpr_ref(&r->pending_queries); } -static void grpc_ares_request_unref(grpc_exec_ctx *exec_ctx, - grpc_ares_request *r) { +static void grpc_ares_request_unref(grpc_exec_ctx* exec_ctx, + grpc_ares_request* r) { /* If there are no pending queries, invoke on_done callback and destroy the request */ if (gpr_unref(&r->pending_queries)) { @@ -120,10 +120,10 @@ static void grpc_ares_request_unref(grpc_exec_ctx *exec_ctx, } } -static grpc_ares_hostbyname_request *create_hostbyname_request( - grpc_ares_request *parent_request, char *host, uint16_t port, +static grpc_ares_hostbyname_request* create_hostbyname_request( + grpc_ares_request* parent_request, char* host, uint16_t port, bool is_balancer) { - grpc_ares_hostbyname_request *hr = (grpc_ares_hostbyname_request *)gpr_zalloc( + grpc_ares_hostbyname_request* hr = (grpc_ares_hostbyname_request*)gpr_zalloc( sizeof(grpc_ares_hostbyname_request)); hr->parent_request = parent_request; hr->host = gpr_strdup(host); @@ -133,23 +133,23 @@ static grpc_ares_hostbyname_request *create_hostbyname_request( return hr; } -static void destroy_hostbyname_request(grpc_exec_ctx *exec_ctx, - grpc_ares_hostbyname_request *hr) { +static void destroy_hostbyname_request(grpc_exec_ctx* exec_ctx, + grpc_ares_hostbyname_request* hr) { grpc_ares_request_unref(exec_ctx, hr->parent_request); gpr_free(hr->host); gpr_free(hr); } -static void on_hostbyname_done_cb(void *arg, int status, int timeouts, - struct hostent *hostent) { - grpc_ares_hostbyname_request *hr = (grpc_ares_hostbyname_request *)arg; - grpc_ares_request *r = hr->parent_request; +static void on_hostbyname_done_cb(void* arg, int status, int timeouts, + struct hostent* hostent) { + grpc_ares_hostbyname_request* hr = (grpc_ares_hostbyname_request*)arg; + grpc_ares_request* r = hr->parent_request; gpr_mu_lock(&r->mu); if (status == ARES_SUCCESS) { GRPC_ERROR_UNREF(r->error); r->error = GRPC_ERROR_NONE; r->success = true; - grpc_lb_addresses **lb_addresses = r->lb_addrs_out; + grpc_lb_addresses** lb_addresses = r->lb_addrs_out; if (*lb_addresses == NULL) { *lb_addresses = grpc_lb_addresses_create(0, NULL); } @@ -158,7 +158,7 @@ static void on_hostbyname_done_cb(void *arg, int status, int timeouts, for (i = 0; hostent->h_addr_list[i] != NULL; i++) { } (*lb_addresses)->num_addresses += i; - (*lb_addresses)->addresses = (grpc_lb_address *)gpr_realloc( + (*lb_addresses)->addresses = (grpc_lb_address*)gpr_realloc( (*lb_addresses)->addresses, sizeof(grpc_lb_address) * (*lb_addresses)->num_addresses); for (i = prev_naddr; i < (*lb_addresses)->num_addresses; i++) { @@ -208,10 +208,10 @@ static void on_hostbyname_done_cb(void *arg, int status, int timeouts, } } } else if (!r->success) { - char *error_msg; + char* error_msg; gpr_asprintf(&error_msg, "C-ares status is not ARES_SUCCESS: %s", ares_strerror(status)); - grpc_error *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg); + grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg); gpr_free(error_msg); if (r->error == GRPC_ERROR_NONE) { r->error = error; @@ -223,26 +223,26 @@ static void on_hostbyname_done_cb(void *arg, int status, int timeouts, destroy_hostbyname_request(NULL, hr); } -static void on_srv_query_done_cb(void *arg, int status, int timeouts, - unsigned char *abuf, int alen) { - grpc_ares_request *r = (grpc_ares_request *)arg; +static void on_srv_query_done_cb(void* arg, int status, int timeouts, + unsigned char* abuf, int alen) { + grpc_ares_request* r = (grpc_ares_request*)arg; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_log(GPR_DEBUG, "on_query_srv_done_cb"); if (status == ARES_SUCCESS) { gpr_log(GPR_DEBUG, "on_query_srv_done_cb ARES_SUCCESS"); - struct ares_srv_reply *reply; + struct ares_srv_reply* reply; const int parse_status = ares_parse_srv_reply(abuf, alen, &reply); if (parse_status == ARES_SUCCESS) { - ares_channel *channel = grpc_ares_ev_driver_get_channel(r->ev_driver); - for (struct ares_srv_reply *srv_it = reply; srv_it != NULL; + ares_channel* channel = grpc_ares_ev_driver_get_channel(r->ev_driver); + for (struct ares_srv_reply* srv_it = reply; srv_it != NULL; srv_it = srv_it->next) { if (grpc_ipv6_loopback_available()) { - grpc_ares_hostbyname_request *hr = create_hostbyname_request( + grpc_ares_hostbyname_request* hr = create_hostbyname_request( r, srv_it->host, htons(srv_it->port), true /* is_balancer */); ares_gethostbyname(*channel, hr->host, AF_INET6, on_hostbyname_done_cb, hr); } - grpc_ares_hostbyname_request *hr = create_hostbyname_request( + grpc_ares_hostbyname_request* hr = create_hostbyname_request( r, srv_it->host, htons(srv_it->port), true /* is_balancer */); ares_gethostbyname(*channel, hr->host, AF_INET, on_hostbyname_done_cb, hr); @@ -253,10 +253,10 @@ static void on_srv_query_done_cb(void *arg, int status, int timeouts, ares_free_data(reply); } } else if (!r->success) { - char *error_msg; + char* error_msg; gpr_asprintf(&error_msg, "C-ares status is not ARES_SUCCESS: %s", ares_strerror(status)); - grpc_error *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg); + grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg); gpr_free(error_msg); if (r->error == GRPC_ERROR_NONE) { r->error = error; @@ -270,15 +270,15 @@ static void on_srv_query_done_cb(void *arg, int status, int timeouts, static const char g_service_config_attribute_prefix[] = "grpc_config="; -static void on_txt_done_cb(void *arg, int status, int timeouts, - unsigned char *buf, int len) { +static void on_txt_done_cb(void* arg, int status, int timeouts, + unsigned char* buf, int len) { gpr_log(GPR_DEBUG, "on_txt_done_cb"); - char *error_msg; - grpc_ares_request *r = (grpc_ares_request *)arg; + char* error_msg; + grpc_ares_request* r = (grpc_ares_request*)arg; const size_t prefix_len = sizeof(g_service_config_attribute_prefix) - 1; - struct ares_txt_ext *result = NULL; - struct ares_txt_ext *reply = NULL; - grpc_error *error = GRPC_ERROR_NONE; + struct ares_txt_ext* result = NULL; + struct ares_txt_ext* reply = NULL; + grpc_error* error = GRPC_ERROR_NONE; gpr_mu_lock(&r->mu); if (status != ARES_SUCCESS) goto fail; status = ares_parse_txt_reply_ext(buf, len, &reply); @@ -294,12 +294,12 @@ static void on_txt_done_cb(void *arg, int status, int timeouts, // Found a service config record. if (result != NULL) { size_t service_config_len = result->length - prefix_len; - *r->service_config_json_out = (char *)gpr_malloc(service_config_len + 1); + *r->service_config_json_out = (char*)gpr_malloc(service_config_len + 1); memcpy(*r->service_config_json_out, result->txt + prefix_len, service_config_len); for (result = result->next; result != NULL && !result->record_start; result = result->next) { - *r->service_config_json_out = (char *)gpr_realloc( + *r->service_config_json_out = (char*)gpr_realloc( *r->service_config_json_out, service_config_len + result->length + 1); memcpy(*r->service_config_json_out + service_config_len, result->txt, result->length); @@ -326,15 +326,15 @@ done: grpc_ares_request_unref(NULL, r); } -static grpc_ares_request *grpc_dns_lookup_ares_impl( - grpc_exec_ctx *exec_ctx, const char *dns_server, const char *name, - const char *default_port, grpc_pollset_set *interested_parties, - grpc_closure *on_done, grpc_lb_addresses **addrs, bool check_grpclb, - char **service_config_json) { - grpc_error *error = GRPC_ERROR_NONE; - grpc_ares_hostbyname_request *hr = NULL; - grpc_ares_request *r = NULL; - ares_channel *channel = NULL; +static grpc_ares_request* grpc_dns_lookup_ares_impl( + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, + char** service_config_json) { + grpc_error* error = GRPC_ERROR_NONE; + grpc_ares_hostbyname_request* hr = NULL; + grpc_ares_request* r = NULL; + ares_channel* channel = NULL; /* TODO(zyc): Enable tracing after #9603 is checked in */ /* if (grpc_dns_trace) { gpr_log(GPR_DEBUG, "resolve_address (blocking): name=%s, default_port=%s", @@ -342,8 +342,8 @@ static grpc_ares_request *grpc_dns_lookup_ares_impl( } */ /* parse name, splitting it into host and port parts */ - char *host; - char *port; + char* host; + char* port; gpr_split_host_port(name, &host, &port); if (host == NULL) { error = grpc_error_set_str( @@ -360,11 +360,11 @@ static grpc_ares_request *grpc_dns_lookup_ares_impl( port = gpr_strdup(default_port); } - grpc_ares_ev_driver *ev_driver; + grpc_ares_ev_driver* ev_driver; error = grpc_ares_ev_driver_create(&ev_driver, interested_parties); if (error != GRPC_ERROR_NONE) goto error_cleanup; - r = (grpc_ares_request *)gpr_zalloc(sizeof(grpc_ares_request)); + r = (grpc_ares_request*)gpr_zalloc(sizeof(grpc_ares_request)); gpr_mu_init(&r->mu); r->ev_driver = ev_driver; r->on_done = on_done; @@ -380,7 +380,7 @@ static grpc_ares_request *grpc_dns_lookup_ares_impl( grpc_resolved_address addr; if (grpc_parse_ipv4_hostport(dns_server, &addr, false /* log_errors */)) { r->dns_server_addr.family = AF_INET; - struct sockaddr_in *in = (struct sockaddr_in *)addr.addr; + struct sockaddr_in* in = (struct sockaddr_in*)addr.addr; memcpy(&r->dns_server_addr.addr.addr4, &in->sin_addr, sizeof(struct in_addr)); r->dns_server_addr.tcp_port = grpc_sockaddr_get_port(&addr); @@ -388,7 +388,7 @@ static grpc_ares_request *grpc_dns_lookup_ares_impl( } else if (grpc_parse_ipv6_hostport(dns_server, &addr, false /* log_errors */)) { r->dns_server_addr.family = AF_INET6; - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr.addr; + struct sockaddr_in6* in6 = (struct sockaddr_in6*)addr.addr; memcpy(&r->dns_server_addr.addr.addr6, &in6->sin6_addr, sizeof(struct in6_addr)); r->dns_server_addr.tcp_port = grpc_sockaddr_get_port(&addr); @@ -402,7 +402,7 @@ static grpc_ares_request *grpc_dns_lookup_ares_impl( } int status = ares_set_servers_ports(*channel, &r->dns_server_addr); if (status != ARES_SUCCESS) { - char *error_msg; + char* error_msg; gpr_asprintf(&error_msg, "C-ares status is not ARES_SUCCESS: %s", ares_strerror(status)); error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg); @@ -423,7 +423,7 @@ static grpc_ares_request *grpc_dns_lookup_ares_impl( if (check_grpclb) { /* Query the SRV record */ grpc_ares_request_ref(r); - char *service_name; + char* service_name; gpr_asprintf(&service_name, "_grpclb._tcp.%s", host); ares_query(*channel, service_name, ns_c_in, ns_t_srv, on_srv_query_done_cb, r); @@ -447,29 +447,29 @@ error_cleanup: return NULL; } -grpc_ares_request *(*grpc_dns_lookup_ares)( - grpc_exec_ctx *exec_ctx, const char *dns_server, const char *name, - const char *default_port, grpc_pollset_set *interested_parties, - grpc_closure *on_done, grpc_lb_addresses **addrs, bool check_grpclb, - char **service_config_json) = grpc_dns_lookup_ares_impl; +grpc_ares_request* (*grpc_dns_lookup_ares)( + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, + char** service_config_json) = grpc_dns_lookup_ares_impl; -void grpc_cancel_ares_request(grpc_exec_ctx *exec_ctx, grpc_ares_request *r) { +void grpc_cancel_ares_request(grpc_exec_ctx* exec_ctx, grpc_ares_request* r) { if (grpc_dns_lookup_ares == grpc_dns_lookup_ares_impl) { grpc_ares_ev_driver_shutdown(exec_ctx, r->ev_driver); } } -grpc_error *grpc_ares_init(void) { +grpc_error* grpc_ares_init(void) { gpr_once_init(&g_basic_init, do_basic_init); gpr_mu_lock(&g_init_mu); int status = ares_library_init(ARES_LIB_INIT_ALL); gpr_mu_unlock(&g_init_mu); if (status != ARES_SUCCESS) { - char *error_msg; + char* error_msg; gpr_asprintf(&error_msg, "ares_library_init failed: %s", ares_strerror(status)); - grpc_error *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg); + grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg); gpr_free(error_msg); return error; } @@ -488,28 +488,28 @@ void grpc_ares_cleanup(void) { typedef struct grpc_resolve_address_ares_request { /** the pointer to receive the resolved addresses */ - grpc_resolved_addresses **addrs_out; + grpc_resolved_addresses** addrs_out; /** currently resolving lb addresses */ - grpc_lb_addresses *lb_addrs; + grpc_lb_addresses* lb_addrs; /** closure to call when the resolve_address_ares request completes */ - grpc_closure *on_resolve_address_done; + grpc_closure* on_resolve_address_done; /** a closure wrapping on_dns_lookup_done_cb, which should be invoked when the grpc_dns_lookup_ares operation is done. */ grpc_closure on_dns_lookup_done; } grpc_resolve_address_ares_request; -static void on_dns_lookup_done_cb(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_resolve_address_ares_request *r = - (grpc_resolve_address_ares_request *)arg; - grpc_resolved_addresses **resolved_addresses = r->addrs_out; +static void on_dns_lookup_done_cb(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_resolve_address_ares_request* r = + (grpc_resolve_address_ares_request*)arg; + grpc_resolved_addresses** resolved_addresses = r->addrs_out; if (r->lb_addrs == NULL || r->lb_addrs->num_addresses == 0) { *resolved_addresses = NULL; } else { *resolved_addresses = - (grpc_resolved_addresses *)gpr_zalloc(sizeof(grpc_resolved_addresses)); + (grpc_resolved_addresses*)gpr_zalloc(sizeof(grpc_resolved_addresses)); (*resolved_addresses)->naddrs = r->lb_addrs->num_addresses; - (*resolved_addresses)->addrs = (grpc_resolved_address *)gpr_zalloc( + (*resolved_addresses)->addrs = (grpc_resolved_address*)gpr_zalloc( sizeof(grpc_resolved_address) * (*resolved_addresses)->naddrs); for (size_t i = 0; i < (*resolved_addresses)->naddrs; i++) { GPR_ASSERT(!r->lb_addrs->addresses[i].is_balancer); @@ -523,14 +523,14 @@ static void on_dns_lookup_done_cb(grpc_exec_ctx *exec_ctx, void *arg, gpr_free(r); } -static void grpc_resolve_address_ares_impl(grpc_exec_ctx *exec_ctx, - const char *name, - const char *default_port, - grpc_pollset_set *interested_parties, - grpc_closure *on_done, - grpc_resolved_addresses **addrs) { - grpc_resolve_address_ares_request *r = - (grpc_resolve_address_ares_request *)gpr_zalloc( +static void grpc_resolve_address_ares_impl(grpc_exec_ctx* exec_ctx, + const char* name, + const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addrs) { + grpc_resolve_address_ares_request* r = + (grpc_resolve_address_ares_request*)gpr_zalloc( sizeof(grpc_resolve_address_ares_request)); r->addrs_out = addrs; r->on_resolve_address_done = on_done; @@ -543,8 +543,8 @@ static void grpc_resolve_address_ares_impl(grpc_exec_ctx *exec_ctx, } void (*grpc_resolve_address_ares)( - grpc_exec_ctx *exec_ctx, const char *name, const char *default_port, - grpc_pollset_set *interested_parties, grpc_closure *on_done, - grpc_resolved_addresses **addrs) = grpc_resolve_address_ares_impl; + grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_resolved_addresses** addrs) = grpc_resolve_address_ares_impl; #endif /* GRPC_ARES == 1 && !defined(GRPC_UV) */ diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h index 38fbea9aac..6882b7b1d1 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h @@ -36,12 +36,12 @@ typedef struct grpc_ares_request grpc_ares_request; must be called at least once before this function. \a on_done may be called directly in this function without being scheduled with \a exec_ctx, so it must not try to acquire locks that are being held by the caller. */ -extern void (*grpc_resolve_address_ares)(grpc_exec_ctx *exec_ctx, - const char *name, - const char *default_port, - grpc_pollset_set *interested_parties, - grpc_closure *on_done, - grpc_resolved_addresses **addresses); +extern void (*grpc_resolve_address_ares)(grpc_exec_ctx* exec_ctx, + const char* name, + const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addresses); /* Asynchronously resolve \a name. It will try to resolve grpclb SRV records in addition to the normal address records. For normal address records, it uses @@ -50,19 +50,19 @@ extern void (*grpc_resolve_address_ares)(grpc_exec_ctx *exec_ctx, function. \a on_done may be called directly in this function without being scheduled with \a exec_ctx, so it must not try to acquire locks that are being held by the caller. */ -extern grpc_ares_request *(*grpc_dns_lookup_ares)( - grpc_exec_ctx *exec_ctx, const char *dns_server, const char *name, - const char *default_port, grpc_pollset_set *interested_parties, - grpc_closure *on_done, grpc_lb_addresses **addresses, bool check_grpclb, - char **service_config_json); +extern grpc_ares_request* (*grpc_dns_lookup_ares)( + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** addresses, bool check_grpclb, + char** service_config_json); /* Cancel the pending grpc_ares_request \a request */ -void grpc_cancel_ares_request(grpc_exec_ctx *exec_ctx, - grpc_ares_request *request); +void grpc_cancel_ares_request(grpc_exec_ctx* exec_ctx, + grpc_ares_request* request); /* Initialize gRPC ares wrapper. Must be called at least once before grpc_resolve_address_ares(). */ -grpc_error *grpc_ares_init(void); +grpc_error* grpc_ares_init(void); /* Uninitialized gRPC ares wrapper. If there was more than one previous call to grpc_ares_init(), this function uninitializes the gRPC ares wrapper only if @@ -74,4 +74,4 @@ void grpc_ares_cleanup(void); #endif #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H \ - */ + */ diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc index f2587c4520..a68a7c47fb 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc @@ -25,36 +25,36 @@ struct grpc_ares_request { char val; }; -static grpc_ares_request *grpc_dns_lookup_ares_impl( - grpc_exec_ctx *exec_ctx, const char *dns_server, const char *name, - const char *default_port, grpc_pollset_set *interested_parties, - grpc_closure *on_done, grpc_lb_addresses **addrs, bool check_grpclb, - char **service_config_json) { +static grpc_ares_request* grpc_dns_lookup_ares_impl( + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, + char** service_config_json) { return NULL; } -grpc_ares_request *(*grpc_dns_lookup_ares)( - grpc_exec_ctx *exec_ctx, const char *dns_server, const char *name, - const char *default_port, grpc_pollset_set *interested_parties, - grpc_closure *on_done, grpc_lb_addresses **addrs, bool check_grpclb, - char **service_config_json) = grpc_dns_lookup_ares_impl; +grpc_ares_request* (*grpc_dns_lookup_ares)( + grpc_exec_ctx* exec_ctx, const char* dns_server, const char* name, + const char* default_port, grpc_pollset_set* interested_parties, + grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, + char** service_config_json) = grpc_dns_lookup_ares_impl; -void grpc_cancel_ares_request(grpc_exec_ctx *exec_ctx, grpc_ares_request *r) {} +void grpc_cancel_ares_request(grpc_exec_ctx* exec_ctx, grpc_ares_request* r) {} -grpc_error *grpc_ares_init(void) { return GRPC_ERROR_NONE; } +grpc_error* grpc_ares_init(void) { return GRPC_ERROR_NONE; } void grpc_ares_cleanup(void) {} -static void grpc_resolve_address_ares_impl(grpc_exec_ctx *exec_ctx, - const char *name, - const char *default_port, - grpc_pollset_set *interested_parties, - grpc_closure *on_done, - grpc_resolved_addresses **addrs) {} +static void grpc_resolve_address_ares_impl(grpc_exec_ctx* exec_ctx, + const char* name, + const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addrs) {} void (*grpc_resolve_address_ares)( - grpc_exec_ctx *exec_ctx, const char *name, const char *default_port, - grpc_pollset_set *interested_parties, grpc_closure *on_done, - grpc_resolved_addresses **addrs) = grpc_resolve_address_ares_impl; + grpc_exec_ctx* exec_ctx, const char* name, const char* default_port, + grpc_pollset_set* interested_parties, grpc_closure* on_done, + grpc_resolved_addresses** addrs) = grpc_resolve_address_ares_impl; #endif /* GRPC_ARES != 1 || defined(GRPC_UV) */ diff --git a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc index 62aead5517..a57ab66118 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc @@ -45,13 +45,13 @@ typedef struct { /** base class: must be first */ grpc_resolver base; /** name to resolve */ - char *name_to_resolve; + char* name_to_resolve; /** default port to use */ - char *default_port; + char* default_port; /** channel args. */ - grpc_channel_args *channel_args; + grpc_channel_args* channel_args; /** pollset_set to drive the name resolution process */ - grpc_pollset_set *interested_parties; + grpc_pollset_set* interested_parties; /** are we currently resolving? */ bool resolving; @@ -60,11 +60,11 @@ typedef struct { /** which version of the result is current? */ int resolved_version; /** pending next completion, or NULL */ - grpc_closure *next_completion; + grpc_closure* next_completion; /** target result address for next completion */ - grpc_channel_args **target_result; + grpc_channel_args** target_result; /** current (fully resolved) result */ - grpc_channel_args *resolved_result; + grpc_channel_args* resolved_result; /** retry timer */ bool have_retry_timer; grpc_timer retry_timer; @@ -73,30 +73,30 @@ typedef struct { grpc_backoff backoff_state; /** currently resolving addresses */ - grpc_resolved_addresses *addresses; + grpc_resolved_addresses* addresses; } dns_resolver; -static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *r); +static void dns_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* r); -static void dns_start_resolving_locked(grpc_exec_ctx *exec_ctx, - dns_resolver *r); -static void dns_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, - dns_resolver *r); +static void dns_start_resolving_locked(grpc_exec_ctx* exec_ctx, + dns_resolver* r); +static void dns_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + dns_resolver* r); -static void dns_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *r); -static void dns_channel_saw_error_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *r); -static void dns_next_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *r, - grpc_channel_args **target_result, - grpc_closure *on_complete); +static void dns_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r); +static void dns_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* r); +static void dns_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r, + grpc_channel_args** target_result, + grpc_closure* on_complete); static const grpc_resolver_vtable dns_resolver_vtable = { dns_destroy, dns_shutdown_locked, dns_channel_saw_error_locked, dns_next_locked}; -static void dns_shutdown_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver) { - dns_resolver *r = (dns_resolver *)resolver; +static void dns_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { + dns_resolver* r = (dns_resolver*)resolver; if (r->have_retry_timer) { grpc_timer_cancel(exec_ctx, &r->retry_timer); } @@ -109,19 +109,19 @@ static void dns_shutdown_locked(grpc_exec_ctx *exec_ctx, } } -static void dns_channel_saw_error_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver) { - dns_resolver *r = (dns_resolver *)resolver; +static void dns_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { + dns_resolver* r = (dns_resolver*)resolver; if (!r->resolving) { grpc_backoff_reset(&r->backoff_state); dns_start_resolving_locked(exec_ctx, r); } } -static void dns_next_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_channel_args **target_result, - grpc_closure *on_complete) { - dns_resolver *r = (dns_resolver *)resolver; +static void dns_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, + grpc_channel_args** target_result, + grpc_closure* on_complete) { + dns_resolver* r = (dns_resolver*)resolver; GPR_ASSERT(!r->next_completion); r->next_completion = on_complete; r->target_result = target_result; @@ -133,9 +133,9 @@ static void dns_next_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, } } -static void dns_on_retry_timer_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - dns_resolver *r = (dns_resolver *)arg; +static void dns_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + dns_resolver* r = (dns_resolver*)arg; r->have_retry_timer = false; if (error == GRPC_ERROR_NONE) { @@ -147,17 +147,17 @@ static void dns_on_retry_timer_locked(grpc_exec_ctx *exec_ctx, void *arg, GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "retry-timer"); } -static void dns_on_resolved_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - dns_resolver *r = (dns_resolver *)arg; - grpc_channel_args *result = NULL; +static void dns_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + dns_resolver* r = (dns_resolver*)arg; + grpc_channel_args* result = NULL; GPR_ASSERT(r->resolving); r->resolving = false; GRPC_ERROR_REF(error); error = grpc_error_set_str(error, GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(r->name_to_resolve)); if (r->addresses != NULL) { - grpc_lb_addresses *addresses = grpc_lb_addresses_create( + grpc_lb_addresses* addresses = grpc_lb_addresses_create( r->addresses->naddrs, NULL /* user_data_vtable */); for (size_t i = 0; i < r->addresses->naddrs; ++i) { grpc_lb_addresses_set_address( @@ -198,8 +198,8 @@ static void dns_on_resolved_locked(grpc_exec_ctx *exec_ctx, void *arg, GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "dns-resolving"); } -static void dns_start_resolving_locked(grpc_exec_ctx *exec_ctx, - dns_resolver *r) { +static void dns_start_resolving_locked(grpc_exec_ctx* exec_ctx, + dns_resolver* r) { GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GPR_ASSERT(!r->resolving); r->resolving = true; @@ -211,8 +211,8 @@ static void dns_start_resolving_locked(grpc_exec_ctx *exec_ctx, &r->addresses); } -static void dns_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, - dns_resolver *r) { +static void dns_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + dns_resolver* r) { if (r->next_completion != NULL && r->resolved_version != r->published_version) { *r->target_result = r->resolved_result == NULL @@ -224,8 +224,8 @@ static void dns_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, } } -static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { - dns_resolver *r = (dns_resolver *)gr; +static void dns_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { + dns_resolver* r = (dns_resolver*)gr; if (r->resolved_result != NULL) { grpc_channel_args_destroy(exec_ctx, r->resolved_result); } @@ -236,18 +236,18 @@ static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { gpr_free(r); } -static grpc_resolver *dns_create(grpc_exec_ctx *exec_ctx, - grpc_resolver_args *args, - const char *default_port) { +static grpc_resolver* dns_create(grpc_exec_ctx* exec_ctx, + grpc_resolver_args* args, + const char* default_port) { if (0 != strcmp(args->uri->authority, "")) { gpr_log(GPR_ERROR, "authority based dns uri's not supported"); return NULL; } // Get name from args. - char *path = args->uri->path; + char* path = args->uri->path; if (path[0] == '/') ++path; // Create resolver. - dns_resolver *r = (dns_resolver *)gpr_zalloc(sizeof(dns_resolver)); + dns_resolver* r = (dns_resolver*)gpr_zalloc(sizeof(dns_resolver)); grpc_resolver_init(&r->base, &dns_resolver_vtable, args->combiner); r->name_to_resolve = gpr_strdup(path); r->default_port = gpr_strdup(default_port); @@ -269,19 +269,19 @@ static grpc_resolver *dns_create(grpc_exec_ctx *exec_ctx, * FACTORY */ -static void dns_factory_ref(grpc_resolver_factory *factory) {} +static void dns_factory_ref(grpc_resolver_factory* factory) {} -static void dns_factory_unref(grpc_resolver_factory *factory) {} +static void dns_factory_unref(grpc_resolver_factory* factory) {} -static grpc_resolver *dns_factory_create_resolver( - grpc_exec_ctx *exec_ctx, grpc_resolver_factory *factory, - grpc_resolver_args *args) { +static grpc_resolver* dns_factory_create_resolver( + grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, + grpc_resolver_args* args) { return dns_create(exec_ctx, args, "https"); } -static char *dns_factory_get_default_host_name(grpc_resolver_factory *factory, - grpc_uri *uri) { - const char *path = uri->path; +static char* dns_factory_get_default_host_name(grpc_resolver_factory* factory, + grpc_uri* uri) { + const char* path = uri->path; if (path[0] == '/') ++path; return gpr_strdup(path); } @@ -291,17 +291,17 @@ static const grpc_resolver_factory_vtable dns_factory_vtable = { dns_factory_get_default_host_name, "dns"}; static grpc_resolver_factory dns_resolver_factory = {&dns_factory_vtable}; -static grpc_resolver_factory *dns_resolver_factory_create() { +static grpc_resolver_factory* dns_resolver_factory_create() { return &dns_resolver_factory; } extern "C" void grpc_resolver_dns_native_init(void) { - char *resolver = gpr_getenv("GRPC_DNS_RESOLVER"); + char* resolver = gpr_getenv("GRPC_DNS_RESOLVER"); if (resolver != NULL && gpr_stricmp(resolver, "native") == 0) { gpr_log(GPR_DEBUG, "Using native dns resolver"); grpc_register_resolver_type(dns_resolver_factory_create()); } else { - grpc_resolver_factory *existing_factory = + grpc_resolver_factory* existing_factory = grpc_resolver_factory_lookup("dns"); if (existing_factory == NULL) { gpr_log(GPR_DEBUG, "Using native dns resolver"); diff --git a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h index 95c3bafed8..3f341fa8ed 100644 --- a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +++ b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h @@ -65,4 +65,4 @@ void grpc_fake_resolver_response_generator_unref( #endif #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_FAKE_FAKE_RESOLVER_H \ - */ + */ diff --git a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc index dda9542325..9fc8dffea3 100644 --- a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc @@ -41,36 +41,36 @@ typedef struct { /** base class: must be first */ grpc_resolver base; /** the addresses that we've 'resolved' */ - grpc_lb_addresses *addresses; + grpc_lb_addresses* addresses; /** channel args */ - grpc_channel_args *channel_args; + grpc_channel_args* channel_args; /** have we published? */ bool published; /** pending next completion, or NULL */ - grpc_closure *next_completion; + grpc_closure* next_completion; /** target result address for next completion */ - grpc_channel_args **target_result; + grpc_channel_args** target_result; } sockaddr_resolver; -static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *r); +static void sockaddr_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* r); -static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, - sockaddr_resolver *r); +static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + sockaddr_resolver* r); -static void sockaddr_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *r); -static void sockaddr_channel_saw_error_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *r); -static void sockaddr_next_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *r, - grpc_channel_args **target_result, - grpc_closure *on_complete); +static void sockaddr_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r); +static void sockaddr_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* r); +static void sockaddr_next_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* r, + grpc_channel_args** target_result, + grpc_closure* on_complete); static const grpc_resolver_vtable sockaddr_resolver_vtable = { sockaddr_destroy, sockaddr_shutdown_locked, sockaddr_channel_saw_error_locked, sockaddr_next_locked}; -static void sockaddr_shutdown_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver) { - sockaddr_resolver *r = (sockaddr_resolver *)resolver; +static void sockaddr_shutdown_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { + sockaddr_resolver* r = (sockaddr_resolver*)resolver; if (r->next_completion != NULL) { *r->target_result = NULL; GRPC_CLOSURE_SCHED( @@ -80,26 +80,26 @@ static void sockaddr_shutdown_locked(grpc_exec_ctx *exec_ctx, } } -static void sockaddr_channel_saw_error_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver) { - sockaddr_resolver *r = (sockaddr_resolver *)resolver; +static void sockaddr_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver) { + sockaddr_resolver* r = (sockaddr_resolver*)resolver; r->published = false; sockaddr_maybe_finish_next_locked(exec_ctx, r); } -static void sockaddr_next_locked(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver, - grpc_channel_args **target_result, - grpc_closure *on_complete) { - sockaddr_resolver *r = (sockaddr_resolver *)resolver; +static void sockaddr_next_locked(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver, + grpc_channel_args** target_result, + grpc_closure* on_complete) { + sockaddr_resolver* r = (sockaddr_resolver*)resolver; GPR_ASSERT(!r->next_completion); r->next_completion = on_complete; r->target_result = target_result; sockaddr_maybe_finish_next_locked(exec_ctx, r); } -static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, - sockaddr_resolver *r) { +static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, + sockaddr_resolver* r) { if (r->next_completion != NULL && !r->published) { r->published = true; grpc_arg arg = grpc_lb_addresses_create_channel_arg(r->addresses); @@ -110,42 +110,42 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, } } -static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { - sockaddr_resolver *r = (sockaddr_resolver *)gr; +static void sockaddr_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { + sockaddr_resolver* r = (sockaddr_resolver*)gr; grpc_lb_addresses_destroy(exec_ctx, r->addresses); grpc_channel_args_destroy(exec_ctx, r->channel_args); gpr_free(r); } -static char *ip_get_default_authority(grpc_uri *uri) { - const char *path = uri->path; +static char* ip_get_default_authority(grpc_uri* uri) { + const char* path = uri->path; if (path[0] == '/') ++path; return gpr_strdup(path); } -static char *ipv4_get_default_authority(grpc_resolver_factory *factory, - grpc_uri *uri) { +static char* ipv4_get_default_authority(grpc_resolver_factory* factory, + grpc_uri* uri) { return ip_get_default_authority(uri); } -static char *ipv6_get_default_authority(grpc_resolver_factory *factory, - grpc_uri *uri) { +static char* ipv6_get_default_authority(grpc_resolver_factory* factory, + grpc_uri* uri) { return ip_get_default_authority(uri); } #ifdef GRPC_HAVE_UNIX_SOCKET -char *unix_get_default_authority(grpc_resolver_factory *factory, - grpc_uri *uri) { +char* unix_get_default_authority(grpc_resolver_factory* factory, + grpc_uri* uri) { return gpr_strdup("localhost"); } #endif -static void do_nothing(void *ignored) {} +static void do_nothing(void* ignored) {} -static grpc_resolver *sockaddr_create(grpc_exec_ctx *exec_ctx, - grpc_resolver_args *args, - bool parse(const grpc_uri *uri, - grpc_resolved_address *dst)) { +static grpc_resolver* sockaddr_create(grpc_exec_ctx* exec_ctx, + grpc_resolver_args* args, + bool parse(const grpc_uri* uri, + grpc_resolved_address* dst)) { if (0 != strcmp(args->uri->authority, "")) { gpr_log(GPR_ERROR, "authority based uri's not supported by the %s scheme", args->uri->scheme); @@ -157,12 +157,12 @@ static grpc_resolver *sockaddr_create(grpc_exec_ctx *exec_ctx, grpc_slice_buffer path_parts; grpc_slice_buffer_init(&path_parts); grpc_slice_split(path_slice, ",", &path_parts); - grpc_lb_addresses *addresses = + grpc_lb_addresses* addresses = grpc_lb_addresses_create(path_parts.count, NULL /* user_data_vtable */); bool errors_found = false; for (size_t i = 0; i < addresses->num_addresses; i++) { grpc_uri ith_uri = *args->uri; - char *part_str = grpc_slice_to_c_string(path_parts.slices[i]); + char* part_str = grpc_slice_to_c_string(path_parts.slices[i]); ith_uri.path = part_str; if (!parse(&ith_uri, &addresses->addresses[i].address)) { errors_found = true; /* GPR_TRUE */ @@ -177,8 +177,8 @@ static grpc_resolver *sockaddr_create(grpc_exec_ctx *exec_ctx, return NULL; } /* Instantiate resolver. */ - sockaddr_resolver *r = - (sockaddr_resolver *)gpr_zalloc(sizeof(sockaddr_resolver)); + sockaddr_resolver* r = + (sockaddr_resolver*)gpr_zalloc(sizeof(sockaddr_resolver)); r->addresses = addresses; r->channel_args = grpc_channel_args_copy(args->args); grpc_resolver_init(&r->base, &sockaddr_resolver_vtable, args->combiner); @@ -189,14 +189,14 @@ static grpc_resolver *sockaddr_create(grpc_exec_ctx *exec_ctx, * FACTORY */ -static void sockaddr_factory_ref(grpc_resolver_factory *factory) {} +static void sockaddr_factory_ref(grpc_resolver_factory* factory) {} -static void sockaddr_factory_unref(grpc_resolver_factory *factory) {} +static void sockaddr_factory_unref(grpc_resolver_factory* factory) {} #define DECL_FACTORY(name) \ - static grpc_resolver *name##_factory_create_resolver( \ - grpc_exec_ctx *exec_ctx, grpc_resolver_factory *factory, \ - grpc_resolver_args *args) { \ + static grpc_resolver* name##_factory_create_resolver( \ + grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, \ + grpc_resolver_args* args) { \ return sockaddr_create(exec_ctx, args, grpc_parse_##name); \ } \ static const grpc_resolver_factory_vtable name##_factory_vtable = { \ diff --git a/src/core/ext/filters/client_channel/resolver_factory.h b/src/core/ext/filters/client_channel/resolver_factory.h index c8b2c58db3..62555a4f01 100644 --- a/src/core/ext/filters/client_channel/resolver_factory.h +++ b/src/core/ext/filters/client_channel/resolver_factory.h @@ -32,44 +32,44 @@ typedef struct grpc_resolver_factory grpc_resolver_factory; typedef struct grpc_resolver_factory_vtable grpc_resolver_factory_vtable; struct grpc_resolver_factory { - const grpc_resolver_factory_vtable *vtable; + const grpc_resolver_factory_vtable* vtable; }; typedef struct grpc_resolver_args { - grpc_uri *uri; - const grpc_channel_args *args; - grpc_pollset_set *pollset_set; - grpc_combiner *combiner; + grpc_uri* uri; + const grpc_channel_args* args; + grpc_pollset_set* pollset_set; + grpc_combiner* combiner; } grpc_resolver_args; struct grpc_resolver_factory_vtable { - void (*ref)(grpc_resolver_factory *factory); - void (*unref)(grpc_resolver_factory *factory); + void (*ref)(grpc_resolver_factory* factory); + void (*unref)(grpc_resolver_factory* factory); /** Implementation of grpc_resolver_factory_create_resolver */ - grpc_resolver *(*create_resolver)(grpc_exec_ctx *exec_ctx, - grpc_resolver_factory *factory, - grpc_resolver_args *args); + grpc_resolver* (*create_resolver)(grpc_exec_ctx* exec_ctx, + grpc_resolver_factory* factory, + grpc_resolver_args* args); /** Implementation of grpc_resolver_factory_get_default_authority */ - char *(*get_default_authority)(grpc_resolver_factory *factory, grpc_uri *uri); + char* (*get_default_authority)(grpc_resolver_factory* factory, grpc_uri* uri); /** URI scheme that this factory implements */ - const char *scheme; + const char* scheme; }; -void grpc_resolver_factory_ref(grpc_resolver_factory *resolver); -void grpc_resolver_factory_unref(grpc_resolver_factory *resolver); +void grpc_resolver_factory_ref(grpc_resolver_factory* resolver); +void grpc_resolver_factory_unref(grpc_resolver_factory* resolver); /** Create a resolver instance for a name */ -grpc_resolver *grpc_resolver_factory_create_resolver( - grpc_exec_ctx *exec_ctx, grpc_resolver_factory *factory, - grpc_resolver_args *args); +grpc_resolver* grpc_resolver_factory_create_resolver( + grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, + grpc_resolver_args* args); /** Return a (freshly allocated with gpr_malloc) string representing the default authority to use for this scheme. */ -char *grpc_resolver_factory_get_default_authority( - grpc_resolver_factory *factory, grpc_uri *uri); +char* grpc_resolver_factory_get_default_authority( + grpc_resolver_factory* factory, grpc_uri* uri); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/resolver_registry.cc b/src/core/ext/filters/client_channel/resolver_registry.cc index 1a0fb0bc3c..9e45887f35 100644 --- a/src/core/ext/filters/client_channel/resolver_registry.cc +++ b/src/core/ext/filters/client_channel/resolver_registry.cc @@ -27,7 +27,7 @@ #define MAX_RESOLVERS 10 #define DEFAULT_RESOLVER_PREFIX_MAX_LENGTH 32 -static grpc_resolver_factory *g_all_of_the_resolvers[MAX_RESOLVERS]; +static grpc_resolver_factory* g_all_of_the_resolvers[MAX_RESOLVERS]; static int g_number_of_resolvers = 0; static char g_default_resolver_prefix[DEFAULT_RESOLVER_PREFIX_MAX_LENGTH] = @@ -49,7 +49,7 @@ void grpc_resolver_registry_shutdown(void) { } void grpc_resolver_registry_set_default_prefix( - const char *default_resolver_prefix) { + const char* default_resolver_prefix) { const size_t len = strlen(default_resolver_prefix); GPR_ASSERT(len < DEFAULT_RESOLVER_PREFIX_MAX_LENGTH && "default resolver prefix too long"); @@ -59,7 +59,7 @@ void grpc_resolver_registry_set_default_prefix( strcpy(g_default_resolver_prefix, default_resolver_prefix); } -void grpc_register_resolver_type(grpc_resolver_factory *factory) { +void grpc_register_resolver_type(grpc_resolver_factory* factory) { int i; for (i = 0; i < g_number_of_resolvers; i++) { GPR_ASSERT(0 != strcmp(factory->vtable->scheme, @@ -70,7 +70,7 @@ void grpc_register_resolver_type(grpc_resolver_factory *factory) { g_all_of_the_resolvers[g_number_of_resolvers++] = factory; } -static grpc_resolver_factory *lookup_factory(const char *name) { +static grpc_resolver_factory* lookup_factory(const char* name) { int i; for (i = 0; i < g_number_of_resolvers; i++) { @@ -81,22 +81,22 @@ static grpc_resolver_factory *lookup_factory(const char *name) { return NULL; } -grpc_resolver_factory *grpc_resolver_factory_lookup(const char *name) { - grpc_resolver_factory *f = lookup_factory(name); +grpc_resolver_factory* grpc_resolver_factory_lookup(const char* name) { + grpc_resolver_factory* f = lookup_factory(name); if (f) grpc_resolver_factory_ref(f); return f; } -static grpc_resolver_factory *lookup_factory_by_uri(grpc_uri *uri) { +static grpc_resolver_factory* lookup_factory_by_uri(grpc_uri* uri) { if (!uri) return NULL; return lookup_factory(uri->scheme); } -static grpc_resolver_factory *resolve_factory(grpc_exec_ctx *exec_ctx, - const char *target, - grpc_uri **uri, - char **canonical_target) { - grpc_resolver_factory *factory = NULL; +static grpc_resolver_factory* resolve_factory(grpc_exec_ctx* exec_ctx, + const char* target, + grpc_uri** uri, + char** canonical_target) { + grpc_resolver_factory* factory = NULL; GPR_ASSERT(uri != NULL); *uri = grpc_uri_parse(exec_ctx, target, 1); @@ -116,15 +116,15 @@ static grpc_resolver_factory *resolve_factory(grpc_exec_ctx *exec_ctx, return factory; } -grpc_resolver *grpc_resolver_create(grpc_exec_ctx *exec_ctx, const char *target, - const grpc_channel_args *args, - grpc_pollset_set *pollset_set, - grpc_combiner *combiner) { - grpc_uri *uri = NULL; - char *canonical_target = NULL; - grpc_resolver_factory *factory = +grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target, + const grpc_channel_args* args, + grpc_pollset_set* pollset_set, + grpc_combiner* combiner) { + grpc_uri* uri = NULL; + char* canonical_target = NULL; + grpc_resolver_factory* factory = resolve_factory(exec_ctx, target, &uri, &canonical_target); - grpc_resolver *resolver; + grpc_resolver* resolver; grpc_resolver_args resolver_args; memset(&resolver_args, 0, sizeof(resolver_args)); resolver_args.uri = uri; @@ -138,21 +138,21 @@ grpc_resolver *grpc_resolver_create(grpc_exec_ctx *exec_ctx, const char *target, return resolver; } -char *grpc_get_default_authority(grpc_exec_ctx *exec_ctx, const char *target) { - grpc_uri *uri = NULL; - char *canonical_target = NULL; - grpc_resolver_factory *factory = +char* grpc_get_default_authority(grpc_exec_ctx* exec_ctx, const char* target) { + grpc_uri* uri = NULL; + char* canonical_target = NULL; + grpc_resolver_factory* factory = resolve_factory(exec_ctx, target, &uri, &canonical_target); - char *authority = grpc_resolver_factory_get_default_authority(factory, uri); + char* authority = grpc_resolver_factory_get_default_authority(factory, uri); grpc_uri_destroy(uri); gpr_free(canonical_target); return authority; } -char *grpc_resolver_factory_add_default_prefix_if_needed( - grpc_exec_ctx *exec_ctx, const char *target) { - grpc_uri *uri = NULL; - char *canonical_target = NULL; +char* grpc_resolver_factory_add_default_prefix_if_needed( + grpc_exec_ctx* exec_ctx, const char* target) { + grpc_uri* uri = NULL; + char* canonical_target = NULL; resolve_factory(exec_ctx, target, &uri, &canonical_target); grpc_uri_destroy(uri); return canonical_target == NULL ? gpr_strdup(target) : canonical_target; diff --git a/src/core/ext/filters/client_channel/resolver_registry.h b/src/core/ext/filters/client_channel/resolver_registry.h index 06d0b99a35..01a2d0b18b 100644 --- a/src/core/ext/filters/client_channel/resolver_registry.h +++ b/src/core/ext/filters/client_channel/resolver_registry.h @@ -30,14 +30,14 @@ void grpc_resolver_registry_init(); void grpc_resolver_registry_shutdown(void); /** Set the default URI prefix to \a default_prefix. */ -void grpc_resolver_registry_set_default_prefix(const char *default_prefix); +void grpc_resolver_registry_set_default_prefix(const char* default_prefix); /** Register a resolver type. URI's of \a scheme will be resolved with the given resolver. If \a priority is greater than zero, then the resolver will be eligible to resolve names that are passed in with no scheme. Higher priority resolvers will be tried before lower priority schemes. */ -void grpc_register_resolver_type(grpc_resolver_factory *factory); +void grpc_register_resolver_type(grpc_resolver_factory* factory); /** Create a resolver given \a target. First tries to parse \a target as a URI. If this succeeds, tries @@ -52,23 +52,23 @@ void grpc_register_resolver_type(grpc_resolver_factory *factory); (typically the set of arguments passed in from the client API). \a pollset_set is used to drive IO in the name resolution process, it should not be NULL. */ -grpc_resolver *grpc_resolver_create(grpc_exec_ctx *exec_ctx, const char *target, - const grpc_channel_args *args, - grpc_pollset_set *pollset_set, - grpc_combiner *combiner); +grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target, + const grpc_channel_args* args, + grpc_pollset_set* pollset_set, + grpc_combiner* combiner); /** Find a resolver factory given a name and return an (owned-by-the-caller) * reference to it */ -grpc_resolver_factory *grpc_resolver_factory_lookup(const char *name); +grpc_resolver_factory* grpc_resolver_factory_lookup(const char* name); /** Given a target, return a (freshly allocated with gpr_malloc) string representing the default authority to pass from a client. */ -char *grpc_get_default_authority(grpc_exec_ctx *exec_ctx, const char *target); +char* grpc_get_default_authority(grpc_exec_ctx* exec_ctx, const char* target); /** Returns a newly allocated string containing \a target, adding the default prefix if needed. */ -char *grpc_resolver_factory_add_default_prefix_if_needed( - grpc_exec_ctx *exec_ctx, const char *target); +char* grpc_resolver_factory_add_default_prefix_if_needed( + grpc_exec_ctx* exec_ctx, const char* target); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index b954e1b879..427df743d6 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -52,27 +52,27 @@ #define GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS 120 #define GRPC_SUBCHANNEL_RECONNECT_JITTER 0.2 -#define GET_CONNECTED_SUBCHANNEL(subchannel, barrier) \ - ((grpc_connected_subchannel *)(gpr_atm_##barrier##_load( \ +#define GET_CONNECTED_SUBCHANNEL(subchannel, barrier) \ + ((grpc_connected_subchannel*)(gpr_atm_##barrier##_load( \ &(subchannel)->connected_subchannel))) typedef struct { grpc_closure closure; - grpc_subchannel *subchannel; + grpc_subchannel* subchannel; grpc_connectivity_state connectivity_state; } state_watcher; typedef struct external_state_watcher { - grpc_subchannel *subchannel; - grpc_pollset_set *pollset_set; - grpc_closure *notify; + grpc_subchannel* subchannel; + grpc_pollset_set* pollset_set; + grpc_closure* notify; grpc_closure closure; - struct external_state_watcher *next; - struct external_state_watcher *prev; + struct external_state_watcher* next; + struct external_state_watcher* prev; } external_state_watcher; struct grpc_subchannel { - grpc_connector *connector; + grpc_connector* connector; /** refcount - lower INTERNAL_REF_BITS bits are for internal references: @@ -82,12 +82,12 @@ struct grpc_subchannel { gpr_atm ref_pair; /** non-transport related channel filters */ - const grpc_channel_filter **filters; + const grpc_channel_filter** filters; size_t num_filters; /** channel arguments */ - grpc_channel_args *args; + grpc_channel_args* args; - grpc_subchannel_key *key; + grpc_subchannel_key* key; /** set during connection */ grpc_connect_out_args connecting_result; @@ -100,7 +100,7 @@ struct grpc_subchannel { /** pollset_set tracking who's interested in a connection being setup */ - grpc_pollset_set *pollset_set; + grpc_pollset_set* pollset_set; /** active connection, or null; of type grpc_connected_subchannel */ gpr_atm connected_subchannel; @@ -130,22 +130,22 @@ struct grpc_subchannel { }; struct grpc_subchannel_call { - grpc_connected_subchannel *connection; - grpc_closure *schedule_closure_after_destroy; + grpc_connected_subchannel* connection; + grpc_closure* schedule_closure_after_destroy; }; -#define SUBCHANNEL_CALL_TO_CALL_STACK(call) ((grpc_call_stack *)((call) + 1)) -#define CHANNEL_STACK_FROM_CONNECTION(con) ((grpc_channel_stack *)(con)) +#define SUBCHANNEL_CALL_TO_CALL_STACK(call) ((grpc_call_stack*)((call) + 1)) +#define CHANNEL_STACK_FROM_CONNECTION(con) ((grpc_channel_stack*)(con)) #define CALLSTACK_TO_SUBCHANNEL_CALL(callstack) \ - (((grpc_subchannel_call *)(callstack)) - 1) + (((grpc_subchannel_call*)(callstack)) - 1) -static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *subchannel, - grpc_error *error); +static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* subchannel, + grpc_error* error); #ifndef NDEBUG #define REF_REASON reason #define REF_MUTATE_EXTRA_ARGS \ - GRPC_SUBCHANNEL_REF_EXTRA_ARGS, const char *purpose + GRPC_SUBCHANNEL_REF_EXTRA_ARGS, const char* purpose #define REF_MUTATE_PURPOSE(x) , file, line, reason, x #else #define REF_REASON "" @@ -157,21 +157,21 @@ static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *subchannel, * connection implementation */ -static void connection_destroy(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_connected_subchannel *c = (grpc_connected_subchannel *)arg; +static void connection_destroy(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_connected_subchannel* c = (grpc_connected_subchannel*)arg; grpc_channel_stack_destroy(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c)); gpr_free(c); } -grpc_connected_subchannel *grpc_connected_subchannel_ref( - grpc_connected_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { +grpc_connected_subchannel* grpc_connected_subchannel_ref( + grpc_connected_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { GRPC_CHANNEL_STACK_REF(CHANNEL_STACK_FROM_CONNECTION(c), REF_REASON); return c; } -void grpc_connected_subchannel_unref(grpc_exec_ctx *exec_ctx, - grpc_connected_subchannel *c +void grpc_connected_subchannel_unref(grpc_exec_ctx* exec_ctx, + grpc_connected_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { GRPC_CHANNEL_STACK_UNREF(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c), REF_REASON); @@ -181,10 +181,10 @@ void grpc_connected_subchannel_unref(grpc_exec_ctx *exec_ctx, * grpc_subchannel implementation */ -static void subchannel_destroy(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_subchannel *c = (grpc_subchannel *)arg; - gpr_free((void *)c->filters); +static void subchannel_destroy(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_subchannel* c = (grpc_subchannel*)arg; + gpr_free((void*)c->filters); grpc_channel_args_destroy(exec_ctx, c->args); grpc_connectivity_state_destroy(exec_ctx, &c->state_tracker); grpc_connector_unref(exec_ctx, c->connector); @@ -194,7 +194,7 @@ static void subchannel_destroy(grpc_exec_ctx *exec_ctx, void *arg, gpr_free(c); } -static gpr_atm ref_mutate(grpc_subchannel *c, gpr_atm delta, +static gpr_atm ref_mutate(grpc_subchannel* c, gpr_atm delta, int barrier REF_MUTATE_EXTRA_ARGS) { gpr_atm old_val = barrier ? gpr_atm_full_fetch_add(&c->ref_pair, delta) : gpr_atm_no_barrier_fetch_add(&c->ref_pair, delta); @@ -208,8 +208,8 @@ static gpr_atm ref_mutate(grpc_subchannel *c, gpr_atm delta, return old_val; } -grpc_subchannel *grpc_subchannel_ref( - grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { +grpc_subchannel* grpc_subchannel_ref( + grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; old_refs = ref_mutate(c, (1 << INTERNAL_REF_BITS), 0 REF_MUTATE_PURPOSE("STRONG_REF")); @@ -217,16 +217,16 @@ grpc_subchannel *grpc_subchannel_ref( return c; } -grpc_subchannel *grpc_subchannel_weak_ref( - grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { +grpc_subchannel* grpc_subchannel_weak_ref( + grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; old_refs = ref_mutate(c, 1, 0 REF_MUTATE_PURPOSE("WEAK_REF")); GPR_ASSERT(old_refs != 0); return c; } -grpc_subchannel *grpc_subchannel_ref_from_weak_ref( - grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { +grpc_subchannel* grpc_subchannel_ref_from_weak_ref( + grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { if (!c) return NULL; for (;;) { gpr_atm old_refs = gpr_atm_acq_load(&c->ref_pair); @@ -241,8 +241,8 @@ grpc_subchannel *grpc_subchannel_ref_from_weak_ref( } } -static void disconnect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) { - grpc_connected_subchannel *con; +static void disconnect(grpc_exec_ctx* exec_ctx, grpc_subchannel* c) { + grpc_connected_subchannel* con; grpc_subchannel_index_unregister(exec_ctx, c->key, c); gpr_mu_lock(&c->mu); GPR_ASSERT(!c->disconnected); @@ -258,8 +258,8 @@ static void disconnect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) { gpr_mu_unlock(&c->mu); } -void grpc_subchannel_unref(grpc_exec_ctx *exec_ctx, - grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { +void grpc_subchannel_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; // add a weak ref and subtract a strong ref (atomically) old_refs = ref_mutate(c, (gpr_atm)1 - (gpr_atm)(1 << INTERNAL_REF_BITS), @@ -270,56 +270,57 @@ void grpc_subchannel_unref(grpc_exec_ctx *exec_ctx, GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "strong-unref"); } -void grpc_subchannel_weak_unref(grpc_exec_ctx *exec_ctx, - grpc_subchannel *c +void grpc_subchannel_weak_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { gpr_atm old_refs; old_refs = ref_mutate(c, -(gpr_atm)1, 1 REF_MUTATE_PURPOSE("WEAK_UNREF")); if (old_refs == 1) { - GRPC_CLOSURE_SCHED(exec_ctx, GRPC_CLOSURE_CREATE(subchannel_destroy, c, - grpc_schedule_on_exec_ctx), - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED( + exec_ctx, + GRPC_CLOSURE_CREATE(subchannel_destroy, c, grpc_schedule_on_exec_ctx), + GRPC_ERROR_NONE); } } -grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, - grpc_connector *connector, - const grpc_subchannel_args *args) { - grpc_subchannel_key *key = grpc_subchannel_key_create(args); - grpc_subchannel *c = grpc_subchannel_index_find(exec_ctx, key); +grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx, + grpc_connector* connector, + const grpc_subchannel_args* args) { + grpc_subchannel_key* key = grpc_subchannel_key_create(args); + grpc_subchannel* c = grpc_subchannel_index_find(exec_ctx, key); if (c) { grpc_subchannel_key_destroy(exec_ctx, key); return c; } GRPC_STATS_INC_CLIENT_SUBCHANNELS_CREATED(exec_ctx); - c = (grpc_subchannel *)gpr_zalloc(sizeof(*c)); + c = (grpc_subchannel*)gpr_zalloc(sizeof(*c)); c->key = key; gpr_atm_no_barrier_store(&c->ref_pair, 1 << INTERNAL_REF_BITS); c->connector = connector; grpc_connector_ref(c->connector); c->num_filters = args->filter_count; if (c->num_filters > 0) { - c->filters = (const grpc_channel_filter **)gpr_malloc( - sizeof(grpc_channel_filter *) * c->num_filters); - memcpy((void *)c->filters, args->filters, - sizeof(grpc_channel_filter *) * c->num_filters); + c->filters = (const grpc_channel_filter**)gpr_malloc( + sizeof(grpc_channel_filter*) * c->num_filters); + memcpy((void*)c->filters, args->filters, + sizeof(grpc_channel_filter*) * c->num_filters); } else { c->filters = NULL; } c->pollset_set = grpc_pollset_set_create(); - grpc_resolved_address *addr = - (grpc_resolved_address *)gpr_malloc(sizeof(*addr)); + grpc_resolved_address* addr = + (grpc_resolved_address*)gpr_malloc(sizeof(*addr)); grpc_get_subchannel_address_arg(exec_ctx, args->args, addr); - grpc_resolved_address *new_address = NULL; - grpc_channel_args *new_args = NULL; + grpc_resolved_address* new_address = NULL; + grpc_channel_args* new_args = NULL; if (grpc_proxy_mappers_map_address(exec_ctx, addr, args->args, &new_address, &new_args)) { GPR_ASSERT(new_address != NULL); gpr_free(addr); addr = new_address; } - static const char *keys_to_remove[] = {GRPC_ARG_SUBCHANNEL_ADDRESS}; + static const char* keys_to_remove[] = {GRPC_ARG_SUBCHANNEL_ADDRESS}; grpc_arg new_arg = grpc_create_subchannel_address_arg(addr); gpr_free(addr); c->args = grpc_channel_args_copy_and_add_and_remove( @@ -375,8 +376,8 @@ grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, return grpc_subchannel_index_register(exec_ctx, key, c); } -static void continue_connect_locked(grpc_exec_ctx *exec_ctx, - grpc_subchannel *c) { +static void continue_connect_locked(grpc_exec_ctx* exec_ctx, + grpc_subchannel* c) { grpc_connect_in_args args; args.interested_parties = c->pollset_set; @@ -390,8 +391,8 @@ static void continue_connect_locked(grpc_exec_ctx *exec_ctx, &c->connected); } -grpc_connectivity_state grpc_subchannel_check_connectivity(grpc_subchannel *c, - grpc_error **error) { +grpc_connectivity_state grpc_subchannel_check_connectivity(grpc_subchannel* c, + grpc_error** error) { grpc_connectivity_state state; gpr_mu_lock(&c->mu); state = grpc_connectivity_state_get(&c->state_tracker, error); @@ -399,10 +400,10 @@ grpc_connectivity_state grpc_subchannel_check_connectivity(grpc_subchannel *c, return state; } -static void on_external_state_watcher_done(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - external_state_watcher *w = (external_state_watcher *)arg; - grpc_closure *follow_up = w->notify; +static void on_external_state_watcher_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + external_state_watcher* w = (external_state_watcher*)arg; + grpc_closure* follow_up = w->notify; if (w->pollset_set != NULL) { grpc_pollset_set_del_pollset_set(exec_ctx, w->subchannel->pollset_set, w->pollset_set); @@ -416,8 +417,8 @@ static void on_external_state_watcher_done(grpc_exec_ctx *exec_ctx, void *arg, GRPC_CLOSURE_RUN(exec_ctx, follow_up, GRPC_ERROR_REF(error)); } -static void on_alarm(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - grpc_subchannel *c = (grpc_subchannel *)arg; +static void on_alarm(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + grpc_subchannel* c = (grpc_subchannel*)arg; gpr_mu_lock(&c->mu); c->have_alarm = false; if (c->disconnected) { @@ -438,8 +439,8 @@ static void on_alarm(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { GRPC_ERROR_UNREF(error); } -static void maybe_start_connecting_locked(grpc_exec_ctx *exec_ctx, - grpc_subchannel *c) { +static void maybe_start_connecting_locked(grpc_exec_ctx* exec_ctx, + grpc_subchannel* c) { if (c->disconnected) { /* Don't try to connect if we're already disconnected */ return; @@ -484,10 +485,10 @@ static void maybe_start_connecting_locked(grpc_exec_ctx *exec_ctx, } void grpc_subchannel_notify_on_state_change( - grpc_exec_ctx *exec_ctx, grpc_subchannel *c, - grpc_pollset_set *interested_parties, grpc_connectivity_state *state, - grpc_closure *notify) { - external_state_watcher *w; + grpc_exec_ctx* exec_ctx, grpc_subchannel* c, + grpc_pollset_set* interested_parties, grpc_connectivity_state* state, + grpc_closure* notify) { + external_state_watcher* w; if (state == NULL) { gpr_mu_lock(&c->mu); @@ -500,7 +501,7 @@ void grpc_subchannel_notify_on_state_change( } gpr_mu_unlock(&c->mu); } else { - w = (external_state_watcher *)gpr_malloc(sizeof(*w)); + w = (external_state_watcher*)gpr_malloc(sizeof(*w)); w->subchannel = c; w->pollset_set = interested_parties; w->notify = notify; @@ -523,18 +524,18 @@ void grpc_subchannel_notify_on_state_change( } void grpc_connected_subchannel_process_transport_op( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, - grpc_transport_op *op) { - grpc_channel_stack *channel_stack = CHANNEL_STACK_FROM_CONNECTION(con); - grpc_channel_element *top_elem = grpc_channel_stack_element(channel_stack, 0); + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con, + grpc_transport_op* op) { + grpc_channel_stack* channel_stack = CHANNEL_STACK_FROM_CONNECTION(con); + grpc_channel_element* top_elem = grpc_channel_stack_element(channel_stack, 0); top_elem->filter->start_transport_op(exec_ctx, top_elem, op); } -static void subchannel_on_child_state_changed(grpc_exec_ctx *exec_ctx, void *p, - grpc_error *error) { - state_watcher *sw = (state_watcher *)p; - grpc_subchannel *c = sw->subchannel; - gpr_mu *mu = &c->mu; +static void subchannel_on_child_state_changed(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { + state_watcher* sw = (state_watcher*)p; + grpc_subchannel* c = sw->subchannel; + gpr_mu* mu = &c->mu; gpr_mu_lock(mu); @@ -559,13 +560,13 @@ static void subchannel_on_child_state_changed(grpc_exec_ctx *exec_ctx, void *p, gpr_free(sw); } -static void connected_subchannel_state_op(grpc_exec_ctx *exec_ctx, - grpc_connected_subchannel *con, - grpc_pollset_set *interested_parties, - grpc_connectivity_state *state, - grpc_closure *closure) { - grpc_transport_op *op = grpc_make_transport_op(NULL); - grpc_channel_element *elem; +static void connected_subchannel_state_op(grpc_exec_ctx* exec_ctx, + grpc_connected_subchannel* con, + grpc_pollset_set* interested_parties, + grpc_connectivity_state* state, + grpc_closure* closure) { + grpc_transport_op* op = grpc_make_transport_op(NULL); + grpc_channel_element* elem; op->connectivity_state = state; op->on_connectivity_state_change = closure; op->bind_pollset_set = interested_parties; @@ -574,31 +575,31 @@ static void connected_subchannel_state_op(grpc_exec_ctx *exec_ctx, } void grpc_connected_subchannel_notify_on_state_change( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, - grpc_pollset_set *interested_parties, grpc_connectivity_state *state, - grpc_closure *closure) { + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con, + grpc_pollset_set* interested_parties, grpc_connectivity_state* state, + grpc_closure* closure) { connected_subchannel_state_op(exec_ctx, con, interested_parties, state, closure); } -void grpc_connected_subchannel_ping(grpc_exec_ctx *exec_ctx, - grpc_connected_subchannel *con, - grpc_closure *closure) { - grpc_transport_op *op = grpc_make_transport_op(NULL); - grpc_channel_element *elem; +void grpc_connected_subchannel_ping(grpc_exec_ctx* exec_ctx, + grpc_connected_subchannel* con, + grpc_closure* closure) { + grpc_transport_op* op = grpc_make_transport_op(NULL); + grpc_channel_element* elem; op->send_ping = closure; elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); elem->filter->start_transport_op(exec_ctx, elem, op); } -static bool publish_transport_locked(grpc_exec_ctx *exec_ctx, - grpc_subchannel *c) { - grpc_connected_subchannel *con; - grpc_channel_stack *stk; - state_watcher *sw_subchannel; +static bool publish_transport_locked(grpc_exec_ctx* exec_ctx, + grpc_subchannel* c) { + grpc_connected_subchannel* con; + grpc_channel_stack* stk; + state_watcher* sw_subchannel; /* construct channel stack */ - grpc_channel_stack_builder *builder = grpc_channel_stack_builder_create(); + grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); grpc_channel_stack_builder_set_channel_arguments( exec_ctx, builder, c->connecting_result.channel_args); grpc_channel_stack_builder_set_transport(builder, @@ -609,8 +610,8 @@ static bool publish_transport_locked(grpc_exec_ctx *exec_ctx, grpc_channel_stack_builder_destroy(exec_ctx, builder); return false; } - grpc_error *error = grpc_channel_stack_builder_finish( - exec_ctx, builder, 0, 1, connection_destroy, NULL, (void **)&con); + grpc_error* error = grpc_channel_stack_builder_finish( + exec_ctx, builder, 0, 1, connection_destroy, NULL, (void**)&con); if (error != GRPC_ERROR_NONE) { grpc_transport_destroy(exec_ctx, c->connecting_result.transport); gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", @@ -622,7 +623,7 @@ static bool publish_transport_locked(grpc_exec_ctx *exec_ctx, memset(&c->connecting_result, 0, sizeof(c->connecting_result)); /* initialize state watcher */ - sw_subchannel = (state_watcher *)gpr_malloc(sizeof(*sw_subchannel)); + sw_subchannel = (state_watcher*)gpr_malloc(sizeof(*sw_subchannel)); sw_subchannel->subchannel = c; sw_subchannel->connectivity_state = GRPC_CHANNEL_READY; GRPC_CLOSURE_INIT(&sw_subchannel->closure, subchannel_on_child_state_changed, @@ -657,10 +658,10 @@ static bool publish_transport_locked(grpc_exec_ctx *exec_ctx, return true; } -static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_subchannel *c = (grpc_subchannel *)arg; - grpc_channel_args *delete_channel_args = c->connecting_result.channel_args; +static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_subchannel* c = (grpc_subchannel*)arg; + grpc_channel_args* delete_channel_args = c->connecting_result.channel_args; GRPC_SUBCHANNEL_WEAK_REF(c, "connected"); gpr_mu_lock(&c->mu); @@ -678,7 +679,7 @@ static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE), "connect_failed"); - const char *errmsg = grpc_error_string(error); + const char* errmsg = grpc_error_string(error); gpr_log(GPR_INFO, "Connect failed: %s", errmsg); maybe_start_connecting_locked(exec_ctx, c); @@ -693,65 +694,65 @@ static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, * grpc_subchannel_call implementation */ -static void subchannel_call_destroy(grpc_exec_ctx *exec_ctx, void *call, - grpc_error *error) { - grpc_subchannel_call *c = (grpc_subchannel_call *)call; +static void subchannel_call_destroy(grpc_exec_ctx* exec_ctx, void* call, + grpc_error* error) { + grpc_subchannel_call* c = (grpc_subchannel_call*)call; GPR_ASSERT(c->schedule_closure_after_destroy != NULL); GPR_TIMER_BEGIN("grpc_subchannel_call_unref.destroy", 0); - grpc_connected_subchannel *connection = c->connection; + grpc_connected_subchannel* connection = c->connection; grpc_call_stack_destroy(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), NULL, c->schedule_closure_after_destroy); GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, connection, "subchannel_call"); GPR_TIMER_END("grpc_subchannel_call_unref.destroy", 0); } -void grpc_subchannel_call_set_cleanup_closure(grpc_subchannel_call *call, - grpc_closure *closure) { +void grpc_subchannel_call_set_cleanup_closure(grpc_subchannel_call* call, + grpc_closure* closure) { GPR_ASSERT(call->schedule_closure_after_destroy == NULL); GPR_ASSERT(closure != NULL); call->schedule_closure_after_destroy = closure; } void grpc_subchannel_call_ref( - grpc_subchannel_call *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { + grpc_subchannel_call* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { GRPC_CALL_STACK_REF(SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); } -void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, - grpc_subchannel_call *c +void grpc_subchannel_call_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel_call* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { GRPC_CALL_STACK_UNREF(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); } -void grpc_subchannel_call_process_op(grpc_exec_ctx *exec_ctx, - grpc_subchannel_call *call, - grpc_transport_stream_op_batch *batch) { +void grpc_subchannel_call_process_op(grpc_exec_ctx* exec_ctx, + grpc_subchannel_call* call, + grpc_transport_stream_op_batch* batch) { GPR_TIMER_BEGIN("grpc_subchannel_call_process_op", 0); - grpc_call_stack *call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call); - grpc_call_element *top_elem = grpc_call_stack_element(call_stack, 0); + grpc_call_stack* call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call); + grpc_call_element* top_elem = grpc_call_stack_element(call_stack, 0); GRPC_CALL_LOG_OP(GPR_INFO, top_elem, batch); top_elem->filter->start_transport_stream_op_batch(exec_ctx, top_elem, batch); GPR_TIMER_END("grpc_subchannel_call_process_op", 0); } -grpc_connected_subchannel *grpc_subchannel_get_connected_subchannel( - grpc_subchannel *c) { +grpc_connected_subchannel* grpc_subchannel_get_connected_subchannel( + grpc_subchannel* c) { return GET_CONNECTED_SUBCHANNEL(c, acq); } -const grpc_subchannel_key *grpc_subchannel_get_key( - const grpc_subchannel *subchannel) { +const grpc_subchannel_key* grpc_subchannel_get_key( + const grpc_subchannel* subchannel) { return subchannel->key; } -grpc_error *grpc_connected_subchannel_create_call( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, - const grpc_connected_subchannel_call_args *args, - grpc_subchannel_call **call) { - grpc_channel_stack *chanstk = CHANNEL_STACK_FROM_CONNECTION(con); - *call = (grpc_subchannel_call *)gpr_arena_alloc( +grpc_error* grpc_connected_subchannel_create_call( + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con, + const grpc_connected_subchannel_call_args* args, + grpc_subchannel_call** call) { + grpc_channel_stack* chanstk = CHANNEL_STACK_FROM_CONNECTION(con); + *call = (grpc_subchannel_call*)gpr_arena_alloc( args->arena, sizeof(grpc_subchannel_call) + chanstk->call_stack_size); - grpc_call_stack *callstk = SUBCHANNEL_CALL_TO_CALL_STACK(*call); + grpc_call_stack* callstk = SUBCHANNEL_CALL_TO_CALL_STACK(*call); (*call)->connection = GRPC_CONNECTED_SUBCHANNEL_REF(con, "subchannel_call"); const grpc_call_element_args call_args = { callstk, /* call_stack */ @@ -763,10 +764,10 @@ grpc_error *grpc_connected_subchannel_create_call( args->arena, /* arena */ args->call_combiner /* call_combiner */ }; - grpc_error *error = grpc_call_stack_init( + grpc_error* error = grpc_call_stack_init( exec_ctx, chanstk, 1, subchannel_call_destroy, *call, &call_args); if (error != GRPC_ERROR_NONE) { - const char *error_string = grpc_error_string(error); + const char* error_string = grpc_error_string(error); gpr_log(GPR_ERROR, "error: %s", error_string); return error; } @@ -774,39 +775,39 @@ grpc_error *grpc_connected_subchannel_create_call( return GRPC_ERROR_NONE; } -grpc_call_stack *grpc_subchannel_call_get_call_stack( - grpc_subchannel_call *subchannel_call) { +grpc_call_stack* grpc_subchannel_call_get_call_stack( + grpc_subchannel_call* subchannel_call) { return SUBCHANNEL_CALL_TO_CALL_STACK(subchannel_call); } -static void grpc_uri_to_sockaddr(grpc_exec_ctx *exec_ctx, const char *uri_str, - grpc_resolved_address *addr) { - grpc_uri *uri = grpc_uri_parse(exec_ctx, uri_str, 0 /* suppress_errors */); +static void grpc_uri_to_sockaddr(grpc_exec_ctx* exec_ctx, const char* uri_str, + grpc_resolved_address* addr) { + grpc_uri* uri = grpc_uri_parse(exec_ctx, uri_str, 0 /* suppress_errors */); GPR_ASSERT(uri != NULL); if (!grpc_parse_uri(uri, addr)) memset(addr, 0, sizeof(*addr)); grpc_uri_destroy(uri); } -void grpc_get_subchannel_address_arg(grpc_exec_ctx *exec_ctx, - const grpc_channel_args *args, - grpc_resolved_address *addr) { - const char *addr_uri_str = grpc_get_subchannel_address_uri_arg(args); +void grpc_get_subchannel_address_arg(grpc_exec_ctx* exec_ctx, + const grpc_channel_args* args, + grpc_resolved_address* addr) { + const char* addr_uri_str = grpc_get_subchannel_address_uri_arg(args); memset(addr, 0, sizeof(*addr)); if (*addr_uri_str != '\0') { grpc_uri_to_sockaddr(exec_ctx, addr_uri_str, addr); } } -const char *grpc_get_subchannel_address_uri_arg(const grpc_channel_args *args) { - const grpc_arg *addr_arg = +const char* grpc_get_subchannel_address_uri_arg(const grpc_channel_args* args) { + const grpc_arg* addr_arg = grpc_channel_args_find(args, GRPC_ARG_SUBCHANNEL_ADDRESS); GPR_ASSERT(addr_arg != NULL); // Should have been set by LB policy. GPR_ASSERT(addr_arg->type == GRPC_ARG_STRING); return addr_arg->value.string; } -grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address *addr) { +grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address* addr) { return grpc_channel_arg_string_create( - (char *)GRPC_ARG_SUBCHANNEL_ADDRESS, + (char*)GRPC_ARG_SUBCHANNEL_ADDRESS, addr->len > 0 ? grpc_sockaddr_to_uri(addr) : gpr_strdup("")); } diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index 1cd73f3ff4..970f182ff0 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -79,118 +79,118 @@ typedef struct grpc_subchannel_key grpc_subchannel_key; #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS #endif -grpc_subchannel *grpc_subchannel_ref( - grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -grpc_subchannel *grpc_subchannel_ref_from_weak_ref( - grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_subchannel_unref(grpc_exec_ctx *exec_ctx, - grpc_subchannel *channel +grpc_subchannel* grpc_subchannel_ref( + grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +grpc_subchannel* grpc_subchannel_ref_from_weak_ref( + grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_subchannel_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -grpc_subchannel *grpc_subchannel_weak_ref( - grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_subchannel_weak_unref(grpc_exec_ctx *exec_ctx, - grpc_subchannel *channel +grpc_subchannel* grpc_subchannel_weak_ref( + grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_subchannel_weak_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -grpc_connected_subchannel *grpc_connected_subchannel_ref( - grpc_connected_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_connected_subchannel_unref(grpc_exec_ctx *exec_ctx, - grpc_connected_subchannel *channel +grpc_connected_subchannel* grpc_connected_subchannel_ref( + grpc_connected_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_connected_subchannel_unref(grpc_exec_ctx* exec_ctx, + grpc_connected_subchannel* channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); void grpc_subchannel_call_ref( - grpc_subchannel_call *call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, - grpc_subchannel_call *call + grpc_subchannel_call* call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_subchannel_call_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel_call* call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); /** construct a subchannel call */ typedef struct { - grpc_polling_entity *pollent; + grpc_polling_entity* pollent; grpc_slice path; gpr_timespec start_time; grpc_millis deadline; - gpr_arena *arena; - grpc_call_context_element *context; - grpc_call_combiner *call_combiner; + gpr_arena* arena; + grpc_call_context_element* context; + grpc_call_combiner* call_combiner; } grpc_connected_subchannel_call_args; -grpc_error *grpc_connected_subchannel_create_call( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *connected_subchannel, - const grpc_connected_subchannel_call_args *args, - grpc_subchannel_call **subchannel_call); +grpc_error* grpc_connected_subchannel_create_call( + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* connected_subchannel, + const grpc_connected_subchannel_call_args* args, + grpc_subchannel_call** subchannel_call); /** process a transport level op */ void grpc_connected_subchannel_process_transport_op( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *subchannel, - grpc_transport_op *op); + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* subchannel, + grpc_transport_op* op); /** poll the current connectivity state of a channel */ grpc_connectivity_state grpc_subchannel_check_connectivity( - grpc_subchannel *channel, grpc_error **error); + grpc_subchannel* channel, grpc_error** error); /** Calls notify when the connectivity state of a channel becomes different from *state. Updates *state with the new state of the channel. */ void grpc_subchannel_notify_on_state_change( - grpc_exec_ctx *exec_ctx, grpc_subchannel *channel, - grpc_pollset_set *interested_parties, grpc_connectivity_state *state, - grpc_closure *notify); + grpc_exec_ctx* exec_ctx, grpc_subchannel* channel, + grpc_pollset_set* interested_parties, grpc_connectivity_state* state, + grpc_closure* notify); void grpc_connected_subchannel_notify_on_state_change( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *channel, - grpc_pollset_set *interested_parties, grpc_connectivity_state *state, - grpc_closure *notify); -void grpc_connected_subchannel_ping(grpc_exec_ctx *exec_ctx, - grpc_connected_subchannel *channel, - grpc_closure *notify); + grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* channel, + grpc_pollset_set* interested_parties, grpc_connectivity_state* state, + grpc_closure* notify); +void grpc_connected_subchannel_ping(grpc_exec_ctx* exec_ctx, + grpc_connected_subchannel* channel, + grpc_closure* notify); /** retrieve the grpc_connected_subchannel - or NULL if called before the subchannel becomes connected */ -grpc_connected_subchannel *grpc_subchannel_get_connected_subchannel( - grpc_subchannel *subchannel); +grpc_connected_subchannel* grpc_subchannel_get_connected_subchannel( + grpc_subchannel* subchannel); /** return the subchannel index key for \a subchannel */ -const grpc_subchannel_key *grpc_subchannel_get_key( - const grpc_subchannel *subchannel); +const grpc_subchannel_key* grpc_subchannel_get_key( + const grpc_subchannel* subchannel); /** continue processing a transport op */ -void grpc_subchannel_call_process_op(grpc_exec_ctx *exec_ctx, - grpc_subchannel_call *subchannel_call, - grpc_transport_stream_op_batch *op); +void grpc_subchannel_call_process_op(grpc_exec_ctx* exec_ctx, + grpc_subchannel_call* subchannel_call, + grpc_transport_stream_op_batch* op); /** Must be called once per call. Sets the 'then_schedule_closure' argument for call stack destruction. */ void grpc_subchannel_call_set_cleanup_closure( - grpc_subchannel_call *subchannel_call, grpc_closure *closure); + grpc_subchannel_call* subchannel_call, grpc_closure* closure); -grpc_call_stack *grpc_subchannel_call_get_call_stack( - grpc_subchannel_call *subchannel_call); +grpc_call_stack* grpc_subchannel_call_get_call_stack( + grpc_subchannel_call* subchannel_call); struct grpc_subchannel_args { /* When updating this struct, also update subchannel_index.c */ /** Channel filters for this channel - wrapped factories will likely want to mutate this */ - const grpc_channel_filter **filters; + const grpc_channel_filter** filters; /** The number of filters in the above array */ size_t filter_count; /** Channel arguments to be supplied to the newly created channel */ - const grpc_channel_args *args; + const grpc_channel_args* args; }; /** create a subchannel given a connector */ -grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, - grpc_connector *connector, - const grpc_subchannel_args *args); +grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx, + grpc_connector* connector, + const grpc_subchannel_args* args); /// Sets \a addr from \a args. -void grpc_get_subchannel_address_arg(grpc_exec_ctx *exec_ctx, - const grpc_channel_args *args, - grpc_resolved_address *addr); +void grpc_get_subchannel_address_arg(grpc_exec_ctx* exec_ctx, + const grpc_channel_args* args, + grpc_resolved_address* addr); /// Returns the URI string for the address to connect to. -const char *grpc_get_subchannel_address_uri_arg(const grpc_channel_args *args); +const char* grpc_get_subchannel_address_uri_arg(const grpc_channel_args* args); /// Returns a new channel arg encoding the subchannel address as a string. /// Caller is responsible for freeing the string. -grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address *addr); +grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address* addr); #ifdef __cplusplus } diff --git a/src/core/ext/filters/client_channel/subchannel_index.cc b/src/core/ext/filters/client_channel/subchannel_index.cc index 1f466ec0b8..0c4213cf77 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.cc +++ b/src/core/ext/filters/client_channel/subchannel_index.cc @@ -42,15 +42,15 @@ struct grpc_subchannel_key { static bool g_force_creation = false; -static grpc_subchannel_key *create_key( - const grpc_subchannel_args *args, - grpc_channel_args *(*copy_channel_args)(const grpc_channel_args *args)) { - grpc_subchannel_key *k = (grpc_subchannel_key *)gpr_malloc(sizeof(*k)); +static grpc_subchannel_key* create_key( + const grpc_subchannel_args* args, + grpc_channel_args* (*copy_channel_args)(const grpc_channel_args* args)) { + grpc_subchannel_key* k = (grpc_subchannel_key*)gpr_malloc(sizeof(*k)); k->args.filter_count = args->filter_count; if (k->args.filter_count > 0) { - k->args.filters = (const grpc_channel_filter **)gpr_malloc( + k->args.filters = (const grpc_channel_filter**)gpr_malloc( sizeof(*k->args.filters) * k->args.filter_count); - memcpy((grpc_channel_filter *)k->args.filters, args->filters, + memcpy((grpc_channel_filter*)k->args.filters, args->filters, sizeof(*k->args.filters) * k->args.filter_count); } else { k->args.filters = NULL; @@ -59,17 +59,17 @@ static grpc_subchannel_key *create_key( return k; } -grpc_subchannel_key *grpc_subchannel_key_create( - const grpc_subchannel_args *args) { +grpc_subchannel_key* grpc_subchannel_key_create( + const grpc_subchannel_args* args) { return create_key(args, grpc_channel_args_normalize); } -static grpc_subchannel_key *subchannel_key_copy(grpc_subchannel_key *k) { +static grpc_subchannel_key* subchannel_key_copy(grpc_subchannel_key* k) { return create_key(&k->args, grpc_channel_args_copy); } -int grpc_subchannel_key_compare(const grpc_subchannel_key *a, - const grpc_subchannel_key *b) { +int grpc_subchannel_key_compare(const grpc_subchannel_key* a, + const grpc_subchannel_key* b) { if (g_force_creation) return false; int c = GPR_ICMP(a->args.filter_count, b->args.filter_count); if (c != 0) return c; @@ -81,35 +81,34 @@ int grpc_subchannel_key_compare(const grpc_subchannel_key *a, return grpc_channel_args_compare(a->args.args, b->args.args); } -void grpc_subchannel_key_destroy(grpc_exec_ctx *exec_ctx, - grpc_subchannel_key *k) { - gpr_free((grpc_channel_args *)k->args.filters); - grpc_channel_args_destroy(exec_ctx, (grpc_channel_args *)k->args.args); +void grpc_subchannel_key_destroy(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* k) { + gpr_free((grpc_channel_args*)k->args.filters); + grpc_channel_args_destroy(exec_ctx, (grpc_channel_args*)k->args.args); gpr_free(k); } -static void sck_avl_destroy(void *p, void *user_data) { - grpc_exec_ctx *exec_ctx = (grpc_exec_ctx *)user_data; - grpc_subchannel_key_destroy(exec_ctx, (grpc_subchannel_key *)p); +static void sck_avl_destroy(void* p, void* user_data) { + grpc_exec_ctx* exec_ctx = (grpc_exec_ctx*)user_data; + grpc_subchannel_key_destroy(exec_ctx, (grpc_subchannel_key*)p); } -static void *sck_avl_copy(void *p, void *unused) { - return subchannel_key_copy((grpc_subchannel_key *)p); +static void* sck_avl_copy(void* p, void* unused) { + return subchannel_key_copy((grpc_subchannel_key*)p); } -static long sck_avl_compare(void *a, void *b, void *unused) { - return grpc_subchannel_key_compare((grpc_subchannel_key *)a, - (grpc_subchannel_key *)b); +static long sck_avl_compare(void* a, void* b, void* unused) { + return grpc_subchannel_key_compare((grpc_subchannel_key*)a, + (grpc_subchannel_key*)b); } -static void scv_avl_destroy(void *p, void *user_data) { - grpc_exec_ctx *exec_ctx = (grpc_exec_ctx *)user_data; - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, (grpc_subchannel *)p, - "subchannel_index"); +static void scv_avl_destroy(void* p, void* user_data) { + grpc_exec_ctx* exec_ctx = (grpc_exec_ctx*)user_data; + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, (grpc_subchannel*)p, "subchannel_index"); } -static void *scv_avl_copy(void *p, void *unused) { - GRPC_SUBCHANNEL_WEAK_REF((grpc_subchannel *)p, "subchannel_index"); +static void* scv_avl_copy(void* p, void* unused) { + GRPC_SUBCHANNEL_WEAK_REF((grpc_subchannel*)p, "subchannel_index"); return p; } @@ -145,25 +144,25 @@ void grpc_subchannel_index_unref(void) { void grpc_subchannel_index_ref(void) { gpr_ref_non_zero(&g_refcount); } -grpc_subchannel *grpc_subchannel_index_find(grpc_exec_ctx *exec_ctx, - grpc_subchannel_key *key) { +grpc_subchannel* grpc_subchannel_index_find(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key) { // Lock, and take a reference to the subchannel index. // We don't need to do the search under a lock as avl's are immutable. gpr_mu_lock(&g_mu); gpr_avl index = gpr_avl_ref(g_subchannel_index, exec_ctx); gpr_mu_unlock(&g_mu); - grpc_subchannel *c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF( - (grpc_subchannel *)gpr_avl_get(index, key, exec_ctx), "index_find"); + grpc_subchannel* c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF( + (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx), "index_find"); gpr_avl_unref(index, exec_ctx); return c; } -grpc_subchannel *grpc_subchannel_index_register(grpc_exec_ctx *exec_ctx, - grpc_subchannel_key *key, - grpc_subchannel *constructed) { - grpc_subchannel *c = NULL; +grpc_subchannel* grpc_subchannel_index_register(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key, + grpc_subchannel* constructed) { + grpc_subchannel* c = NULL; bool need_to_unref_constructed; while (c == NULL) { @@ -176,7 +175,7 @@ grpc_subchannel *grpc_subchannel_index_register(grpc_exec_ctx *exec_ctx, gpr_mu_unlock(&g_mu); // - Check to see if a subchannel already exists - c = (grpc_subchannel *)gpr_avl_get(index, key, exec_ctx); + c = (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx); if (c != NULL) { c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(c, "index_register"); } @@ -211,9 +210,9 @@ grpc_subchannel *grpc_subchannel_index_register(grpc_exec_ctx *exec_ctx, return c; } -void grpc_subchannel_index_unregister(grpc_exec_ctx *exec_ctx, - grpc_subchannel_key *key, - grpc_subchannel *constructed) { +void grpc_subchannel_index_unregister(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key, + grpc_subchannel* constructed) { bool done = false; while (!done) { // Compare and swap loop: @@ -224,7 +223,7 @@ void grpc_subchannel_index_unregister(grpc_exec_ctx *exec_ctx, // Check to see if this key still refers to the previously // registered subchannel - grpc_subchannel *c = (grpc_subchannel *)gpr_avl_get(index, key, exec_ctx); + grpc_subchannel* c = (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx); if (c != constructed) { gpr_avl_unref(index, exec_ctx); break; diff --git a/src/core/ext/filters/client_channel/subchannel_index.h b/src/core/ext/filters/client_channel/subchannel_index.h index 05c3878379..47f9c7bb1e 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.h +++ b/src/core/ext/filters/client_channel/subchannel_index.h @@ -29,34 +29,34 @@ extern "C" { shared amongst channels */ /** Create a key that can be used to uniquely identify a subchannel */ -grpc_subchannel_key *grpc_subchannel_key_create( - const grpc_subchannel_args *args); +grpc_subchannel_key* grpc_subchannel_key_create( + const grpc_subchannel_args* args); /** Destroy a subchannel key */ -void grpc_subchannel_key_destroy(grpc_exec_ctx *exec_ctx, - grpc_subchannel_key *key); +void grpc_subchannel_key_destroy(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key); /** Given a subchannel key, find the subchannel registered for it. Returns NULL if no such channel exists. Thread-safe. */ -grpc_subchannel *grpc_subchannel_index_find(grpc_exec_ctx *exec_ctx, - grpc_subchannel_key *key); +grpc_subchannel* grpc_subchannel_index_find(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key); /** Register a subchannel against a key. Takes ownership of \a constructed. Returns the registered subchannel. This may be different from \a constructed in the case of a registration race. */ -grpc_subchannel *grpc_subchannel_index_register(grpc_exec_ctx *exec_ctx, - grpc_subchannel_key *key, - grpc_subchannel *constructed); +grpc_subchannel* grpc_subchannel_index_register(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key, + grpc_subchannel* constructed); /** Remove \a constructed as the registered subchannel for \a key. */ -void grpc_subchannel_index_unregister(grpc_exec_ctx *exec_ctx, - grpc_subchannel_key *key, - grpc_subchannel *constructed); +void grpc_subchannel_index_unregister(grpc_exec_ctx* exec_ctx, + grpc_subchannel_key* key, + grpc_subchannel* constructed); -int grpc_subchannel_key_compare(const grpc_subchannel_key *a, - const grpc_subchannel_key *b); +int grpc_subchannel_key_compare(const grpc_subchannel_key* a, + const grpc_subchannel_key* b); /** Initialize the subchannel index (global) */ void grpc_subchannel_index_init(void); diff --git a/src/core/ext/filters/client_channel/uri_parser.cc b/src/core/ext/filters/client_channel/uri_parser.cc index fb4fb8e694..917e65342b 100644 --- a/src/core/ext/filters/client_channel/uri_parser.cc +++ b/src/core/ext/filters/client_channel/uri_parser.cc @@ -34,9 +34,9 @@ /** a size_t default value... maps to all 1's */ #define NOT_SET (~(size_t)0) -static grpc_uri *bad_uri(const char *uri_text, size_t pos, const char *section, +static grpc_uri* bad_uri(const char* uri_text, size_t pos, const char* section, bool suppress_errors) { - char *line_prefix; + char* line_prefix; size_t pfx_len; if (!suppress_errors) { @@ -45,7 +45,7 @@ static grpc_uri *bad_uri(const char *uri_text, size_t pos, const char *section, gpr_log(GPR_ERROR, "%s%s'", line_prefix, uri_text); gpr_free(line_prefix); - line_prefix = (char *)gpr_malloc(pfx_len + 1); + line_prefix = (char*)gpr_malloc(pfx_len + 1); memset(line_prefix, ' ', pfx_len); line_prefix[pfx_len] = 0; gpr_log(GPR_ERROR, "%s^ here", line_prefix); @@ -56,13 +56,13 @@ static grpc_uri *bad_uri(const char *uri_text, size_t pos, const char *section, } /** Returns a copy of percent decoded \a src[begin, end) */ -static char *decode_and_copy_component(grpc_exec_ctx *exec_ctx, const char *src, +static char* decode_and_copy_component(grpc_exec_ctx* exec_ctx, const char* src, size_t begin, size_t end) { grpc_slice component = grpc_slice_from_copied_buffer(src + begin, end - begin); grpc_slice decoded_component = grpc_permissive_percent_decode_slice(component); - char *out = grpc_dump_slice(decoded_component, GPR_DUMP_ASCII); + char* out = grpc_dump_slice(decoded_component, GPR_DUMP_ASCII); grpc_slice_unref_internal(exec_ctx, component); grpc_slice_unref_internal(exec_ctx, decoded_component); return out; @@ -76,7 +76,7 @@ static bool valid_hex(char c) { /** Returns how many chars to advance if \a uri_text[i] begins a valid \a pchar * production. If \a uri_text[i] introduces an invalid \a pchar (such as percent * sign not followed by two hex digits), NOT_SET is returned. */ -static size_t parse_pchar(const char *uri_text, size_t i) { +static size_t parse_pchar(const char* uri_text, size_t i) { /* pchar = unreserved / pct-encoded / sub-delims / ":" / "@" * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" * pct-encoded = "%" HEXDIG HEXDIG @@ -118,7 +118,7 @@ static size_t parse_pchar(const char *uri_text, size_t i) { } /* *( pchar / "?" / "/" ) */ -static int parse_fragment_or_query(const char *uri_text, size_t *i) { +static int parse_fragment_or_query(const char* uri_text, size_t* i) { char c; while ((c = uri_text[*i]) != 0) { const size_t advance = parse_pchar(uri_text, *i); /* pchar */ @@ -143,9 +143,9 @@ static int parse_fragment_or_query(const char *uri_text, size_t *i) { return 1; } -static void parse_query_parts(grpc_uri *uri) { - static const char *QUERY_PARTS_SEPARATOR = "&"; - static const char *QUERY_PARTS_VALUE_SEPARATOR = "="; +static void parse_query_parts(grpc_uri* uri) { + static const char* QUERY_PARTS_SEPARATOR = "&"; + static const char* QUERY_PARTS_VALUE_SEPARATOR = "="; GPR_ASSERT(uri->query != NULL); if (uri->query[0] == '\0') { uri->query_parts = NULL; @@ -157,11 +157,11 @@ static void parse_query_parts(grpc_uri *uri) { gpr_string_split(uri->query, QUERY_PARTS_SEPARATOR, &uri->query_parts, &uri->num_query_parts); uri->query_parts_values = - (char **)gpr_malloc(uri->num_query_parts * sizeof(char **)); + (char**)gpr_malloc(uri->num_query_parts * sizeof(char**)); for (size_t i = 0; i < uri->num_query_parts; i++) { - char **query_param_parts; + char** query_param_parts; size_t num_query_param_parts; - char *full = uri->query_parts[i]; + char* full = uri->query_parts[i]; gpr_string_split(full, QUERY_PARTS_VALUE_SEPARATOR, &query_param_parts, &num_query_param_parts); GPR_ASSERT(num_query_param_parts > 0); @@ -182,9 +182,9 @@ static void parse_query_parts(grpc_uri *uri) { } } -grpc_uri *grpc_uri_parse(grpc_exec_ctx *exec_ctx, const char *uri_text, +grpc_uri* grpc_uri_parse(grpc_exec_ctx* exec_ctx, const char* uri_text, bool suppress_errors) { - grpc_uri *uri; + grpc_uri* uri; size_t scheme_begin = 0; size_t scheme_end = NOT_SET; size_t authority_begin = NOT_SET; @@ -270,7 +270,7 @@ grpc_uri *grpc_uri_parse(grpc_exec_ctx *exec_ctx, const char *uri_text, fragment_end = i; } - uri = (grpc_uri *)gpr_zalloc(sizeof(*uri)); + uri = (grpc_uri*)gpr_zalloc(sizeof(*uri)); uri->scheme = decode_and_copy_component(exec_ctx, uri_text, scheme_begin, scheme_end); uri->authority = decode_and_copy_component(exec_ctx, uri_text, @@ -286,7 +286,7 @@ grpc_uri *grpc_uri_parse(grpc_exec_ctx *exec_ctx, const char *uri_text, return uri; } -const char *grpc_uri_get_query_arg(const grpc_uri *uri, const char *key) { +const char* grpc_uri_get_query_arg(const grpc_uri* uri, const char* key) { GPR_ASSERT(key != NULL); if (key[0] == '\0') return NULL; @@ -298,7 +298,7 @@ const char *grpc_uri_get_query_arg(const grpc_uri *uri, const char *key) { return NULL; } -void grpc_uri_destroy(grpc_uri *uri) { +void grpc_uri_destroy(grpc_uri* uri) { if (!uri) return; gpr_free(uri->scheme); gpr_free(uri->authority); diff --git a/src/core/ext/filters/client_channel/uri_parser.h b/src/core/ext/filters/client_channel/uri_parser.h index e78da5928b..cd877ade8d 100644 --- a/src/core/ext/filters/client_channel/uri_parser.h +++ b/src/core/ext/filters/client_channel/uri_parser.h @@ -27,29 +27,29 @@ extern "C" { #endif typedef struct { - char *scheme; - char *authority; - char *path; - char *query; + char* scheme; + char* authority; + char* path; + char* query; /** Query substrings separated by '&' */ - char **query_parts; + char** query_parts; /** Number of elements in \a query_parts and \a query_parts_values */ size_t num_query_parts; /** Split each query part by '='. NULL if not present. */ - char **query_parts_values; - char *fragment; + char** query_parts_values; + char* fragment; } grpc_uri; /** parse a uri, return NULL on failure */ -grpc_uri *grpc_uri_parse(grpc_exec_ctx *exec_ctx, const char *uri_text, +grpc_uri* grpc_uri_parse(grpc_exec_ctx* exec_ctx, const char* uri_text, bool suppress_errors); /** return the part of a query string after the '=' in "?key=xxx&...", or NULL * if key is not present */ -const char *grpc_uri_get_query_arg(const grpc_uri *uri, const char *key); +const char* grpc_uri_get_query_arg(const grpc_uri* uri, const char* key); /** destroy a uri */ -void grpc_uri_destroy(grpc_uri *uri); +void grpc_uri_destroy(grpc_uri* uri); #ifdef __cplusplus } diff --git a/src/core/ext/filters/http/client/http_client_filter.cc b/src/core/ext/filters/http/client/http_client_filter.cc index 6208089f2e..590bd22b1e 100644 --- a/src/core/ext/filters/http/client/http_client_filter.cc +++ b/src/core/ext/filters/http/client/http_client_filter.cc @@ -36,7 +36,7 @@ static const size_t kMaxPayloadSizeForGet = 2048; typedef struct call_data { - grpc_call_combiner *call_combiner; + grpc_call_combiner* call_combiner; // State for handling send_initial_metadata ops. grpc_linked_mdelem method; grpc_linked_mdelem scheme; @@ -45,20 +45,20 @@ typedef struct call_data { grpc_linked_mdelem content_type; grpc_linked_mdelem user_agent; // State for handling recv_initial_metadata ops. - grpc_metadata_batch *recv_initial_metadata; - grpc_closure *original_recv_initial_metadata_ready; + grpc_metadata_batch* recv_initial_metadata; + grpc_closure* original_recv_initial_metadata_ready; grpc_closure recv_initial_metadata_ready; // State for handling recv_trailing_metadata ops. - grpc_metadata_batch *recv_trailing_metadata; - grpc_closure *original_recv_trailing_metadata_on_complete; + grpc_metadata_batch* recv_trailing_metadata; + grpc_closure* original_recv_trailing_metadata_on_complete; grpc_closure recv_trailing_metadata_on_complete; // State for handling send_message ops. - grpc_transport_stream_op_batch *send_message_batch; + grpc_transport_stream_op_batch* send_message_batch; size_t send_message_bytes_read; grpc_byte_stream_cache send_message_cache; grpc_caching_byte_stream send_message_caching_stream; grpc_closure on_send_message_next_done; - grpc_closure *original_send_message_on_complete; + grpc_closure* original_send_message_on_complete; grpc_closure send_message_on_complete; } call_data; @@ -68,18 +68,18 @@ typedef struct channel_data { size_t max_payload_size_for_get; } channel_data; -static grpc_error *client_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_metadata_batch *b) { +static grpc_error* client_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_metadata_batch* b) { if (b->idx.named.status != NULL) { if (grpc_mdelem_eq(b->idx.named.status->md, GRPC_MDELEM_STATUS_200)) { grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.status); } else { - char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.status->md), + char* val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.status->md), GPR_DUMP_ASCII); - char *msg; + char* msg; gpr_asprintf(&msg, "Received http2 header with status: %s", val); - grpc_error *e = grpc_error_set_str( + grpc_error* e = grpc_error_set_str( grpc_error_set_int( grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING( @@ -125,7 +125,7 @@ static grpc_error *client_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, } else { /* TODO(klempner): We're currently allowing this, but we shouldn't see it without a proxy so log for now. */ - char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.content_type->md), + char* val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.content_type->md), GPR_DUMP_ASCII); gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); gpr_free(val); @@ -137,10 +137,10 @@ static grpc_error *client_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -static void recv_initial_metadata_ready(grpc_exec_ctx *exec_ctx, - void *user_data, grpc_error *error) { - grpc_call_element *elem = (grpc_call_element *)user_data; - call_data *calld = (call_data *)elem->call_data; +static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_error* error) { + grpc_call_element* elem = (grpc_call_element*)user_data; + call_data* calld = (call_data*)elem->call_data; if (error == GRPC_ERROR_NONE) { error = client_filter_incoming_metadata(exec_ctx, elem, calld->recv_initial_metadata); @@ -151,11 +151,11 @@ static void recv_initial_metadata_ready(grpc_exec_ctx *exec_ctx, error); } -static void recv_trailing_metadata_on_complete(grpc_exec_ctx *exec_ctx, - void *user_data, - grpc_error *error) { - grpc_call_element *elem = (grpc_call_element *)user_data; - call_data *calld = (call_data *)elem->call_data; +static void recv_trailing_metadata_on_complete(grpc_exec_ctx* exec_ctx, + void* user_data, + grpc_error* error) { + grpc_call_element* elem = (grpc_call_element*)user_data; + call_data* calld = (call_data*)elem->call_data; if (error == GRPC_ERROR_NONE) { error = client_filter_incoming_metadata(exec_ctx, elem, calld->recv_trailing_metadata); @@ -166,10 +166,10 @@ static void recv_trailing_metadata_on_complete(grpc_exec_ctx *exec_ctx, error); } -static void send_message_on_complete(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_call_element *elem = (grpc_call_element *)arg; - call_data *calld = (call_data *)elem->call_data; +static void send_message_on_complete(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_call_element* elem = (grpc_call_element*)arg; + call_data* calld = (call_data*)elem->call_data; grpc_byte_stream_cache_destroy(exec_ctx, &calld->send_message_cache); GRPC_CLOSURE_RUN(exec_ctx, calld->original_send_message_on_complete, GRPC_ERROR_REF(error)); @@ -177,10 +177,10 @@ static void send_message_on_complete(grpc_exec_ctx *exec_ctx, void *arg, // Pulls a slice from the send_message byte stream, updating // calld->send_message_bytes_read. -static grpc_error *pull_slice_from_send_message(grpc_exec_ctx *exec_ctx, - call_data *calld) { +static grpc_error* pull_slice_from_send_message(grpc_exec_ctx* exec_ctx, + call_data* calld) { grpc_slice incoming_slice; - grpc_error *error = grpc_byte_stream_pull( + grpc_error* error = grpc_byte_stream_pull( exec_ctx, &calld->send_message_caching_stream.base, &incoming_slice); if (error == GRPC_ERROR_NONE) { calld->send_message_bytes_read += GRPC_SLICE_LENGTH(incoming_slice); @@ -194,12 +194,12 @@ static grpc_error *pull_slice_from_send_message(grpc_exec_ctx *exec_ctx, // calld->send_message_caching_stream.base.length, then we have completed // reading from the byte stream; otherwise, an async read has been dispatched // and on_send_message_next_done() will be invoked when it is complete. -static grpc_error *read_all_available_send_message_data(grpc_exec_ctx *exec_ctx, - call_data *calld) { +static grpc_error* read_all_available_send_message_data(grpc_exec_ctx* exec_ctx, + call_data* calld) { while (grpc_byte_stream_next(exec_ctx, &calld->send_message_caching_stream.base, ~(size_t)0, &calld->on_send_message_next_done)) { - grpc_error *error = pull_slice_from_send_message(exec_ctx, calld); + grpc_error* error = pull_slice_from_send_message(exec_ctx, calld); if (error != GRPC_ERROR_NONE) return error; if (calld->send_message_bytes_read == calld->send_message_caching_stream.base.length) { @@ -210,10 +210,10 @@ static grpc_error *read_all_available_send_message_data(grpc_exec_ctx *exec_ctx, } // Async callback for grpc_byte_stream_next(). -static void on_send_message_next_done(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_call_element *elem = (grpc_call_element *)arg; - call_data *calld = (call_data *)elem->call_data; +static void on_send_message_next_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_call_element* elem = (grpc_call_element*)arg; + call_data* calld = (call_data*)elem->call_data; if (error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure( exec_ctx, calld->send_message_batch, error, calld->call_combiner); @@ -233,8 +233,8 @@ static void on_send_message_next_done(grpc_exec_ctx *exec_ctx, void *arg, grpc_call_next_op(exec_ctx, elem, calld->send_message_batch); } -static char *slice_buffer_to_string(grpc_slice_buffer *slice_buffer) { - char *payload_bytes = (char *)gpr_malloc(slice_buffer->length + 1); +static char* slice_buffer_to_string(grpc_slice_buffer* slice_buffer) { + char* payload_bytes = (char*)gpr_malloc(slice_buffer->length + 1); size_t offset = 0; for (size_t i = 0; i < slice_buffer->count; ++i) { memcpy(payload_bytes + offset, @@ -248,10 +248,10 @@ static char *slice_buffer_to_string(grpc_slice_buffer *slice_buffer) { // Modifies the path entry in the batch's send_initial_metadata to // append the base64-encoded query for a GET request. -static grpc_error *update_path_for_get(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_transport_stream_op_batch *batch) { - call_data *calld = (call_data *)elem->call_data; +static grpc_error* update_path_for_get(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { + call_data* calld = (call_data*)elem->call_data; grpc_slice path_slice = GRPC_MDVALUE(batch->payload->send_initial_metadata.send_initial_metadata ->idx.named.path->md); @@ -264,33 +264,33 @@ static grpc_error *update_path_for_get(grpc_exec_ctx *exec_ctx, false /* multi_line */); grpc_slice path_with_query_slice = GRPC_SLICE_MALLOC(estimated_len); /* memcopy individual pieces into this slice */ - char *write_ptr = (char *)GRPC_SLICE_START_PTR(path_with_query_slice); - char *original_path = (char *)GRPC_SLICE_START_PTR(path_slice); + char* write_ptr = (char*)GRPC_SLICE_START_PTR(path_with_query_slice); + char* original_path = (char*)GRPC_SLICE_START_PTR(path_slice); memcpy(write_ptr, original_path, GRPC_SLICE_LENGTH(path_slice)); write_ptr += GRPC_SLICE_LENGTH(path_slice); *write_ptr++ = '?'; - char *payload_bytes = + char* payload_bytes = slice_buffer_to_string(&calld->send_message_cache.cache_buffer); - grpc_base64_encode_core((char *)write_ptr, payload_bytes, + grpc_base64_encode_core((char*)write_ptr, payload_bytes, batch->payload->send_message.send_message->length, true /* url_safe */, false /* multi_line */); gpr_free(payload_bytes); /* remove trailing unused memory and add trailing 0 to terminate string */ - char *t = (char *)GRPC_SLICE_START_PTR(path_with_query_slice); + char* t = (char*)GRPC_SLICE_START_PTR(path_with_query_slice); /* safe to use strlen since base64_encode will always add '\0' */ path_with_query_slice = grpc_slice_sub_no_ref(path_with_query_slice, 0, strlen(t)); /* substitute previous path with the new path+query */ grpc_mdelem mdelem_path_and_query = grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH, path_with_query_slice); - grpc_metadata_batch *b = + grpc_metadata_batch* b = batch->payload->send_initial_metadata.send_initial_metadata; return grpc_metadata_batch_substitute(exec_ctx, b, b->idx.named.path, mdelem_path_and_query); } -static void remove_if_present(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, +static void remove_if_present(grpc_exec_ctx* exec_ctx, + grpc_metadata_batch* batch, grpc_metadata_batch_callouts_index idx) { if (batch->idx.array[idx] != NULL) { grpc_metadata_batch_remove(exec_ctx, batch, batch->idx.array[idx]); @@ -298,10 +298,10 @@ static void remove_if_present(grpc_exec_ctx *exec_ctx, } static void hc_start_transport_stream_op_batch( - grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_transport_stream_op_batch *batch) { - call_data *calld = (call_data *)elem->call_data; - channel_data *channeld = (channel_data *)elem->channel_data; + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { + call_data* calld = (call_data*)elem->call_data; + channel_data* channeld = (channel_data*)elem->channel_data; GPR_TIMER_BEGIN("hc_start_transport_stream_op_batch", 0); if (batch->recv_initial_metadata) { @@ -322,7 +322,7 @@ static void hc_start_transport_stream_op_batch( batch->on_complete = &calld->recv_trailing_metadata_on_complete; } - grpc_error *error = GRPC_ERROR_NONE; + grpc_error* error = GRPC_ERROR_NONE; bool batch_will_be_handled_asynchronously = false; if (batch->send_initial_metadata) { // Decide which HTTP VERB to use. We use GET if the request is marked @@ -422,10 +422,10 @@ done: } /* Constructor for call_data */ -static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_element_args *args) { - call_data *calld = (call_data *)elem->call_data; +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + const grpc_call_element_args* args) { + call_data* calld = (call_data*)elem->call_data; calld->call_combiner = args->call_combiner; GRPC_CLOSURE_INIT(&calld->recv_initial_metadata_ready, recv_initial_metadata_ready, elem, @@ -441,11 +441,11 @@ static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_final_info *final_info, - grpc_closure *ignored) {} +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* ignored) {} -static grpc_mdelem scheme_from_args(const grpc_channel_args *args) { +static grpc_mdelem scheme_from_args(const grpc_channel_args* args) { unsigned i; size_t j; grpc_mdelem valid_schemes[] = {GRPC_MDELEM_SCHEME_HTTP, @@ -466,7 +466,7 @@ static grpc_mdelem scheme_from_args(const grpc_channel_args *args) { return GRPC_MDELEM_SCHEME_HTTP; } -static size_t max_payload_size_from_args(const grpc_channel_args *args) { +static size_t max_payload_size_from_args(const grpc_channel_args* args) { if (args != NULL) { for (size_t i = 0; i < args->num_args; ++i) { if (0 == strcmp(args->args[i].key, GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET)) { @@ -482,12 +482,12 @@ static size_t max_payload_size_from_args(const grpc_channel_args *args) { return kMaxPayloadSizeForGet; } -static grpc_slice user_agent_from_args(const grpc_channel_args *args, - const char *transport_name) { +static grpc_slice user_agent_from_args(const grpc_channel_args* args, + const char* transport_name) { gpr_strvec v; size_t i; int is_first = 1; - char *tmp; + char* tmp; grpc_slice result; gpr_strvec_init(&v); @@ -533,10 +533,10 @@ static grpc_slice user_agent_from_args(const grpc_channel_args *args, } /* Constructor for channel_data */ -static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_channel_element_args *args) { - channel_data *chand = (channel_data *)elem->channel_data; +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + grpc_channel_element_args* args) { + channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(!args->is_last); GPR_ASSERT(args->optional_transport != NULL); chand->static_scheme = scheme_from_args(args->channel_args); @@ -550,9 +550,9 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem) { - channel_data *chand = (channel_data *)elem->channel_data; +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { + channel_data* chand = (channel_data*)elem->channel_data; GRPC_MDELEM_UNREF(exec_ctx, chand->user_agent); } diff --git a/src/core/ext/filters/http/http_filters_plugin.cc b/src/core/ext/filters/http/http_filters_plugin.cc index 8f5b856317..064e66e323 100644 --- a/src/core/ext/filters/http/http_filters_plugin.cc +++ b/src/core/ext/filters/http/http_filters_plugin.cc @@ -27,25 +27,25 @@ #include "src/core/lib/transport/transport_impl.h" typedef struct { - const grpc_channel_filter *filter; - const char *control_channel_arg; + const grpc_channel_filter* filter; + const char* control_channel_arg; } optional_filter; static optional_filter compress_filter = { &grpc_message_compress_filter, GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION}; static bool is_building_http_like_transport( - grpc_channel_stack_builder *builder) { - grpc_transport *t = grpc_channel_stack_builder_get_transport(builder); + grpc_channel_stack_builder* builder) { + grpc_transport* t = grpc_channel_stack_builder_get_transport(builder); return t != NULL && strstr(t->vtable->name, "http"); } -static bool maybe_add_optional_filter(grpc_exec_ctx *exec_ctx, - grpc_channel_stack_builder *builder, - void *arg) { +static bool maybe_add_optional_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, + void* arg) { if (!is_building_http_like_transport(builder)) return true; - optional_filter *filtarg = (optional_filter *)arg; - const grpc_channel_args *channel_args = + optional_filter* filtarg = (optional_filter*)arg; + const grpc_channel_args* channel_args = grpc_channel_stack_builder_get_channel_arguments(builder); bool enable = grpc_channel_arg_get_bool( grpc_channel_args_find(channel_args, filtarg->control_channel_arg), @@ -55,12 +55,12 @@ static bool maybe_add_optional_filter(grpc_exec_ctx *exec_ctx, : true; } -static bool maybe_add_required_filter(grpc_exec_ctx *exec_ctx, - grpc_channel_stack_builder *builder, - void *arg) { +static bool maybe_add_required_filter(grpc_exec_ctx* exec_ctx, + grpc_channel_stack_builder* builder, + void* arg) { return is_building_http_like_transport(builder) ? grpc_channel_stack_builder_prepend_filter( - builder, (const grpc_channel_filter *)arg, NULL, NULL) + builder, (const grpc_channel_filter*)arg, NULL, NULL) : true; } @@ -77,13 +77,13 @@ extern "C" void grpc_http_filters_init(void) { maybe_add_optional_filter, &compress_filter); grpc_channel_init_register_stage( GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_required_filter, (void *)&grpc_http_client_filter); + maybe_add_required_filter, (void*)&grpc_http_client_filter); grpc_channel_init_register_stage( GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_required_filter, (void *)&grpc_http_client_filter); + maybe_add_required_filter, (void*)&grpc_http_client_filter); grpc_channel_init_register_stage( GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_required_filter, (void *)&grpc_http_server_filter); + maybe_add_required_filter, (void*)&grpc_http_server_filter); } extern "C" void grpc_http_filters_shutdown(void) {} diff --git a/src/core/ext/filters/http/message_compress/message_compress_filter.cc b/src/core/ext/filters/http/message_compress/message_compress_filter.cc index f785e1355d..949ff917d6 100644 --- a/src/core/ext/filters/http/message_compress/message_compress_filter.cc +++ b/src/core/ext/filters/http/message_compress/message_compress_filter.cc @@ -45,7 +45,7 @@ typedef enum { } initial_metadata_state; typedef struct call_data { - grpc_call_combiner *call_combiner; + grpc_call_combiner* call_combiner; grpc_linked_mdelem compression_algorithm_storage; grpc_linked_mdelem stream_compression_algorithm_storage; grpc_linked_mdelem accept_encoding_storage; @@ -54,12 +54,12 @@ typedef struct call_data { * metadata, or by the channel's default compression settings. */ grpc_compression_algorithm compression_algorithm; initial_metadata_state send_initial_metadata_state; - grpc_error *cancel_error; + grpc_error* cancel_error; grpc_closure start_send_message_batch_in_call_combiner; - grpc_transport_stream_op_batch *send_message_batch; + grpc_transport_stream_op_batch* send_message_batch; grpc_slice_buffer slices; /**< Buffers up input slices to be compressed */ grpc_slice_buffer_stream replacement_stream; - grpc_closure *original_send_message_on_complete; + grpc_closure* original_send_message_on_complete; grpc_closure send_message_on_complete; grpc_closure on_send_message_next_done; } call_data; @@ -80,10 +80,10 @@ typedef struct channel_data { uint32_t supported_stream_compression_algorithms; } channel_data; -static bool skip_compression(grpc_call_element *elem, uint32_t flags, +static bool skip_compression(grpc_call_element* elem, uint32_t flags, bool has_compression_algorithm) { - call_data *calld = (call_data *)elem->call_data; - channel_data *channeld = (channel_data *)elem->channel_data; + call_data* calld = (call_data*)elem->call_data; + channel_data* channeld = (channel_data*)elem->channel_data; if (flags & (GRPC_WRITE_NO_COMPRESS | GRPC_WRITE_INTERNAL_COMPRESS)) { return true; @@ -99,15 +99,15 @@ static bool skip_compression(grpc_call_element *elem, uint32_t flags, } /** Filter initial metadata */ -static grpc_error *process_send_initial_metadata( - grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_metadata_batch *initial_metadata, - bool *has_compression_algorithm) GRPC_MUST_USE_RESULT; -static grpc_error *process_send_initial_metadata( - grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_metadata_batch *initial_metadata, bool *has_compression_algorithm) { - call_data *calld = (call_data *)elem->call_data; - channel_data *channeld = (channel_data *)elem->channel_data; +static grpc_error* process_send_initial_metadata( + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_metadata_batch* initial_metadata, + bool* has_compression_algorithm) GRPC_MUST_USE_RESULT; +static grpc_error* process_send_initial_metadata( + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_metadata_batch* initial_metadata, bool* has_compression_algorithm) { + call_data* calld = (call_data*)elem->call_data; + channel_data* channeld = (channel_data*)elem->channel_data; *has_compression_algorithm = false; grpc_stream_compression_algorithm stream_compression_algorithm = GRPC_STREAM_COMPRESS_NONE; @@ -117,7 +117,7 @@ static grpc_error *process_send_initial_metadata( initial_metadata->idx.named.grpc_internal_stream_encoding_request->md; if (!grpc_stream_compression_algorithm_parse( GRPC_MDVALUE(md), &stream_compression_algorithm)) { - char *val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); + char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log(GPR_ERROR, "Invalid stream compression algorithm: '%s' (unknown). Ignoring.", val); @@ -126,7 +126,7 @@ static grpc_error *process_send_initial_metadata( } if (!GPR_BITGET(channeld->enabled_stream_compression_algorithms_bitset, stream_compression_algorithm)) { - char *val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); + char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log( GPR_ERROR, "Invalid stream compression algorithm: '%s' (previously disabled). " @@ -152,7 +152,7 @@ static grpc_error *process_send_initial_metadata( initial_metadata->idx.named.grpc_internal_encoding_request->md; if (!grpc_compression_algorithm_parse(GRPC_MDVALUE(md), &calld->compression_algorithm)) { - char *val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); + char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s' (unknown). Ignoring.", val); gpr_free(val); @@ -177,7 +177,7 @@ static grpc_error *process_send_initial_metadata( *has_compression_algorithm = true; } - grpc_error *error = GRPC_ERROR_NONE; + grpc_error* error = GRPC_ERROR_NONE; /* hint compression algorithm */ if (stream_compression_algorithm != GRPC_STREAM_COMPRESS_NONE) { error = grpc_metadata_batch_add_tail( @@ -211,30 +211,30 @@ static grpc_error *process_send_initial_metadata( return error; } -static void send_message_on_complete(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_call_element *elem = (grpc_call_element *)arg; - call_data *calld = (call_data *)elem->call_data; +static void send_message_on_complete(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_call_element* elem = (grpc_call_element*)arg; + call_data* calld = (call_data*)elem->call_data; grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &calld->slices); GRPC_CLOSURE_RUN(exec_ctx, calld->original_send_message_on_complete, GRPC_ERROR_REF(error)); } -static void send_message_batch_continue(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) { - call_data *calld = (call_data *)elem->call_data; +static void send_message_batch_continue(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { + call_data* calld = (call_data*)elem->call_data; // Note: The call to grpc_call_next_op() results in yielding the // call combiner, so we need to clear calld->send_message_batch // before we do that. - grpc_transport_stream_op_batch *send_message_batch = + grpc_transport_stream_op_batch* send_message_batch = calld->send_message_batch; calld->send_message_batch = NULL; grpc_call_next_op(exec_ctx, elem, send_message_batch); } -static void finish_send_message(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) { - call_data *calld = (call_data *)elem->call_data; +static void finish_send_message(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { + call_data* calld = (call_data*)elem->call_data; // Compress the data if appropriate. grpc_slice_buffer tmp; grpc_slice_buffer_init(&tmp); @@ -244,21 +244,22 @@ static void finish_send_message(grpc_exec_ctx *exec_ctx, &calld->slices, &tmp); if (did_compress) { if (GRPC_TRACER_ON(grpc_compression_trace)) { - const char *algo_name; + const char* algo_name; const size_t before_size = calld->slices.length; const size_t after_size = tmp.length; const float savings_ratio = 1.0f - (float)after_size / (float)before_size; GPR_ASSERT(grpc_compression_algorithm_name(calld->compression_algorithm, &algo_name)); - gpr_log(GPR_DEBUG, "Compressed[%s] %" PRIuPTR " bytes vs. %" PRIuPTR - " bytes (%.2f%% savings)", + gpr_log(GPR_DEBUG, + "Compressed[%s] %" PRIuPTR " bytes vs. %" PRIuPTR + " bytes (%.2f%% savings)", algo_name, before_size, after_size, 100 * savings_ratio); } grpc_slice_buffer_swap(&calld->slices, &tmp); send_flags |= GRPC_WRITE_INTERNAL_COMPRESS; } else { if (GRPC_TRACER_ON(grpc_compression_trace)) { - const char *algo_name; + const char* algo_name; GPR_ASSERT(grpc_compression_algorithm_name(calld->compression_algorithm, &algo_name)); gpr_log(GPR_DEBUG, @@ -282,10 +283,10 @@ static void finish_send_message(grpc_exec_ctx *exec_ctx, send_message_batch_continue(exec_ctx, elem); } -static void fail_send_message_batch_in_call_combiner(grpc_exec_ctx *exec_ctx, - void *arg, - grpc_error *error) { - call_data *calld = (call_data *)arg; +static void fail_send_message_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, + void* arg, + grpc_error* error) { + call_data* calld = (call_data*)arg; if (calld->send_message_batch != NULL) { grpc_transport_stream_op_batch_finish_with_failure( exec_ctx, calld->send_message_batch, GRPC_ERROR_REF(error), @@ -295,10 +296,10 @@ static void fail_send_message_batch_in_call_combiner(grpc_exec_ctx *exec_ctx, } // Pulls a slice from the send_message byte stream and adds it to calld->slices. -static grpc_error *pull_slice_from_send_message(grpc_exec_ctx *exec_ctx, - call_data *calld) { +static grpc_error* pull_slice_from_send_message(grpc_exec_ctx* exec_ctx, + call_data* calld) { grpc_slice incoming_slice; - grpc_error *error = grpc_byte_stream_pull( + grpc_error* error = grpc_byte_stream_pull( exec_ctx, calld->send_message_batch->payload->send_message.send_message, &incoming_slice); if (error == GRPC_ERROR_NONE) { @@ -311,13 +312,13 @@ static grpc_error *pull_slice_from_send_message(grpc_exec_ctx *exec_ctx, // If all data has been read, invokes finish_send_message(). Otherwise, // an async call to grpc_byte_stream_next() has been started, which will // eventually result in calling on_send_message_next_done(). -static void continue_reading_send_message(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) { - call_data *calld = (call_data *)elem->call_data; +static void continue_reading_send_message(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem) { + call_data* calld = (call_data*)elem->call_data; while (grpc_byte_stream_next( exec_ctx, calld->send_message_batch->payload->send_message.send_message, ~(size_t)0, &calld->on_send_message_next_done)) { - grpc_error *error = pull_slice_from_send_message(exec_ctx, calld); + grpc_error* error = pull_slice_from_send_message(exec_ctx, calld); if (error != GRPC_ERROR_NONE) { // Closure callback; does not take ownership of error. fail_send_message_batch_in_call_combiner(exec_ctx, calld, error); @@ -333,10 +334,10 @@ static void continue_reading_send_message(grpc_exec_ctx *exec_ctx, } // Async callback for grpc_byte_stream_next(). -static void on_send_message_next_done(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_call_element *elem = (grpc_call_element *)arg; - call_data *calld = (call_data *)elem->call_data; +static void on_send_message_next_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_call_element* elem = (grpc_call_element*)arg; + call_data* calld = (call_data*)elem->call_data; if (error != GRPC_ERROR_NONE) { // Closure callback; does not take ownership of error. fail_send_message_batch_in_call_combiner(exec_ctx, calld, error); @@ -357,10 +358,10 @@ static void on_send_message_next_done(grpc_exec_ctx *exec_ctx, void *arg, } } -static void start_send_message_batch(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *unused) { - grpc_call_element *elem = (grpc_call_element *)arg; - call_data *calld = (call_data *)elem->call_data; +static void start_send_message_batch(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* unused) { + grpc_call_element* elem = (grpc_call_element*)arg; + call_data* calld = (call_data*)elem->call_data; if (skip_compression( elem, calld->send_message_batch->payload->send_message.send_message->flags, @@ -372,9 +373,9 @@ static void start_send_message_batch(grpc_exec_ctx *exec_ctx, void *arg, } static void compress_start_transport_stream_op_batch( - grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_transport_stream_op_batch *batch) { - call_data *calld = (call_data *)elem->call_data; + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* batch) { + call_data* calld = (call_data*)elem->call_data; GPR_TIMER_BEGIN("compress_start_transport_stream_op_batch", 0); // Handle cancel_stream. if (batch->cancel_stream) { @@ -405,7 +406,7 @@ static void compress_start_transport_stream_op_batch( if (batch->send_initial_metadata) { GPR_ASSERT(calld->send_initial_metadata_state == INITIAL_METADATA_UNSEEN); bool has_compression_algorithm; - grpc_error *error = process_send_initial_metadata( + grpc_error* error = process_send_initial_metadata( exec_ctx, elem, batch->payload->send_initial_metadata.send_initial_metadata, &has_compression_algorithm); @@ -453,10 +454,10 @@ done: } /* Constructor for call_data */ -static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_element_args *args) { - call_data *calld = (call_data *)elem->call_data; +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + const grpc_call_element_args* args) { + call_data* calld = (call_data*)elem->call_data; calld->call_combiner = args->call_combiner; calld->cancel_error = GRPC_ERROR_NONE; grpc_slice_buffer_init(&calld->slices); @@ -470,19 +471,19 @@ static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_final_info *final_info, - grpc_closure *ignored) { - call_data *calld = (call_data *)elem->call_data; +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* ignored) { + call_data* calld = (call_data*)elem->call_data; grpc_slice_buffer_destroy_internal(exec_ctx, &calld->slices); GRPC_ERROR_UNREF(calld->cancel_error); } /* Constructor for channel_data */ -static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_channel_element_args *args) { - channel_data *channeld = (channel_data *)elem->channel_data; +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + grpc_channel_element_args* args) { + channel_data* channeld = (channel_data*)elem->channel_data; /* Configuration for message compression */ channeld->enabled_algorithms_bitset = @@ -530,8 +531,8 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} const grpc_channel_filter grpc_message_compress_filter = { compress_start_transport_stream_op_batch, diff --git a/src/core/ext/filters/http/message_compress/message_compress_filter.h b/src/core/ext/filters/http/message_compress/message_compress_filter.h index 92771d9858..79a2815655 100644 --- a/src/core/ext/filters/http/message_compress/message_compress_filter.h +++ b/src/core/ext/filters/http/message_compress/message_compress_filter.h @@ -56,4 +56,4 @@ extern const grpc_channel_filter grpc_message_compress_filter; #endif #endif /* GRPC_CORE_EXT_FILTERS_HTTP_MESSAGE_COMPRESS_MESSAGE_COMPRESS_FILTER_H \ - */ + */ diff --git a/src/core/ext/filters/http/server/http_server_filter.cc b/src/core/ext/filters/http/server/http_server_filter.cc index 03958136b4..5cfe5acced 100644 --- a/src/core/ext/filters/http/server/http_server_filter.cc +++ b/src/core/ext/filters/http/server/http_server_filter.cc @@ -32,7 +32,7 @@ #define EXPECTED_CONTENT_TYPE_LENGTH sizeof(EXPECTED_CONTENT_TYPE) - 1 typedef struct call_data { - grpc_call_combiner *call_combiner; + grpc_call_combiner* call_combiner; grpc_linked_mdelem status; grpc_linked_mdelem content_type; @@ -42,15 +42,15 @@ typedef struct call_data { /* flag to ensure payload_bin is delivered only once */ bool payload_bin_delivered; - grpc_metadata_batch *recv_initial_metadata; - uint32_t *recv_initial_metadata_flags; + grpc_metadata_batch* recv_initial_metadata; + uint32_t* recv_initial_metadata_flags; /** Closure to call when finished with the hs_on_recv hook */ - grpc_closure *on_done_recv; + grpc_closure* on_done_recv; /** Closure to call when we retrieve read message from the path URI */ - grpc_closure *recv_message_ready; - grpc_closure *on_complete; - grpc_byte_stream **pp_recv_message; + grpc_closure* recv_message_ready; + grpc_closure* on_complete; + grpc_byte_stream** pp_recv_message; grpc_slice_buffer read_slice_buffer; grpc_slice_buffer_stream read_stream; @@ -62,11 +62,13 @@ typedef struct call_data { grpc_closure hs_recv_message_ready; } call_data; -typedef struct channel_data { uint8_t unused; } channel_data; +typedef struct channel_data { + uint8_t unused; +} channel_data; -static grpc_error *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_metadata_batch *b) { +static grpc_error* server_filter_outgoing_metadata(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_metadata_batch* b) { if (b->idx.named.grpc_message != NULL) { grpc_slice pct_encoded_msg = grpc_percent_encode_slice( GRPC_MDVALUE(b->idx.named.grpc_message->md), @@ -82,8 +84,8 @@ static grpc_error *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -static void add_error(const char *error_name, grpc_error **cumulative, - grpc_error *new_err) { +static void add_error(const char* error_name, grpc_error** cumulative, + grpc_error* new_err) { if (new_err == GRPC_ERROR_NONE) return; if (*cumulative == GRPC_ERROR_NONE) { *cumulative = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_name); @@ -91,12 +93,12 @@ static void add_error(const char *error_name, grpc_error **cumulative, *cumulative = grpc_error_add_child(*cumulative, new_err); } -static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_metadata_batch *b) { - call_data *calld = (call_data *)elem->call_data; - grpc_error *error = GRPC_ERROR_NONE; - static const char *error_name = "Failed processing incoming headers"; +static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_metadata_batch* b) { + call_data* calld = (call_data*)elem->call_data; + grpc_error* error = GRPC_ERROR_NONE; + static const char* error_name = "Failed processing incoming headers"; if (b->idx.named.method != NULL) { if (grpc_mdelem_eq(b->idx.named.method->md, GRPC_MDELEM_METHOD_POST)) { @@ -183,7 +185,7 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, } else { /* TODO(klempner): We're currently allowing this, but we shouldn't see it without a proxy so log for now. */ - char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.content_type->md), + char* val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.content_type->md), GPR_DUMP_ASCII); gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); gpr_free(val); @@ -203,7 +205,7 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, * query parameter which is base64 encoded request payload. */ const char k_query_separator = '?'; grpc_slice path_slice = GRPC_MDVALUE(b->idx.named.path->md); - uint8_t *path_ptr = (uint8_t *)GRPC_SLICE_START_PTR(path_slice); + uint8_t* path_ptr = (uint8_t*)GRPC_SLICE_START_PTR(path_slice); size_t path_length = GRPC_SLICE_LENGTH(path_slice); /* offset of the character '?' */ size_t offset = 0; @@ -226,7 +228,7 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, grpc_slice_buffer_add( &calld->read_slice_buffer, grpc_base64_decode_with_len( - exec_ctx, (const char *)GRPC_SLICE_START_PTR(query_slice), + exec_ctx, (const char*)GRPC_SLICE_START_PTR(query_slice), GRPC_SLICE_LENGTH(query_slice), k_url_safe)); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); @@ -238,15 +240,15 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, } if (b->idx.named.host != NULL && b->idx.named.authority == NULL) { - grpc_linked_mdelem *el = b->idx.named.host; + grpc_linked_mdelem* el = b->idx.named.host; grpc_mdelem md = GRPC_MDELEM_REF(el->md); grpc_metadata_batch_remove(exec_ctx, b, el); - add_error( - error_name, &error, - grpc_metadata_batch_add_head( - exec_ctx, b, el, grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_ref_internal(GRPC_MDVALUE(md))))); + add_error(error_name, &error, + grpc_metadata_batch_add_head( + exec_ctx, b, el, + grpc_mdelem_from_slices( + exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_slice_ref_internal(GRPC_MDVALUE(md))))); GRPC_MDELEM_UNREF(exec_ctx, md); } @@ -261,10 +263,10 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, return error; } -static void hs_on_recv(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_error *err) { - grpc_call_element *elem = (grpc_call_element *)user_data; - call_data *calld = (call_data *)elem->call_data; +static void hs_on_recv(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* err) { + grpc_call_element* elem = (grpc_call_element*)user_data; + call_data* calld = (call_data*)elem->call_data; if (err == GRPC_ERROR_NONE) { err = server_filter_incoming_metadata(exec_ctx, elem, calld->recv_initial_metadata); @@ -274,15 +276,15 @@ static void hs_on_recv(grpc_exec_ctx *exec_ctx, void *user_data, GRPC_CLOSURE_RUN(exec_ctx, calld->on_done_recv, err); } -static void hs_on_complete(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_error *err) { - grpc_call_element *elem = (grpc_call_element *)user_data; - call_data *calld = (call_data *)elem->call_data; +static void hs_on_complete(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* err) { + grpc_call_element* elem = (grpc_call_element*)user_data; + call_data* calld = (call_data*)elem->call_data; /* Call recv_message_ready if we got the payload via the path field */ if (calld->seen_path_with_query && calld->recv_message_ready != NULL) { *calld->pp_recv_message = calld->payload_bin_delivered ? NULL - : (grpc_byte_stream *)&calld->read_stream; + : (grpc_byte_stream*)&calld->read_stream; // Re-enter call combiner for recv_message_ready, since the surface // code will release the call combiner for each callback it receives. GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, @@ -294,10 +296,10 @@ static void hs_on_complete(grpc_exec_ctx *exec_ctx, void *user_data, GRPC_CLOSURE_RUN(exec_ctx, calld->on_complete, GRPC_ERROR_REF(err)); } -static void hs_recv_message_ready(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_error *err) { - grpc_call_element *elem = (grpc_call_element *)user_data; - call_data *calld = (call_data *)elem->call_data; +static void hs_recv_message_ready(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* err) { + grpc_call_element* elem = (grpc_call_element*)user_data; + call_data* calld = (call_data*)elem->call_data; if (calld->seen_path_with_query) { // Do nothing. This is probably a GET request, and payload will be // returned in hs_on_complete callback. @@ -310,15 +312,15 @@ static void hs_recv_message_ready(grpc_exec_ctx *exec_ctx, void *user_data, } } -static grpc_error *hs_mutate_op(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_transport_stream_op_batch *op) { +static grpc_error* hs_mutate_op(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { /* grab pointers to our data from the call element */ - call_data *calld = (call_data *)elem->call_data; + call_data* calld = (call_data*)elem->call_data; if (op->send_initial_metadata) { - grpc_error *error = GRPC_ERROR_NONE; - static const char *error_name = "Failed sending initial metadata"; + grpc_error* error = GRPC_ERROR_NONE; + static const char* error_name = "Failed sending initial metadata"; add_error( error_name, &error, grpc_metadata_batch_add_head( @@ -364,7 +366,7 @@ static grpc_error *hs_mutate_op(grpc_exec_ctx *exec_ctx, } if (op->send_trailing_metadata) { - grpc_error *error = server_filter_outgoing_metadata( + grpc_error* error = server_filter_outgoing_metadata( exec_ctx, elem, op->payload->send_trailing_metadata.send_trailing_metadata); if (error != GRPC_ERROR_NONE) return error; @@ -374,11 +376,11 @@ static grpc_error *hs_mutate_op(grpc_exec_ctx *exec_ctx, } static void hs_start_transport_stream_op_batch( - grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_transport_stream_op_batch *op) { - call_data *calld = (call_data *)elem->call_data; + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { + call_data* calld = (call_data*)elem->call_data; GPR_TIMER_BEGIN("hs_start_transport_stream_op_batch", 0); - grpc_error *error = hs_mutate_op(exec_ctx, elem, op); + grpc_error* error = hs_mutate_op(exec_ctx, elem, op); if (error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure(exec_ctx, op, error, calld->call_combiner); @@ -389,11 +391,11 @@ static void hs_start_transport_stream_op_batch( } /* Constructor for call_data */ -static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_element_args *args) { +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + const grpc_call_element_args* args) { /* grab pointers to our data from the call element */ - call_data *calld = (call_data *)elem->call_data; + call_data* calld = (call_data*)elem->call_data; /* initialize members */ calld->call_combiner = args->call_combiner; GRPC_CLOSURE_INIT(&calld->hs_on_recv, hs_on_recv, elem, @@ -407,24 +409,24 @@ static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_final_info *final_info, - grpc_closure *ignored) { - call_data *calld = (call_data *)elem->call_data; +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* ignored) { + call_data* calld = (call_data*)elem->call_data; grpc_slice_buffer_destroy_internal(exec_ctx, &calld->read_slice_buffer); } /* Constructor for channel_data */ -static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_channel_element_args *args) { +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); return GRPC_ERROR_NONE; } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem) {} +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) {} const grpc_channel_filter grpc_http_server_filter = { hs_start_transport_stream_op_batch, diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc index ca8a3b2a13..77b086c324 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc @@ -43,21 +43,21 @@ typedef struct call_data { /* stores the recv_initial_metadata op's ready closure, which we wrap with our * own (on_initial_md_ready) in order to capture the incoming initial metadata * */ - grpc_closure *ops_recv_initial_metadata_ready; + grpc_closure* ops_recv_initial_metadata_ready; /* to get notified of the availability of the incoming initial metadata. */ grpc_closure on_initial_md_ready; - grpc_metadata_batch *recv_initial_metadata; + grpc_metadata_batch* recv_initial_metadata; } call_data; typedef struct channel_data { intptr_t id; /**< an id unique to the channel */ } channel_data; -static void on_initial_md_ready(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_error *err) { - grpc_call_element *elem = (grpc_call_element *)user_data; - call_data *calld = (call_data *)elem->call_data; +static void on_initial_md_ready(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_error* err) { + grpc_call_element* elem = (grpc_call_element*)user_data; + call_data* calld = (call_data*)elem->call_data; if (err == GRPC_ERROR_NONE) { if (calld->recv_initial_metadata->idx.named.path != NULL) { @@ -85,10 +85,10 @@ static void on_initial_md_ready(grpc_exec_ctx *exec_ctx, void *user_data, } /* Constructor for call_data */ -static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_element_args *args) { - call_data *calld = (call_data *)elem->call_data; +static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, + grpc_call_element* elem, + const grpc_call_element_args* args) { + call_data* calld = (call_data*)elem->call_data; calld->id = (intptr_t)args->call_stack; GRPC_CLOSURE_INIT(&calld->on_initial_md_ready, on_initial_md_ready, elem, grpc_schedule_on_exec_ctx); @@ -108,10 +108,10 @@ static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, } /* Destructor for call_data */ -static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const grpc_call_final_info *final_info, - grpc_closure *ignored) { - call_data *calld = (call_data *)elem->call_data; +static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* ignored) { + call_data* calld = (call_data*)elem->call_data; /* TODO(dgq): do something with the data channel_data *chand = elem->channel_data; @@ -136,12 +136,12 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, } /* Constructor for channel_data */ -static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_channel_element_args *args) { +static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem, + grpc_channel_element_args* args) { GPR_ASSERT(!args->is_last); - channel_data *chand = (channel_data *)elem->channel_data; + channel_data* chand = (channel_data*)elem->channel_data; chand->id = (intptr_t)args->channel_stack; /* TODO(dgq): do something with the data @@ -158,8 +158,8 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, } /* Destructor for channel data */ -static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem) { +static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, + grpc_channel_element* elem) { /* TODO(dgq): do something with the data channel_data *chand = elem->channel_data; grpc_load_reporting_call_data lr_call_data = { @@ -173,11 +173,11 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, */ } -static grpc_filtered_mdelem lr_trailing_md_filter(grpc_exec_ctx *exec_ctx, - void *user_data, +static grpc_filtered_mdelem lr_trailing_md_filter(grpc_exec_ctx* exec_ctx, + void* user_data, grpc_mdelem md) { - grpc_call_element *elem = (grpc_call_element *)user_data; - call_data *calld = (call_data *)elem->call_data; + grpc_call_element* elem = (grpc_call_element*)user_data; + call_data* calld = (call_data*)elem->call_data; if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_LB_COST_BIN)) { calld->trailing_md_string = GRPC_MDVALUE(md); return GRPC_FILTERED_REMOVE(); @@ -186,10 +186,10 @@ static grpc_filtered_mdelem lr_trailing_md_filter(grpc_exec_ctx *exec_ctx, } static void lr_start_transport_stream_op_batch( - grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_transport_stream_op_batch *op) { + grpc_exec_ctx* exec_ctx, grpc_call_element* elem, + grpc_transport_stream_op_batch* op) { GPR_TIMER_BEGIN("lr_start_transport_stream_op_batch", 0); - call_data *calld = (call_data *)elem->call_data; + call_data* calld = (call_data*)elem->call_data; if (op->recv_initial_metadata) { /* substitute our callback for the higher callback */ diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_filter.h b/src/core/ext/filters/load_reporting/server_load_reporting_filter.h index 94d19cc249..356f8b8e66 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_filter.h +++ b/src/core/ext/filters/load_reporting/server_load_reporting_filter.h @@ -33,4 +33,4 @@ extern const grpc_channel_filter grpc_server_load_reporting_filter; #endif #endif /* GRPC_CORE_EXT_FILTERS_LOAD_REPORTING_SERVER_LOAD_REPORTING_FILTER_H \ - */ + */ diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc index 223fb3ee8b..b26cbe3579 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc @@ -32,17 +32,17 @@ #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/channel_init.h" -static bool is_load_reporting_enabled(const grpc_channel_args *a) { +static bool is_load_reporting_enabled(const grpc_channel_args* a) { return grpc_channel_arg_get_bool( grpc_channel_args_find(a, GRPC_ARG_ENABLE_LOAD_REPORTING), false); } static bool maybe_add_server_load_reporting_filter( - grpc_exec_ctx *exec_ctx, grpc_channel_stack_builder *builder, void *arg) { - const grpc_channel_args *args = + grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { + const grpc_channel_args* args = grpc_channel_stack_builder_get_channel_arguments(builder); - const grpc_channel_filter *filter = (const grpc_channel_filter *)arg; - grpc_channel_stack_builder_iterator *it = + const grpc_channel_filter* filter = (const grpc_channel_filter*)arg; + grpc_channel_stack_builder_iterator* it = grpc_channel_stack_builder_iterator_find(builder, filter->name); const bool already_has_load_reporting_filter = !grpc_channel_stack_builder_iterator_is_end(it); @@ -55,7 +55,7 @@ static bool maybe_add_server_load_reporting_filter( } grpc_arg grpc_load_reporting_enable_arg() { - return grpc_channel_arg_integer_create((char *)GRPC_ARG_ENABLE_LOAD_REPORTING, + return grpc_channel_arg_integer_create((char*)GRPC_ARG_ENABLE_LOAD_REPORTING, 1); } @@ -64,7 +64,7 @@ grpc_arg grpc_load_reporting_enable_arg() { extern "C" void grpc_server_load_reporting_plugin_init(void) { grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, maybe_add_server_load_reporting_filter, - (void *)&grpc_server_load_reporting_filter); + (void*)&grpc_server_load_reporting_filter); } extern "C" void grpc_server_load_reporting_plugin_shutdown() {} diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.h b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.h index 65e254eb53..a6448ce97e 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.h +++ b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.h @@ -49,11 +49,11 @@ typedef struct grpc_load_reporting_call_data { /** Only valid when \a source is \a GRPC_LR_POINT_CALL_DESTRUCTION, that is, * once the call has completed */ - const grpc_call_final_info *final_info; + const grpc_call_final_info* final_info; - const char *initial_md_string; /**< value string for LR's initial md key */ - const char *trailing_md_string; /**< value string for LR's trailing md key */ - const char *method_name; /**< Corresponds to :path header */ + const char* initial_md_string; /**< value string for LR's initial md key */ + const char* trailing_md_string; /**< value string for LR's trailing md key */ + const char* method_name; /**< Corresponds to :path header */ } grpc_load_reporting_call_data; /** Return a \a grpc_arg enabling load reporting */ @@ -64,4 +64,4 @@ grpc_arg grpc_load_reporting_enable_arg(); #endif #endif /* GRPC_CORE_EXT_FILTERS_LOAD_REPORTING_SERVER_LOAD_REPORTING_PLUGIN_H \ - */ + */ diff --git a/src/core/ext/filters/workarounds/workaround_utils.cc b/src/core/ext/filters/workarounds/workaround_utils.cc index e600fbee67..9db42fbeee 100644 --- a/src/core/ext/filters/workarounds/workaround_utils.cc +++ b/src/core/ext/filters/workarounds/workaround_utils.cc @@ -21,26 +21,26 @@ user_agent_parser ua_parser[GRPC_MAX_WORKAROUND_ID]; -static void destroy_user_agent_md(void *user_agent_md) { +static void destroy_user_agent_md(void* user_agent_md) { gpr_free(user_agent_md); } -grpc_workaround_user_agent_md *grpc_parse_user_agent(grpc_mdelem md) { - grpc_workaround_user_agent_md *user_agent_md = - (grpc_workaround_user_agent_md *)grpc_mdelem_get_user_data( +grpc_workaround_user_agent_md* grpc_parse_user_agent(grpc_mdelem md) { + grpc_workaround_user_agent_md* user_agent_md = + (grpc_workaround_user_agent_md*)grpc_mdelem_get_user_data( md, destroy_user_agent_md); if (NULL != user_agent_md) { return user_agent_md; } - user_agent_md = (grpc_workaround_user_agent_md *)gpr_malloc( + user_agent_md = (grpc_workaround_user_agent_md*)gpr_malloc( sizeof(grpc_workaround_user_agent_md)); for (int i = 0; i < GRPC_MAX_WORKAROUND_ID; i++) { if (ua_parser[i]) { user_agent_md->workaround_active[i] = ua_parser[i](md); } } - grpc_mdelem_set_user_data(md, destroy_user_agent_md, (void *)user_agent_md); + grpc_mdelem_set_user_data(md, destroy_user_agent_md, (void*)user_agent_md); return user_agent_md; } diff --git a/src/core/ext/filters/workarounds/workaround_utils.h b/src/core/ext/filters/workarounds/workaround_utils.h index 3913cae6b2..a954ad4001 100644 --- a/src/core/ext/filters/workarounds/workaround_utils.h +++ b/src/core/ext/filters/workarounds/workaround_utils.h @@ -32,7 +32,7 @@ typedef struct grpc_workaround_user_agent_md { bool workaround_active[GRPC_MAX_WORKAROUND_ID]; } grpc_workaround_user_agent_md; -grpc_workaround_user_agent_md *grpc_parse_user_agent(grpc_mdelem md); +grpc_workaround_user_agent_md* grpc_parse_user_agent(grpc_mdelem md); typedef bool (*user_agent_parser)(grpc_mdelem); diff --git a/src/core/ext/transport/chttp2/alpn/alpn.cc b/src/core/ext/transport/chttp2/alpn/alpn.cc index ca2e801ec8..89892457d6 100644 --- a/src/core/ext/transport/chttp2/alpn/alpn.cc +++ b/src/core/ext/transport/chttp2/alpn/alpn.cc @@ -21,9 +21,9 @@ #include <grpc/support/useful.h> /* in order of preference */ -static const char *const supported_versions[] = {"grpc-exp", "h2"}; +static const char* const supported_versions[] = {"grpc-exp", "h2"}; -int grpc_chttp2_is_alpn_version_supported(const char *version, size_t size) { +int grpc_chttp2_is_alpn_version_supported(const char* version, size_t size) { size_t i; for (i = 0; i < GPR_ARRAY_SIZE(supported_versions); i++) { if (!strncmp(version, supported_versions[i], size)) return 1; @@ -35,7 +35,7 @@ size_t grpc_chttp2_num_alpn_versions(void) { return GPR_ARRAY_SIZE(supported_versions); } -const char *grpc_chttp2_get_alpn_version_index(size_t i) { +const char* grpc_chttp2_get_alpn_version_index(size_t i) { GPR_ASSERT(i < GPR_ARRAY_SIZE(supported_versions)); return supported_versions[i]; } diff --git a/src/core/ext/transport/chttp2/alpn/alpn.h b/src/core/ext/transport/chttp2/alpn/alpn.h index 99b928ea59..4a420e83e0 100644 --- a/src/core/ext/transport/chttp2/alpn/alpn.h +++ b/src/core/ext/transport/chttp2/alpn/alpn.h @@ -26,14 +26,14 @@ extern "C" { #endif /* Retuns 1 if the version is supported, 0 otherwise. */ -int grpc_chttp2_is_alpn_version_supported(const char *version, size_t size); +int grpc_chttp2_is_alpn_version_supported(const char* version, size_t size); /* Returns the number of protocol versions to advertise */ size_t grpc_chttp2_num_alpn_versions(void); /* Returns the protocol version at index i (0 <= i < * grpc_chttp2_num_alpn_versions()) */ -const char *grpc_chttp2_get_alpn_version_index(size_t i); +const char* grpc_chttp2_get_alpn_version_index(size_t i); #ifdef __cplusplus } diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.cc b/src/core/ext/transport/chttp2/client/chttp2_connector.cc index 74839f2156..6cd476f4ca 100644 --- a/src/core/ext/transport/chttp2/client/chttp2_connector.cc +++ b/src/core/ext/transport/chttp2/client/chttp2_connector.cc @@ -45,25 +45,25 @@ typedef struct { bool shutdown; bool connecting; - grpc_closure *notify; + grpc_closure* notify; grpc_connect_in_args args; - grpc_connect_out_args *result; + grpc_connect_out_args* result; - grpc_endpoint *endpoint; // Non-NULL until handshaking starts. + grpc_endpoint* endpoint; // Non-NULL until handshaking starts. grpc_closure connected; - grpc_handshake_manager *handshake_mgr; + grpc_handshake_manager* handshake_mgr; } chttp2_connector; -static void chttp2_connector_ref(grpc_connector *con) { - chttp2_connector *c = (chttp2_connector *)con; +static void chttp2_connector_ref(grpc_connector* con) { + chttp2_connector* c = (chttp2_connector*)con; gpr_ref(&c->refs); } -static void chttp2_connector_unref(grpc_exec_ctx *exec_ctx, - grpc_connector *con) { - chttp2_connector *c = (chttp2_connector *)con; +static void chttp2_connector_unref(grpc_exec_ctx* exec_ctx, + grpc_connector* con) { + chttp2_connector* c = (chttp2_connector*)con; if (gpr_unref(&c->refs)) { gpr_mu_destroy(&c->mu); // If handshaking is not yet in progress, destroy the endpoint. @@ -73,9 +73,9 @@ static void chttp2_connector_unref(grpc_exec_ctx *exec_ctx, } } -static void chttp2_connector_shutdown(grpc_exec_ctx *exec_ctx, - grpc_connector *con, grpc_error *why) { - chttp2_connector *c = (chttp2_connector *)con; +static void chttp2_connector_shutdown(grpc_exec_ctx* exec_ctx, + grpc_connector* con, grpc_error* why) { + chttp2_connector* c = (chttp2_connector*)con; gpr_mu_lock(&c->mu); c->shutdown = true; if (c->handshake_mgr != NULL) { @@ -91,10 +91,10 @@ static void chttp2_connector_shutdown(grpc_exec_ctx *exec_ctx, GRPC_ERROR_UNREF(why); } -static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_handshaker_args *args = (grpc_handshaker_args *)arg; - chttp2_connector *c = (chttp2_connector *)args->user_data; +static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_handshaker_args* args = (grpc_handshaker_args*)arg; + chttp2_connector* c = (chttp2_connector*)args->user_data; gpr_mu_lock(&c->mu); if (error != GRPC_ERROR_NONE || c->shutdown) { if (error == GRPC_ERROR_NONE) { @@ -124,17 +124,17 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, args->read_buffer); c->result->channel_args = args->args; } - grpc_closure *notify = c->notify; + grpc_closure* notify = c->notify; c->notify = NULL; GRPC_CLOSURE_SCHED(exec_ctx, notify, error); grpc_handshake_manager_destroy(exec_ctx, c->handshake_mgr); c->handshake_mgr = NULL; gpr_mu_unlock(&c->mu); - chttp2_connector_unref(exec_ctx, (grpc_connector *)c); + chttp2_connector_unref(exec_ctx, (grpc_connector*)c); } -static void start_handshake_locked(grpc_exec_ctx *exec_ctx, - chttp2_connector *c) { +static void start_handshake_locked(grpc_exec_ctx* exec_ctx, + chttp2_connector* c) { c->handshake_mgr = grpc_handshake_manager_create(); grpc_handshakers_add(exec_ctx, HANDSHAKER_CLIENT, c->args.channel_args, c->handshake_mgr); @@ -146,8 +146,8 @@ static void start_handshake_locked(grpc_exec_ctx *exec_ctx, c->endpoint = NULL; // Endpoint handed off to handshake manager. } -static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - chttp2_connector *c = (chttp2_connector *)arg; +static void connected(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + chttp2_connector* c = (chttp2_connector*)arg; gpr_mu_lock(&c->mu); GPR_ASSERT(c->connecting); c->connecting = false; @@ -158,14 +158,14 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { error = GRPC_ERROR_REF(error); } memset(c->result, 0, sizeof(*c->result)); - grpc_closure *notify = c->notify; + grpc_closure* notify = c->notify; c->notify = NULL; GRPC_CLOSURE_SCHED(exec_ctx, notify, error); if (c->endpoint != NULL) { grpc_endpoint_shutdown(exec_ctx, c->endpoint, GRPC_ERROR_REF(error)); } gpr_mu_unlock(&c->mu); - chttp2_connector_unref(exec_ctx, (grpc_connector *)arg); + chttp2_connector_unref(exec_ctx, (grpc_connector*)arg); } else { GPR_ASSERT(c->endpoint != NULL); start_handshake_locked(exec_ctx, c); @@ -173,12 +173,12 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { } } -static void chttp2_connector_connect(grpc_exec_ctx *exec_ctx, - grpc_connector *con, - const grpc_connect_in_args *args, - grpc_connect_out_args *result, - grpc_closure *notify) { - chttp2_connector *c = (chttp2_connector *)con; +static void chttp2_connector_connect(grpc_exec_ctx* exec_ctx, + grpc_connector* con, + const grpc_connect_in_args* args, + grpc_connect_out_args* result, + grpc_closure* notify) { + chttp2_connector* c = (chttp2_connector*)con; grpc_resolved_address addr; grpc_get_subchannel_address_arg(exec_ctx, args->channel_args, &addr); gpr_mu_lock(&c->mu); @@ -201,8 +201,8 @@ static const grpc_connector_vtable chttp2_connector_vtable = { chttp2_connector_ref, chttp2_connector_unref, chttp2_connector_shutdown, chttp2_connector_connect}; -grpc_connector *grpc_chttp2_connector_create() { - chttp2_connector *c = (chttp2_connector *)gpr_zalloc(sizeof(*c)); +grpc_connector* grpc_chttp2_connector_create() { + chttp2_connector* c = (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 6410a6043d..26c7f0debf 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -31,37 +31,37 @@ #include "src/core/lib/surface/channel.h" static void client_channel_factory_ref( - grpc_client_channel_factory *cc_factory) {} + grpc_client_channel_factory* cc_factory) {} static void client_channel_factory_unref( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory) {} + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory) {} -static grpc_subchannel *client_channel_factory_create_subchannel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, - const grpc_subchannel_args *args) { - grpc_connector *connector = grpc_chttp2_connector_create(); - grpc_subchannel *s = grpc_subchannel_create(exec_ctx, connector, args); +static grpc_subchannel* client_channel_factory_create_subchannel( + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, + const grpc_subchannel_args* args) { + grpc_connector* connector = grpc_chttp2_connector_create(); + grpc_subchannel* s = grpc_subchannel_create(exec_ctx, connector, args); grpc_connector_unref(exec_ctx, connector); return s; } -static grpc_channel *client_channel_factory_create_channel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, - const char *target, grpc_client_channel_type type, - const grpc_channel_args *args) { +static grpc_channel* client_channel_factory_create_channel( + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, + const char* target, grpc_client_channel_type type, + const grpc_channel_args* args) { if (target == NULL) { gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); return NULL; } // Add channel arg containing the server URI. grpc_arg arg = grpc_channel_arg_string_create( - (char *)GRPC_ARG_SERVER_URI, + (char*)GRPC_ARG_SERVER_URI, grpc_resolver_factory_add_default_prefix_if_needed(exec_ctx, target)); - const char *to_remove[] = {GRPC_ARG_SERVER_URI}; - grpc_channel_args *new_args = + 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(exec_ctx, target, new_args, + grpc_channel* channel = grpc_channel_create(exec_ctx, target, new_args, GRPC_CLIENT_CHANNEL, NULL); grpc_channel_args_destroy(exec_ctx, new_args); return channel; @@ -79,9 +79,9 @@ static grpc_client_channel_factory client_channel_factory = { Asynchronously: - resolve target - connect to it (trying alternatives as presented) - perform handshakes */ -grpc_channel *grpc_insecure_channel_create(const char *target, - const grpc_channel_args *args, - void *reserved) { +grpc_channel* grpc_insecure_channel_create(const char* target, + const grpc_channel_args* args, + void* reserved) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE( "grpc_insecure_channel_create(target=%s, args=%p, reserved=%p)", 3, @@ -90,15 +90,16 @@ grpc_channel *grpc_insecure_channel_create(const char *target, // Add channel arg containing the client channel factory. grpc_arg arg = grpc_client_channel_factory_create_channel_arg(&client_channel_factory); - grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1); + grpc_channel_args* new_args = grpc_channel_args_copy_and_add(args, &arg, 1); // Create channel. - grpc_channel *channel = client_channel_factory_create_channel( + grpc_channel* channel = client_channel_factory_create_channel( &exec_ctx, &client_channel_factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args); // Clean up. grpc_channel_args_destroy(&exec_ctx, new_args); grpc_exec_ctx_finish(&exec_ctx); - return channel != NULL ? channel : grpc_lame_client_channel_create( - target, GRPC_STATUS_INTERNAL, - "Failed to create client channel"); + return channel != NULL ? channel + : grpc_lame_client_channel_create( + target, GRPC_STATUS_INTERNAL, + "Failed to create client channel"); } diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc index dd88136f7b..0974a7c393 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc @@ -35,42 +35,43 @@ #include "src/core/lib/surface/channel.h" #include "src/core/lib/transport/transport.h" -grpc_channel *grpc_insecure_channel_create_from_fd( - const char *target, int fd, const grpc_channel_args *args) { +grpc_channel* grpc_insecure_channel_create_from_fd( + const char* target, int fd, const grpc_channel_args* args) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE("grpc_insecure_channel_create(target=%p, fd=%d, args=%p)", 3, (target, fd, args)); grpc_arg default_authority_arg = grpc_channel_arg_string_create( - (char *)GRPC_ARG_DEFAULT_AUTHORITY, (char *)"test.authority"); - grpc_channel_args *final_args = + (char*)GRPC_ARG_DEFAULT_AUTHORITY, (char*)"test.authority"); + grpc_channel_args* final_args = grpc_channel_args_copy_and_add(args, &default_authority_arg, 1); int flags = fcntl(fd, F_GETFL, 0); GPR_ASSERT(fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0); - grpc_endpoint *client = grpc_tcp_client_create_from_fd( + grpc_endpoint* client = grpc_tcp_client_create_from_fd( &exec_ctx, grpc_fd_create(fd, "client"), args, "fd-client"); - grpc_transport *transport = + grpc_transport* transport = grpc_create_chttp2_transport(&exec_ctx, final_args, client, 1); GPR_ASSERT(transport); - grpc_channel *channel = grpc_channel_create( + grpc_channel* channel = grpc_channel_create( &exec_ctx, target, final_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); grpc_channel_args_destroy(&exec_ctx, final_args); grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); grpc_exec_ctx_finish(&exec_ctx); - return channel != NULL ? channel : grpc_lame_client_channel_create( - target, GRPC_STATUS_INTERNAL, - "Failed to create client channel"); + return channel != NULL ? channel + : grpc_lame_client_channel_create( + target, GRPC_STATUS_INTERNAL, + "Failed to create client channel"); } #else // !GPR_SUPPORT_CHANNELS_FROM_FD -grpc_channel *grpc_insecure_channel_create_from_fd( - const char *target, int fd, const grpc_channel_args *args) { +grpc_channel* grpc_insecure_channel_create_from_fd( + const char* target, int fd, const grpc_channel_args* args) { GPR_ASSERT(0); return NULL; } 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 fe296cf4ff..68c1e1868c 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 @@ -38,14 +38,14 @@ #include "src/core/lib/surface/channel.h" static void client_channel_factory_ref( - grpc_client_channel_factory *cc_factory) {} + grpc_client_channel_factory* cc_factory) {} static void client_channel_factory_unref( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory) {} + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory) {} -static grpc_subchannel_args *get_secure_naming_subchannel_args( - grpc_exec_ctx *exec_ctx, const grpc_subchannel_args *args) { - grpc_channel_credentials *channel_credentials = +static grpc_subchannel_args* get_secure_naming_subchannel_args( + grpc_exec_ctx* exec_ctx, const grpc_subchannel_args* args) { + grpc_channel_credentials* channel_credentials = grpc_channel_credentials_find_in_args(args->args); if (channel_credentials == NULL) { gpr_log(GPR_ERROR, @@ -61,33 +61,33 @@ static grpc_subchannel_args *get_secure_naming_subchannel_args( return NULL; } // To which address are we connecting? By default, use the server URI. - const grpc_arg *server_uri_arg = + const grpc_arg* server_uri_arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_URI); GPR_ASSERT(server_uri_arg != NULL); GPR_ASSERT(server_uri_arg->type == GRPC_ARG_STRING); - const char *server_uri_str = server_uri_arg->value.string; + const char* server_uri_str = server_uri_arg->value.string; GPR_ASSERT(server_uri_str != NULL); - grpc_uri *server_uri = + grpc_uri* server_uri = grpc_uri_parse(exec_ctx, server_uri_str, true /* supress errors */); GPR_ASSERT(server_uri != NULL); - const char *server_uri_path; + const char* server_uri_path; server_uri_path = server_uri->path[0] == '/' ? server_uri->path + 1 : server_uri->path; - const grpc_slice_hash_table *targets_info = + const grpc_slice_hash_table* targets_info = grpc_lb_targets_info_find_in_args(args->args); - char *target_name_to_check = NULL; + char* target_name_to_check = NULL; if (targets_info != NULL) { // LB channel // Find the balancer name for the target. - const char *target_uri_str = + const char* target_uri_str = grpc_get_subchannel_address_uri_arg(args->args); - grpc_uri *target_uri = + grpc_uri* target_uri = grpc_uri_parse(exec_ctx, target_uri_str, false /* suppress errors */); GPR_ASSERT(target_uri != NULL); 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 = + (const char*)grpc_slice_hash_table_get(targets_info, key); if (value != NULL) target_name_to_check = gpr_strdup(value); grpc_slice_unref_internal(exec_ctx, key); } @@ -102,9 +102,9 @@ static grpc_subchannel_args *get_secure_naming_subchannel_args( } grpc_uri_destroy(server_uri); GPR_ASSERT(target_name_to_check != NULL); - grpc_channel_security_connector *subchannel_security_connector = NULL; + grpc_channel_security_connector* subchannel_security_connector = NULL; // Create the security connector using the credentials and target name. - grpc_channel_args *new_args_from_connector = NULL; + grpc_channel_args* new_args_from_connector = NULL; const grpc_security_status security_status = grpc_channel_credentials_create_security_connector( exec_ctx, channel_credentials, target_name_to_check, args->args, @@ -120,7 +120,7 @@ static grpc_subchannel_args *get_secure_naming_subchannel_args( grpc_arg new_security_connector_arg = grpc_security_connector_to_arg(&subchannel_security_connector->base); - grpc_channel_args *new_args = grpc_channel_args_copy_and_add( + grpc_channel_args* new_args = grpc_channel_args_copy_and_add( new_args_from_connector != NULL ? new_args_from_connector : args->args, &new_security_connector_arg, 1); GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &subchannel_security_connector->base, @@ -128,17 +128,17 @@ static grpc_subchannel_args *get_secure_naming_subchannel_args( if (new_args_from_connector != NULL) { grpc_channel_args_destroy(exec_ctx, new_args_from_connector); } - grpc_subchannel_args *final_sc_args = - (grpc_subchannel_args *)gpr_malloc(sizeof(*final_sc_args)); + grpc_subchannel_args* final_sc_args = + (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; } -static grpc_subchannel *client_channel_factory_create_subchannel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, - const grpc_subchannel_args *args) { - grpc_subchannel_args *subchannel_args = +static grpc_subchannel* client_channel_factory_create_subchannel( + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, + const grpc_subchannel_args* args) { + grpc_subchannel_args* subchannel_args = get_secure_naming_subchannel_args(exec_ctx, args); if (subchannel_args == NULL) { gpr_log( @@ -146,33 +146,33 @@ static grpc_subchannel *client_channel_factory_create_subchannel( "Failed to create subchannel arguments during subchannel creation."); return NULL; } - grpc_connector *connector = grpc_chttp2_connector_create(); - grpc_subchannel *s = + grpc_connector* connector = grpc_chttp2_connector_create(); + grpc_subchannel* s = grpc_subchannel_create(exec_ctx, connector, subchannel_args); grpc_connector_unref(exec_ctx, connector); grpc_channel_args_destroy(exec_ctx, - (grpc_channel_args *)subchannel_args->args); + (grpc_channel_args*)subchannel_args->args); gpr_free(subchannel_args); return s; } -static grpc_channel *client_channel_factory_create_channel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, - const char *target, grpc_client_channel_type type, - const grpc_channel_args *args) { +static grpc_channel* client_channel_factory_create_channel( + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, + const char* target, grpc_client_channel_type type, + const grpc_channel_args* args) { if (target == NULL) { gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); return NULL; } // Add channel arg containing the server URI. grpc_arg arg = grpc_channel_arg_string_create( - (char *)GRPC_ARG_SERVER_URI, + (char*)GRPC_ARG_SERVER_URI, grpc_resolver_factory_add_default_prefix_if_needed(exec_ctx, target)); - const char *to_remove[] = {GRPC_ARG_SERVER_URI}; - grpc_channel_args *new_args = + 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(exec_ctx, target, new_args, + grpc_channel* channel = grpc_channel_create(exec_ctx, target, new_args, GRPC_CLIENT_CHANNEL, NULL); grpc_channel_args_destroy(exec_ctx, new_args); return channel; @@ -190,24 +190,24 @@ static grpc_client_channel_factory client_channel_factory = { // Asynchronously: - resolve target // - connect to it (trying alternatives as presented) // - perform handshakes -grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds, - const char *target, - const grpc_channel_args *args, - void *reserved) { +grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds, + const char* target, + const grpc_channel_args* args, + void* reserved) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE( "grpc_secure_channel_create(creds=%p, target=%s, args=%p, " "reserved=%p)", - 4, ((void *)creds, target, (void *)args, (void *)reserved)); + 4, ((void*)creds, target, (void*)args, (void*)reserved)); GPR_ASSERT(reserved == NULL); - grpc_channel *channel = NULL; + grpc_channel* channel = NULL; if (creds != NULL) { // Add channel args containing the client channel factory and channel // credentials. grpc_arg args_to_add[] = { grpc_client_channel_factory_create_channel_arg(&client_channel_factory), grpc_channel_credentials_to_arg(creds)}; - grpc_channel_args *new_args = grpc_channel_args_copy_and_add( + grpc_channel_args* new_args = grpc_channel_args_copy_and_add( args, args_to_add, GPR_ARRAY_SIZE(args_to_add)); // Create channel. channel = client_channel_factory_create_channel( diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index 7ac7f4ece8..98683acc59 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -42,31 +42,31 @@ #include "src/core/lib/surface/server.h" typedef struct { - grpc_server *server; - grpc_tcp_server *tcp_server; - grpc_channel_args *args; + grpc_server* server; + grpc_tcp_server* tcp_server; + grpc_channel_args* args; gpr_mu mu; bool shutdown; grpc_closure tcp_server_shutdown_complete; - grpc_closure *server_destroy_listener_done; - grpc_handshake_manager *pending_handshake_mgrs; + grpc_closure* server_destroy_listener_done; + grpc_handshake_manager* pending_handshake_mgrs; } server_state; typedef struct { - server_state *svr_state; - grpc_pollset *accepting_pollset; - grpc_tcp_server_acceptor *acceptor; - grpc_handshake_manager *handshake_mgr; + server_state* svr_state; + grpc_pollset* accepting_pollset; + grpc_tcp_server_acceptor* acceptor; + grpc_handshake_manager* handshake_mgr; } server_connection_state; -static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_handshaker_args *args = (grpc_handshaker_args *)arg; - server_connection_state *connection_state = - (server_connection_state *)args->user_data; +static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_handshaker_args* args = (grpc_handshaker_args*)arg; + server_connection_state* connection_state = + (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); + const char* error_str = grpc_error_string(error); gpr_log(GPR_DEBUG, "Handshaking failed: %s", error_str); if (error == GRPC_ERROR_NONE && args->endpoint != NULL) { @@ -87,7 +87,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, // handshaker may have handed off the connection to some external // code, so we can just clean up here without creating a transport. if (args->endpoint != NULL) { - grpc_transport *transport = + grpc_transport* transport = grpc_create_chttp2_transport(exec_ctx, args->args, args->endpoint, 0); grpc_server_setup_transport( exec_ctx, connection_state->svr_state->server, transport, @@ -107,10 +107,10 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, gpr_free(connection_state); } -static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp, - grpc_pollset *accepting_pollset, - grpc_tcp_server_acceptor *acceptor) { - server_state *state = (server_state *)arg; +static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp, + grpc_pollset* accepting_pollset, + grpc_tcp_server_acceptor* acceptor) { + server_state* state = (server_state*)arg; gpr_mu_lock(&state->mu); if (state->shutdown) { gpr_mu_unlock(&state->mu); @@ -119,13 +119,13 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp, gpr_free(acceptor); return; } - grpc_handshake_manager *handshake_mgr = grpc_handshake_manager_create(); + grpc_handshake_manager* handshake_mgr = grpc_handshake_manager_create(); grpc_handshake_manager_pending_list_add(&state->pending_handshake_mgrs, handshake_mgr); gpr_mu_unlock(&state->mu); grpc_tcp_server_ref(state->tcp_server); - server_connection_state *connection_state = - (server_connection_state *)gpr_malloc(sizeof(*connection_state)); + server_connection_state* connection_state = + (server_connection_state*)gpr_malloc(sizeof(*connection_state)); connection_state->svr_state = state; connection_state->accepting_pollset = accepting_pollset; connection_state->acceptor = acceptor; @@ -142,10 +142,10 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp, } /* Server callback: start listening on our ports */ -static void server_start_listener(grpc_exec_ctx *exec_ctx, grpc_server *server, - void *arg, grpc_pollset **pollsets, +static void server_start_listener(grpc_exec_ctx* exec_ctx, grpc_server* server, + void* arg, grpc_pollset** pollsets, size_t pollset_count) { - server_state *state = (server_state *)arg; + server_state* state = (server_state*)arg; gpr_mu_lock(&state->mu); state->shutdown = false; gpr_mu_unlock(&state->mu); @@ -153,12 +153,12 @@ static void server_start_listener(grpc_exec_ctx *exec_ctx, grpc_server *server, on_accept, state); } -static void tcp_server_shutdown_complete(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - server_state *state = (server_state *)arg; +static void tcp_server_shutdown_complete(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + server_state* state = (server_state*)arg; /* ensure all threads have unlocked */ gpr_mu_lock(&state->mu); - grpc_closure *destroy_done = state->server_destroy_listener_done; + grpc_closure* destroy_done = state->server_destroy_listener_done; GPR_ASSERT(state->shutdown); grpc_handshake_manager_pending_list_shutdown_all( exec_ctx, state->pending_handshake_mgrs, GRPC_ERROR_REF(error)); @@ -177,31 +177,31 @@ static void tcp_server_shutdown_complete(grpc_exec_ctx *exec_ctx, void *arg, /* Server callback: destroy the tcp listener (so we don't generate further callbacks) */ -static void server_destroy_listener(grpc_exec_ctx *exec_ctx, - grpc_server *server, void *arg, - grpc_closure *destroy_done) { - server_state *state = (server_state *)arg; +static void server_destroy_listener(grpc_exec_ctx* exec_ctx, + grpc_server* server, void* arg, + grpc_closure* destroy_done) { + server_state* state = (server_state*)arg; gpr_mu_lock(&state->mu); state->shutdown = true; state->server_destroy_listener_done = destroy_done; - grpc_tcp_server *tcp_server = state->tcp_server; + grpc_tcp_server* tcp_server = state->tcp_server; gpr_mu_unlock(&state->mu); grpc_tcp_server_shutdown_listeners(exec_ctx, tcp_server); grpc_tcp_server_unref(exec_ctx, tcp_server); } -grpc_error *grpc_chttp2_server_add_port(grpc_exec_ctx *exec_ctx, - grpc_server *server, const char *addr, - grpc_channel_args *args, - int *port_num) { - grpc_resolved_addresses *resolved = NULL; - grpc_tcp_server *tcp_server = NULL; +grpc_error* grpc_chttp2_server_add_port(grpc_exec_ctx* exec_ctx, + grpc_server* server, const char* addr, + grpc_channel_args* args, + int* port_num) { + grpc_resolved_addresses* resolved = NULL; + grpc_tcp_server* tcp_server = NULL; size_t i; size_t count = 0; int port_temp; - grpc_error *err = GRPC_ERROR_NONE; - server_state *state = NULL; - grpc_error **errors = NULL; + grpc_error* err = GRPC_ERROR_NONE; + server_state* state = NULL; + grpc_error** errors = NULL; size_t naddrs = 0; *port_num = -1; @@ -211,7 +211,7 @@ grpc_error *grpc_chttp2_server_add_port(grpc_exec_ctx *exec_ctx, if (err != GRPC_ERROR_NONE) { goto error; } - state = (server_state *)gpr_zalloc(sizeof(*state)); + state = (server_state*)gpr_zalloc(sizeof(*state)); GRPC_CLOSURE_INIT(&state->tcp_server_shutdown_complete, tcp_server_shutdown_complete, state, grpc_schedule_on_exec_ctx); @@ -228,7 +228,7 @@ grpc_error *grpc_chttp2_server_add_port(grpc_exec_ctx *exec_ctx, gpr_mu_init(&state->mu); naddrs = resolved->naddrs; - errors = (grpc_error **)gpr_malloc(sizeof(*errors) * naddrs); + errors = (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); @@ -242,21 +242,22 @@ grpc_error *grpc_chttp2_server_add_port(grpc_exec_ctx *exec_ctx, } } if (count == 0) { - char *msg; + char* msg; gpr_asprintf(&msg, "No address added out of total %" PRIuPTR " resolved", naddrs); err = GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING(msg, errors, naddrs); gpr_free(msg); goto error; } else if (count != naddrs) { - char *msg; - gpr_asprintf(&msg, "Only %" PRIuPTR - " addresses added out of total %" PRIuPTR " resolved", + char* msg; + gpr_asprintf(&msg, + "Only %" PRIuPTR " addresses added out of total %" PRIuPTR + " resolved", count, naddrs); err = GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING(msg, errors, naddrs); gpr_free(msg); - const char *warning_message = grpc_error_string(err); + const char* warning_message = grpc_error_string(err); gpr_log(GPR_INFO, "WARNING: %s", warning_message); /* we managed to bind some addresses: continue */ diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.h b/src/core/ext/transport/chttp2/server/chttp2_server.h index 2ac155160f..4e0e7aa617 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.h +++ b/src/core/ext/transport/chttp2/server/chttp2_server.h @@ -29,9 +29,9 @@ extern "C" { /// Adds a port to \a server. Sets \a port_num to the port number. /// Takes ownership of \a args. -grpc_error *grpc_chttp2_server_add_port(grpc_exec_ctx *exec_ctx, - grpc_server *server, const char *addr, - grpc_channel_args *args, int *port_num); +grpc_error* grpc_chttp2_server_add_port(grpc_exec_ctx* exec_ctx, + grpc_server* server, const char* addr, + grpc_channel_args* args, int* port_num); #ifdef __cplusplus } diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc index d42b2d123e..8984896538 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc @@ -25,16 +25,16 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/server.h" -int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr) { +int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; int port_num = 0; GRPC_API_TRACE("grpc_server_add_insecure_http2_port(server=%p, addr=%s)", 2, (server, addr)); - grpc_error *err = grpc_chttp2_server_add_port( + grpc_error* err = grpc_chttp2_server_add_port( &exec_ctx, server, addr, grpc_channel_args_copy(grpc_server_get_channel_args(server)), &port_num); if (err != GRPC_ERROR_NONE) { - const char *msg = grpc_error_string(err); + const char* msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); GRPC_ERROR_UNREF(err); diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc index e647067f73..e37d69e5e9 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc @@ -34,25 +34,25 @@ #include "src/core/lib/surface/completion_queue.h" #include "src/core/lib/surface/server.h" -void grpc_server_add_insecure_channel_from_fd(grpc_server *server, - void *reserved, int fd) { +void grpc_server_add_insecure_channel_from_fd(grpc_server* server, + void* reserved, int fd) { GPR_ASSERT(reserved == NULL); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - char *name; + char* name; gpr_asprintf(&name, "fd:%d", fd); - grpc_endpoint *server_endpoint = + grpc_endpoint* server_endpoint = grpc_tcp_create(&exec_ctx, grpc_fd_create(fd, name), grpc_server_get_channel_args(server), name); gpr_free(name); - const grpc_channel_args *server_args = grpc_server_get_channel_args(server); - grpc_transport *transport = grpc_create_chttp2_transport( + const grpc_channel_args* server_args = grpc_server_get_channel_args(server); + grpc_transport* transport = grpc_create_chttp2_transport( &exec_ctx, server_args, server_endpoint, 0 /* is_client */); - grpc_pollset **pollsets; + grpc_pollset** pollsets; size_t num_pollsets = 0; grpc_server_get_pollsets(server, &pollsets, &num_pollsets); @@ -67,8 +67,8 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server *server, #else // !GPR_SUPPORT_CHANNELS_FROM_FD -void grpc_server_add_insecure_channel_from_fd(grpc_server *server, - void *reserved, int fd) { +void grpc_server_add_insecure_channel_from_fd(grpc_server* server, + void* reserved, int fd) { GPR_ASSERT(0); } diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc index e74a138d23..4b2e348780 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc @@ -34,14 +34,14 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/server.h" -int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr, - grpc_server_credentials *creds) { +int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr, + grpc_server_credentials* creds) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_error *err = GRPC_ERROR_NONE; - grpc_server_security_connector *sc = NULL; + grpc_error* err = GRPC_ERROR_NONE; + grpc_server_security_connector* sc = NULL; int port_num = 0; grpc_security_status status; - grpc_channel_args *args = NULL; + grpc_channel_args* args = NULL; GRPC_API_TRACE( "grpc_server_add_secure_http2_port(" "server=%p, addr=%s, creds=%p)", @@ -55,7 +55,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr, status = grpc_server_credentials_create_security_connector(&exec_ctx, creds, &sc); if (status != GRPC_SECURITY_OK) { - char *msg; + char* msg; gpr_asprintf(&msg, "Unable to create secure server with credentials of type %s.", creds->type); @@ -79,7 +79,7 @@ done: } grpc_exec_ctx_finish(&exec_ctx); if (err != GRPC_ERROR_NONE) { - const char *msg = grpc_error_string(err); + const char* msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); GRPC_ERROR_UNREF(err); diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.cc b/src/core/ext/transport/chttp2/transport/bin_decoder.cc index 5a99cbeffc..3ccae7afc3 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.cc @@ -49,7 +49,7 @@ static uint8_t decode_table[] = { static const uint8_t tail_xtra[4] = {0, 0, 1, 2}; -static bool input_is_valid(uint8_t *input_ptr, size_t length) { +static bool input_is_valid(uint8_t* input_ptr, size_t length) { size_t i; for (i = 0; i < length; ++i) { @@ -75,7 +75,7 @@ static bool input_is_valid(uint8_t *input_ptr, size_t length) { #define COMPOSE_OUTPUT_BYTE_2(input_ptr) \ (uint8_t)((decode_table[input_ptr[2]] << 6) | decode_table[input_ptr[3]]) -bool grpc_base64_decode_partial(struct grpc_base64_decode_context *ctx) { +bool grpc_base64_decode_partial(struct grpc_base64_decode_context* ctx) { size_t input_tail; if (ctx->input_cur > ctx->input_end || ctx->output_cur > ctx->output_end) { @@ -130,7 +130,7 @@ bool grpc_base64_decode_partial(struct grpc_base64_decode_context *ctx) { return true; } -grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, +grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx* exec_ctx, grpc_slice input) { size_t input_length = GRPC_SLICE_LENGTH(input); size_t output_length = input_length / 4 * 3; @@ -147,7 +147,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, } if (input_length > 0) { - uint8_t *input_end = GRPC_SLICE_END_PTR(input); + uint8_t* input_end = GRPC_SLICE_END_PTR(input); if (*(--input_end) == '=') { output_length--; if (*(--input_end) == '=') { @@ -164,7 +164,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, ctx.contains_tail = false; if (!grpc_base64_decode_partial(&ctx)) { - char *s = grpc_slice_to_c_string(input); + char* s = grpc_slice_to_c_string(input); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); grpc_slice_unref_internal(exec_ctx, output); @@ -175,7 +175,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, return output; } -grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx, +grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx* exec_ctx, grpc_slice input, size_t output_length) { size_t input_length = GRPC_SLICE_LENGTH(input); @@ -210,7 +210,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx, ctx.contains_tail = true; if (!grpc_base64_decode_partial(&ctx)) { - char *s = grpc_slice_to_c_string(input); + char* s = grpc_slice_to_c_string(input); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); grpc_slice_unref_internal(exec_ctx, output); diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.h b/src/core/ext/transport/chttp2/transport/bin_decoder.h index 1c0b2b7e97..a9c4c9a0f6 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.h +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.h @@ -28,10 +28,10 @@ extern "C" { struct grpc_base64_decode_context { /* input/output: */ - uint8_t *input_cur; - uint8_t *input_end; - uint8_t *output_cur; - uint8_t *output_end; + uint8_t* input_cur; + uint8_t* input_end; + uint8_t* output_cur; + uint8_t* output_end; /* Indicate if the decoder should handle the tail of input data*/ bool contains_tail; }; @@ -40,16 +40,16 @@ struct grpc_base64_decode_context { or output_end is reached. When input_end is reached, (input_end - input_cur) is less than 4. When output_end is reached, (output_end - output_cur) is less than 3. Returns false if decoding is failed. */ -bool grpc_base64_decode_partial(struct grpc_base64_decode_context *ctx); +bool grpc_base64_decode_partial(struct grpc_base64_decode_context* ctx); /* base64 decode a slice with pad chars. Returns a new slice, does not take ownership of the input. Returns an empty slice if decoding is failed. */ -grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, grpc_slice input); +grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx* exec_ctx, grpc_slice input); /* base64 decode a slice without pad chars, data length is needed. Returns a new slice, does not take ownership of the input. Returns an empty slice if decoding is failed. */ -grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx, +grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx* exec_ctx, grpc_slice input, size_t output_length); diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.cc b/src/core/ext/transport/chttp2/transport/bin_encoder.cc index 42d481b3c0..09f984d7b2 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.cc @@ -52,8 +52,8 @@ grpc_slice grpc_chttp2_base64_encode(grpc_slice input) { size_t tail_case = input_length % 3; 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); + uint8_t* in = GRPC_SLICE_START_PTR(input); + char* out = (char*)GRPC_SLICE_START_PTR(output); size_t i; /* encode full triplets */ @@ -85,15 +85,15 @@ grpc_slice grpc_chttp2_base64_encode(grpc_slice input) { break; } - GPR_ASSERT(out == (char *)GRPC_SLICE_END_PTR(output)); + GPR_ASSERT(out == (char*)GRPC_SLICE_END_PTR(output)); GPR_ASSERT(in == GRPC_SLICE_END_PTR(input)); return output; } grpc_slice grpc_chttp2_huffman_compress(grpc_slice input) { size_t nbits; - uint8_t *in; - uint8_t *out; + uint8_t* in; + uint8_t* out; grpc_slice output; uint32_t temp = 0; uint32_t temp_length = 0; @@ -136,17 +136,17 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input) { typedef struct { uint32_t temp; uint32_t temp_length; - uint8_t *out; + uint8_t* out; } huff_out; -static void enc_flush_some(huff_out *out) { +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); } } -static void enc_add2(huff_out *out, uint8_t a, uint8_t b) { +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)) | @@ -155,7 +155,7 @@ static void enc_add2(huff_out *out, uint8_t a, uint8_t b) { enc_flush_some(out); } -static void enc_add1(huff_out *out, uint8_t a) { +static void enc_add1(huff_out* out, uint8_t a) { b64_huff_sym sa = huff_alphabet[a]; out->temp = (out->temp << sa.length) | sa.bits; out->temp_length += sa.length; @@ -170,8 +170,8 @@ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) { size_t max_output_bits = 11 * output_syms; size_t max_output_length = max_output_bits / 8 + (max_output_bits % 8 != 0); grpc_slice output = GRPC_SLICE_MALLOC(max_output_length); - uint8_t *in = GRPC_SLICE_START_PTR(input); - uint8_t *start_out = GRPC_SLICE_START_PTR(output); + uint8_t* in = GRPC_SLICE_START_PTR(input); + uint8_t* start_out = GRPC_SLICE_START_PTR(output); huff_out out; size_t i; diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 02fc53122d..034e6ed8ca 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -99,94 +99,94 @@ grpc_tracer_flag grpc_trace_chttp2_refcount = #endif /* forward declarations of various callbacks that we'll build closures around */ -static void write_action_begin_locked(grpc_exec_ctx *exec_ctx, void *t, - grpc_error *error); -static void write_action(grpc_exec_ctx *exec_ctx, void *t, grpc_error *error); -static void write_action_end_locked(grpc_exec_ctx *exec_ctx, void *t, - grpc_error *error); +static void write_action_begin_locked(grpc_exec_ctx* exec_ctx, void* t, + grpc_error* error); +static void write_action(grpc_exec_ctx* exec_ctx, void* t, grpc_error* error); +static void write_action_end_locked(grpc_exec_ctx* exec_ctx, void* t, + grpc_error* error); -static void read_action_locked(grpc_exec_ctx *exec_ctx, void *t, - grpc_error *error); +static void read_action_locked(grpc_exec_ctx* exec_ctx, void* t, + grpc_error* error); -static void complete_fetch_locked(grpc_exec_ctx *exec_ctx, void *gs, - grpc_error *error); +static void complete_fetch_locked(grpc_exec_ctx* exec_ctx, void* gs, + grpc_error* error); /** Set a transport level setting, and push it to our peer */ -static void queue_setting_update(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +static void queue_setting_update(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_setting_id id, uint32_t value); -static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_stream *s, grpc_error *error); +static void close_from_api(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_error* error); /** Start new streams that have been created if we can */ -static void maybe_start_some_streams(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); +static void maybe_start_some_streams(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); -static void connectivity_state_set(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +static void connectivity_state_set(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_connectivity_state state, - grpc_error *error, const char *reason); + grpc_error* error, const char* reason); -static void incoming_byte_stream_destroy_locked(grpc_exec_ctx *exec_ctx, - void *byte_stream, - grpc_error *error_ignored); +static void incoming_byte_stream_destroy_locked(grpc_exec_ctx* exec_ctx, + void* byte_stream, + grpc_error* error_ignored); static void incoming_byte_stream_publish_error( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs, - grpc_error *error); -static void incoming_byte_stream_unref(grpc_exec_ctx *exec_ctx, - grpc_chttp2_incoming_byte_stream *bs); - -static void benign_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *t, - grpc_error *error); -static void destructive_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *t, - grpc_error *error); - -static void post_benign_reclaimer(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); -static void post_destructive_reclaimer(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); - -static void close_transport_locked(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, grpc_error *error); -static void end_all_the_calls(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_error *error); - -static void schedule_bdp_ping_locked(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); -static void start_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, - grpc_error *error); -static void finish_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, - grpc_error *error); -static void next_bdp_ping_timer_expired_locked(grpc_exec_ctx *exec_ctx, - void *tp, grpc_error *error); - -static void cancel_pings(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_error *error); -static void send_ping_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_closure *on_initiate, - grpc_closure *on_complete); -static void retry_initiate_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, - grpc_error *error); + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_error* error); +static void incoming_byte_stream_unref(grpc_exec_ctx* exec_ctx, + grpc_chttp2_incoming_byte_stream* bs); + +static void benign_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* t, + grpc_error* error); +static void destructive_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* t, + grpc_error* error); + +static void post_benign_reclaimer(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static void post_destructive_reclaimer(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); + +static void close_transport_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_error* error); +static void end_all_the_calls(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error); + +static void schedule_bdp_ping_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static void start_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error); +static void finish_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error); +static void next_bdp_ping_timer_expired_locked(grpc_exec_ctx* exec_ctx, + void* tp, grpc_error* error); + +static void cancel_pings(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error); +static void send_ping_locked(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_closure* on_initiate, + grpc_closure* on_complete); +static void retry_initiate_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error); /** keepalive-relevant functions */ -static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error); -static void start_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error); -static void finish_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error); -static void keepalive_watchdog_fired_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error); - -static void reset_byte_stream(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error); +static void init_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); +static void start_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); +static void finish_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); +static void keepalive_watchdog_fired_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); + +static void reset_byte_stream(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); /******************************************************************************* * CONSTRUCTION/DESTRUCTION/REFCOUNTING */ -static void destruct_transport(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { +static void destruct_transport(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { size_t i; grpc_endpoint_destroy(exec_ctx, t->ep); @@ -216,7 +216,7 @@ static void destruct_transport(grpc_exec_ctx *exec_ctx, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed")); while (t->write_cb_pool) { - grpc_chttp2_write_cb *next = t->write_cb_pool->next; + grpc_chttp2_write_cb* next = t->write_cb_pool->next; gpr_free(t->write_cb_pool); t->write_cb_pool = next; } @@ -230,9 +230,9 @@ static void destruct_transport(grpc_exec_ctx *exec_ctx, } #ifndef NDEBUG -void grpc_chttp2_unref_transport(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, const char *reason, - const char *file, int line) { +void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, const char* reason, + const char* file, int line) { if (GRPC_TRACER_ON(grpc_trace_chttp2_refcount)) { gpr_atm val = gpr_atm_no_barrier_load(&t->refs.count); gpr_log(GPR_DEBUG, "chttp2:unref:%p %" PRIdPTR "->%" PRIdPTR " %s [%s:%d]", @@ -242,8 +242,8 @@ void grpc_chttp2_unref_transport(grpc_exec_ctx *exec_ctx, destruct_transport(exec_ctx, t); } -void grpc_chttp2_ref_transport(grpc_chttp2_transport *t, const char *reason, - const char *file, int line) { +void grpc_chttp2_ref_transport(grpc_chttp2_transport* t, const char* reason, + const char* file, int line) { if (GRPC_TRACER_ON(grpc_trace_chttp2_refcount)) { gpr_atm val = gpr_atm_no_barrier_load(&t->refs.count); gpr_log(GPR_DEBUG, "chttp2: ref:%p %" PRIdPTR "->%" PRIdPTR " %s [%s:%d]", @@ -252,20 +252,20 @@ void grpc_chttp2_ref_transport(grpc_chttp2_transport *t, const char *reason, gpr_ref(&t->refs); } #else -void grpc_chttp2_unref_transport(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { +void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { if (!gpr_unref(&t->refs)) return; destruct_transport(exec_ctx, t); } -void grpc_chttp2_ref_transport(grpc_chttp2_transport *t) { gpr_ref(&t->refs); } +void grpc_chttp2_ref_transport(grpc_chttp2_transport* t) { gpr_ref(&t->refs); } #endif -static const grpc_transport_vtable *get_vtable(void); +static const grpc_transport_vtable* get_vtable(void); -static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - const grpc_channel_args *channel_args, - grpc_endpoint *ep, bool is_client) { +static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + const grpc_channel_args* channel_args, + grpc_endpoint* ep, bool is_client) { size_t i; int j; @@ -494,7 +494,7 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, } } else { static const struct { - const char *channel_arg_name; + const char* channel_arg_name; grpc_chttp2_setting_id setting_id; grpc_integer_options integer_options; bool availability[2] /* server, client */; @@ -580,9 +580,9 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, post_benign_reclaimer(exec_ctx, t); } -static void destroy_transport_locked(grpc_exec_ctx *exec_ctx, void *tp, - grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; +static void destroy_transport_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; t->destroying = 1; close_transport_locked( exec_ctx, t, @@ -592,17 +592,17 @@ static void destroy_transport_locked(grpc_exec_ctx *exec_ctx, void *tp, GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "destroy"); } -static void destroy_transport(grpc_exec_ctx *exec_ctx, grpc_transport *gt) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt; +static void destroy_transport(grpc_exec_ctx* exec_ctx, grpc_transport* gt) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; GRPC_CLOSURE_SCHED(exec_ctx, GRPC_CLOSURE_CREATE(destroy_transport_locked, t, grpc_combiner_scheduler(t->combiner)), GRPC_ERROR_NONE); } -static void close_transport_locked(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_error *error) { +static void close_transport_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_error* error) { end_all_the_calls(exec_ctx, t, GRPC_ERROR_REF(error)); cancel_pings(exec_ctx, t, GRPC_ERROR_REF(error)); if (t->closed_with_error == GRPC_ERROR_NONE) { @@ -645,7 +645,7 @@ static void close_transport_locked(grpc_exec_ctx *exec_ctx, } /* flush writable stream list to avoid dangling references */ - grpc_chttp2_stream *s; + grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_writable_stream(t, &s)) { GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:close"); } @@ -656,28 +656,28 @@ static void close_transport_locked(grpc_exec_ctx *exec_ctx, } #ifndef NDEBUG -void grpc_chttp2_stream_ref(grpc_chttp2_stream *s, const char *reason) { +void grpc_chttp2_stream_ref(grpc_chttp2_stream* s, const char* reason) { grpc_stream_ref(s->refcount, reason); } -void grpc_chttp2_stream_unref(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream *s, - const char *reason) { +void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s, + const char* reason) { grpc_stream_unref(exec_ctx, s->refcount, reason); } #else -void grpc_chttp2_stream_ref(grpc_chttp2_stream *s) { +void grpc_chttp2_stream_ref(grpc_chttp2_stream* s) { grpc_stream_ref(s->refcount); } -void grpc_chttp2_stream_unref(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream *s) { +void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s) { grpc_stream_unref(exec_ctx, s->refcount); } #endif -static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, grpc_stream_refcount *refcount, - const void *server_data, gpr_arena *arena) { +static int init_stream(grpc_exec_ctx* exec_ctx, 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; + grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; s->t = t; s->refcount = refcount; @@ -717,10 +717,10 @@ static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, return 0; } -static void destroy_stream_locked(grpc_exec_ctx *exec_ctx, void *sp, - grpc_error *error) { - grpc_chttp2_stream *s = (grpc_chttp2_stream *)sp; - grpc_chttp2_transport *t = s->t; +static void destroy_stream_locked(grpc_exec_ctx* exec_ctx, void* sp, + grpc_error* error) { + grpc_chttp2_stream* s = (grpc_chttp2_stream*)sp; + grpc_chttp2_transport* t = s->t; GPR_TIMER_BEGIN("destroy_stream", 0); @@ -771,12 +771,12 @@ static void destroy_stream_locked(grpc_exec_ctx *exec_ctx, void *sp, GRPC_CLOSURE_SCHED(exec_ctx, s->destroy_stream_arg, GRPC_ERROR_NONE); } -static void destroy_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, - grpc_closure *then_schedule_closure) { +static void destroy_stream(grpc_exec_ctx* exec_ctx, 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; + grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; if (s->stream_compression_ctx != NULL) { grpc_stream_compression_context_destroy(s->stream_compression_ctx); @@ -789,29 +789,30 @@ static void destroy_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, s->destroy_stream_arg = then_schedule_closure; GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT(&s->destroy_stream, destroy_stream_locked, s, - grpc_combiner_scheduler(t->combiner)), + exec_ctx, + 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, +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 (grpc_chttp2_stream*)grpc_chttp2_stream_map_find(&t->stream_map, id); } -grpc_chttp2_stream *grpc_chttp2_parsing_accept_stream(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, uint32_t id) { if (t->channel_callback.accept_stream == NULL) { return NULL; } - grpc_chttp2_stream *accepting; + grpc_chttp2_stream* accepting; GPR_ASSERT(t->accepting_stream == NULL); t->accepting_stream = &accepting; t->channel_callback.accept_stream(exec_ctx, t->channel_callback.accept_stream_user_data, - &t->base, (void *)(uintptr_t)id); + &t->base, (void*)(uintptr_t)id); t->accepting_stream = NULL; return accepting; } @@ -820,7 +821,7 @@ grpc_chttp2_stream *grpc_chttp2_parsing_accept_stream(grpc_exec_ctx *exec_ctx, * OUTPUT PROCESSING */ -static const char *write_state_name(grpc_chttp2_write_state st) { +static const char* write_state_name(grpc_chttp2_write_state st) { switch (st) { case GRPC_CHTTP2_WRITE_STATE_IDLE: return "IDLE"; @@ -832,8 +833,8 @@ static const char *write_state_name(grpc_chttp2_write_state st) { GPR_UNREACHABLE_CODE(return "UNKNOWN"); } -static void set_write_state(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_write_state st, const char *reason) { +static void set_write_state(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_write_state st, const char* reason) { GRPC_CHTTP2_IF_TRACING(gpr_log(GPR_DEBUG, "W:%p %s state %s -> %s [%s]", t, t->is_client ? "CLIENT" : "SERVER", write_state_name(t->write_state), @@ -842,7 +843,7 @@ static void set_write_state(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, if (st == GRPC_CHTTP2_WRITE_STATE_IDLE) { GRPC_CLOSURE_LIST_SCHED(exec_ctx, &t->run_after_write); if (t->close_transport_on_writes_finished != NULL) { - grpc_error *err = t->close_transport_on_writes_finished; + grpc_error* err = t->close_transport_on_writes_finished; t->close_transport_on_writes_finished = NULL; close_transport_locked(exec_ctx, t, err); } @@ -850,7 +851,7 @@ static void set_write_state(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, } static void inc_initiate_write_reason( - grpc_exec_ctx *exec_ctx, grpc_chttp2_initiate_write_reason reason) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_initiate_write_reason reason) { switch (reason) { case GRPC_CHTTP2_INITIATE_WRITE_INITIAL_WRITE: GRPC_STATS_INC_HTTP2_INITIATE_WRITE_DUE_TO_INITIAL_WRITE(exec_ctx); @@ -921,8 +922,8 @@ static void inc_initiate_write_reason( } } -void grpc_chttp2_initiate_write(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +void grpc_chttp2_initiate_write(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_initiate_write_reason reason) { GPR_TIMER_BEGIN("grpc_chttp2_initiate_write", 0); @@ -950,16 +951,16 @@ void grpc_chttp2_initiate_write(grpc_exec_ctx *exec_ctx, GPR_TIMER_END("grpc_chttp2_initiate_write", 0); } -void grpc_chttp2_mark_stream_writable(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +void grpc_chttp2_mark_stream_writable(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { if (t->closed_with_error == GRPC_ERROR_NONE && grpc_chttp2_list_add_writable_stream(t, s)) { GRPC_CHTTP2_STREAM_REF(s, "chttp2_writing:become"); } } -static grpc_closure_scheduler *write_scheduler(grpc_chttp2_transport *t, +static grpc_closure_scheduler* write_scheduler(grpc_chttp2_transport* t, bool early_results_scheduled, bool partial_write) { /* if it's not the first write in a batch, always offload to the executor: @@ -987,7 +988,7 @@ static grpc_closure_scheduler *write_scheduler(grpc_chttp2_transport *t, } #define WRITE_STATE_TUPLE_TO_INT(p, i) (2 * (int)(p) + (int)(i)) -static const char *begin_writing_desc(bool partial, bool inlined) { +static const char* begin_writing_desc(bool partial, bool inlined) { switch (WRITE_STATE_TUPLE_TO_INT(partial, inlined)) { case WRITE_STATE_TUPLE_TO_INT(false, false): return "begin write in background"; @@ -1001,10 +1002,10 @@ static const char *begin_writing_desc(bool partial, bool inlined) { GPR_UNREACHABLE_CODE(return "bad state tuple"); } -static void write_action_begin_locked(grpc_exec_ctx *exec_ctx, void *gt, - grpc_error *error_ignored) { +static void write_action_begin_locked(grpc_exec_ctx* exec_ctx, void* gt, + grpc_error* error_ignored) { GPR_TIMER_BEGIN("write_action_begin_locked", 0); - grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt; + grpc_chttp2_transport* t = (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) { @@ -1019,18 +1020,20 @@ static void write_action_begin_locked(grpc_exec_ctx *exec_ctx, void *gt, if (!t->is_first_write_in_batch) { GRPC_STATS_INC_HTTP2_WRITES_CONTINUED(exec_ctx); } - grpc_closure_scheduler *scheduler = + grpc_closure_scheduler* scheduler = write_scheduler(t, r.early_results_scheduled, r.partial); if (scheduler != grpc_schedule_on_exec_ctx) { GRPC_STATS_INC_HTTP2_WRITES_OFFLOADED(exec_ctx); } set_write_state( - exec_ctx, t, r.partial ? GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE - : GRPC_CHTTP2_WRITE_STATE_WRITING, + exec_ctx, t, + r.partial ? GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE + : GRPC_CHTTP2_WRITE_STATE_WRITING, begin_writing_desc(r.partial, scheduler == grpc_schedule_on_exec_ctx)); - GRPC_CLOSURE_SCHED(exec_ctx, GRPC_CLOSURE_INIT(&t->write_action, - write_action, t, scheduler), - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED( + exec_ctx, + GRPC_CLOSURE_INIT(&t->write_action, write_action, t, scheduler), + GRPC_ERROR_NONE); } else { GRPC_STATS_INC_HTTP2_SPURIOUS_WRITES_BEGUN(exec_ctx); set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_IDLE, @@ -1040,8 +1043,8 @@ static void write_action_begin_locked(grpc_exec_ctx *exec_ctx, void *gt, GPR_TIMER_END("write_action_begin_locked", 0); } -static void write_action(grpc_exec_ctx *exec_ctx, void *gt, grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt; +static void write_action(grpc_exec_ctx* exec_ctx, void* gt, grpc_error* error) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; GPR_TIMER_BEGIN("write_action", 0); grpc_endpoint_write( exec_ctx, t->ep, &t->outbuf, @@ -1050,10 +1053,10 @@ static void write_action(grpc_exec_ctx *exec_ctx, void *gt, grpc_error *error) { GPR_TIMER_END("write_action", 0); } -static void write_action_end_locked(grpc_exec_ctx *exec_ctx, void *tp, - grpc_error *error) { +static void write_action_end_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { GPR_TIMER_BEGIN("terminate_writing_with_lock", 0); - grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; + grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; if (error != GRPC_ERROR_NONE) { close_transport_locked(exec_ctx, t, GRPC_ERROR_REF(error)); @@ -1098,10 +1101,10 @@ static void write_action_end_locked(grpc_exec_ctx *exec_ctx, void *tp, // Dirties an HTTP2 setting to be sent out next time a writing path occurs. // If the change needs to occur immediately, manually initiate a write. -static void queue_setting_update(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +static void queue_setting_update(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_setting_id id, uint32_t value) { - const grpc_chttp2_setting_parameters *sp = + const grpc_chttp2_setting_parameters* sp = &grpc_chttp2_settings_parameters[id]; uint32_t use_value = GPR_CLAMP(value, sp->min_value, sp->max_value); if (use_value != value) { @@ -1114,8 +1117,8 @@ static void queue_setting_update(grpc_exec_ctx *exec_ctx, } } -void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, uint32_t goaway_error, grpc_slice goaway_text) { // GRPC_CHTTP2_IF_TRACING( @@ -1151,9 +1154,9 @@ void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx *exec_ctx, "got_goaway"); } -static void maybe_start_some_streams(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { - grpc_chttp2_stream *s; +static void maybe_start_some_streams(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { + grpc_chttp2_stream* s; /* start streams where we have free grpc_chttp2_stream ids and free * concurrency */ while (t->next_stream_id <= MAX_CLIENT_STREAM_ID && @@ -1204,24 +1207,24 @@ static void maybe_start_some_streams(grpc_exec_ctx *exec_ctx, bits being used for flags defined above) */ #define CLOSURE_BARRIER_FIRST_REF_BIT (1 << 16) -static grpc_closure *add_closure_barrier(grpc_closure *closure) { +static grpc_closure* add_closure_barrier(grpc_closure* closure) { closure->next_data.scratch += CLOSURE_BARRIER_FIRST_REF_BIT; return closure; } -static void null_then_run_closure(grpc_exec_ctx *exec_ctx, - grpc_closure **closure, grpc_error *error) { - grpc_closure *c = *closure; +static void null_then_run_closure(grpc_exec_ctx* exec_ctx, + grpc_closure** closure, grpc_error* error) { + grpc_closure* c = *closure; *closure = NULL; GRPC_CLOSURE_RUN(exec_ctx, c, error); } -void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, - grpc_closure **pclosure, - grpc_error *error, const char *desc) { - grpc_closure *closure = *pclosure; +void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, + grpc_closure** pclosure, + grpc_error* error, const char* desc) { + grpc_closure* closure = *pclosure; *pclosure = NULL; if (closure == NULL) { GRPC_ERROR_UNREF(error); @@ -1229,7 +1232,7 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, } closure->next_data.scratch -= CLOSURE_BARRIER_FIRST_REF_BIT; if (GRPC_TRACER_ON(grpc_http_trace)) { - const char *errstr = grpc_error_string(error); + const char* errstr = grpc_error_string(error); gpr_log( GPR_DEBUG, "complete_closure_step: t=%p %p refs=%d flags=0x%04x desc=%s err=%s " @@ -1265,7 +1268,7 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, } } -static bool contains_non_ok_status(grpc_metadata_batch *batch) { +static bool contains_non_ok_status(grpc_metadata_batch* batch) { if (batch->idx.named.grpc_status != NULL) { return !grpc_mdelem_eq(batch->idx.named.grpc_status->md, GRPC_MDELEM_GRPC_STATUS_0); @@ -1273,9 +1276,9 @@ static bool contains_non_ok_status(grpc_metadata_batch *batch) { return false; } -static void maybe_become_writable_due_to_send_msg(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +static void maybe_become_writable_due_to_send_msg(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { if (s->id != 0 && (!s->write_buffering || s->flow_controlled_buffer.length > t->write_buffer_size)) { grpc_chttp2_mark_stream_writable(exec_ctx, t, s); @@ -1284,18 +1287,18 @@ static void maybe_become_writable_due_to_send_msg(grpc_exec_ctx *exec_ctx, } } -static void add_fetched_slice_locked(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +static void add_fetched_slice_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { s->fetched_send_message_length += (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(exec_ctx, t, s); } -static void continue_fetching_send_locked(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +static void continue_fetching_send_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { for (;;) { if (s->fetching_send_message == NULL) { /* Stream was cancelled before message fetch completed */ @@ -1310,16 +1313,16 @@ static void continue_fetching_send_locked(grpc_exec_ctx *exec_ctx, exec_ctx, t, s, &s->fetching_send_message_finished, GRPC_ERROR_NONE, "fetching_send_message_finished"); } else { - grpc_chttp2_write_cb *cb = t->write_cb_pool; + grpc_chttp2_write_cb* cb = t->write_cb_pool; if (cb == NULL) { - cb = (grpc_chttp2_write_cb *)gpr_malloc(sizeof(*cb)); + cb = (grpc_chttp2_write_cb*)gpr_malloc(sizeof(*cb)); } else { t->write_cb_pool = cb->next; } cb->call_at_byte = notify_offset; cb->closure = s->fetching_send_message_finished; s->fetching_send_message_finished = NULL; - grpc_chttp2_write_cb **list = + grpc_chttp2_write_cb** list = s->fetching_send_message->flags & GRPC_WRITE_THROUGH ? &s->on_write_finished_cbs : &s->on_flow_controlled_cbs; @@ -1330,7 +1333,7 @@ static void continue_fetching_send_locked(grpc_exec_ctx *exec_ctx, return; /* early out */ } else if (grpc_byte_stream_next(exec_ctx, s->fetching_send_message, UINT32_MAX, &s->complete_fetch_locked)) { - grpc_error *error = grpc_byte_stream_pull( + grpc_error* error = grpc_byte_stream_pull( exec_ctx, s->fetching_send_message, &s->fetching_slice); if (error != GRPC_ERROR_NONE) { grpc_byte_stream_destroy(exec_ctx, s->fetching_send_message); @@ -1342,10 +1345,10 @@ static void continue_fetching_send_locked(grpc_exec_ctx *exec_ctx, } } -static void complete_fetch_locked(grpc_exec_ctx *exec_ctx, void *gs, - grpc_error *error) { - grpc_chttp2_stream *s = (grpc_chttp2_stream *)gs; - grpc_chttp2_transport *t = s->t; +static void complete_fetch_locked(grpc_exec_ctx* exec_ctx, void* gs, + grpc_error* error) { + grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; + grpc_chttp2_transport* t = s->t; if (error == GRPC_ERROR_NONE) { error = grpc_byte_stream_pull(exec_ctx, s->fetching_send_message, &s->fetching_slice); @@ -1360,14 +1363,14 @@ static void complete_fetch_locked(grpc_exec_ctx *exec_ctx, void *gs, } } -static void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {} +static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} -static void log_metadata(const grpc_metadata_batch *md_batch, uint32_t id, +static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id, bool is_client, bool is_initial) { - for (grpc_linked_mdelem *md = md_batch->list.head; md != NULL; + for (grpc_linked_mdelem* md = md_batch->list.head; md != NULL; md = md->next) { - char *key = grpc_slice_to_c_string(GRPC_MDKEY(md->md)); - char *value = grpc_slice_to_c_string(GRPC_MDVALUE(md->md)); + char* key = grpc_slice_to_c_string(GRPC_MDKEY(md->md)); + char* value = grpc_slice_to_c_string(GRPC_MDVALUE(md->md)); gpr_log(GPR_INFO, "HTTP:%d:%s:%s: %s: %s", id, is_initial ? "HDR" : "TRL", is_client ? "CLI" : "SVR", key, value); gpr_free(key); @@ -1375,20 +1378,20 @@ static void log_metadata(const grpc_metadata_batch *md_batch, uint32_t id, } } -static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, - grpc_error *error_ignored) { +static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, + grpc_error* error_ignored) { GPR_TIMER_BEGIN("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; - grpc_transport_stream_op_batch_payload *op_payload = op->payload; - grpc_chttp2_transport *t = s->t; + 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; + grpc_transport_stream_op_batch_payload* op_payload = op->payload; + grpc_chttp2_transport* t = s->t; GRPC_STATS_INC_HTTP2_OP_BATCHES(exec_ctx); if (GRPC_TRACER_ON(grpc_http_trace)) { - char *str = grpc_transport_stream_op_batch_string(op); + char* str = grpc_transport_stream_op_batch_string(op); gpr_log(GPR_DEBUG, "perform_stream_op_locked: %s; on_complete = %p", str, op->on_complete); gpr_free(str); @@ -1402,7 +1405,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, } } - grpc_closure *on_complete = op->on_complete; + grpc_closure* on_complete = op->on_complete; if (on_complete == NULL) { on_complete = GRPC_CLOSURE_CREATE(do_nothing, NULL, grpc_schedule_on_exec_ctx); @@ -1530,7 +1533,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, "fetching_send_message_finished"); } else { GPR_ASSERT(s->fetching_send_message == NULL); - uint8_t *frame_hdr = grpc_slice_buffer_tiny_add( + uint8_t* frame_hdr = grpc_slice_buffer_tiny_add( &s->flow_controlled_buffer, GRPC_HEADER_SIZE_IN_BYTES); uint32_t flags = op_payload->send_message.send_message->flags; frame_hdr[0] = (flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0; @@ -1657,12 +1660,12 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "perform_stream_op"); } -static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, - grpc_transport_stream_op_batch *op) { +static void perform_stream_op(grpc_exec_ctx* exec_ctx, 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; + grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; if (!t->is_client) { if (op->send_initial_metadata) { @@ -1678,7 +1681,7 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, } if (GRPC_TRACER_ON(grpc_http_trace)) { - char *str = grpc_transport_stream_op_batch_string(op); + char* str = grpc_transport_stream_op_batch_string(op); gpr_log(GPR_DEBUG, "perform_stream_op[s=%p]: %s", s, str); gpr_free(str); } @@ -1693,11 +1696,11 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, GPR_TIMER_END("perform_stream_op", 0); } -static void cancel_pings(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_error *error) { +static void cancel_pings(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error) { /* callback remaining pings: they're not allowed to call into the transpot, and maybe they hold resources that need to be freed */ - grpc_chttp2_ping_queue *pq = &t->ping_queue; + grpc_chttp2_ping_queue* pq = &t->ping_queue; GPR_ASSERT(error != GRPC_ERROR_NONE); for (size_t j = 0; j < GRPC_CHTTP2_PCL_COUNT; j++) { grpc_closure_list_fail_all(&pq->lists[j], GRPC_ERROR_REF(error)); @@ -1706,24 +1709,24 @@ static void cancel_pings(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, GRPC_ERROR_UNREF(error); } -static void send_ping_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_closure *on_initiate, grpc_closure *on_ack) { +static void send_ping_locked(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_closure* on_initiate, grpc_closure* on_ack) { if (t->closed_with_error != GRPC_ERROR_NONE) { GRPC_CLOSURE_SCHED(exec_ctx, on_initiate, GRPC_ERROR_REF(t->closed_with_error)); GRPC_CLOSURE_SCHED(exec_ctx, on_ack, GRPC_ERROR_REF(t->closed_with_error)); return; } - grpc_chttp2_ping_queue *pq = &t->ping_queue; + grpc_chttp2_ping_queue* pq = &t->ping_queue; grpc_closure_list_append(&pq->lists[GRPC_CHTTP2_PCL_INITIATE], on_initiate, GRPC_ERROR_NONE); grpc_closure_list_append(&pq->lists[GRPC_CHTTP2_PCL_NEXT], on_ack, GRPC_ERROR_NONE); } -static void retry_initiate_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, - grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; +static void retry_initiate_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; t->ping_state.is_delayed_ping_timer_set = false; if (error == GRPC_ERROR_NONE) { grpc_chttp2_initiate_write(exec_ctx, t, @@ -1731,11 +1734,11 @@ static void retry_initiate_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, } } -void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, +void grpc_chttp2_ack_ping(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, uint64_t id) { - grpc_chttp2_ping_queue *pq = &t->ping_queue; + grpc_chttp2_ping_queue* pq = &t->ping_queue; if (pq->inflight_id != id) { - char *from = grpc_endpoint_get_peer(t->ep); + char* from = grpc_endpoint_get_peer(t->ep); gpr_log(GPR_DEBUG, "Unknown ping response from %s: %" PRIx64, from, id); gpr_free(from); return; @@ -1747,8 +1750,8 @@ void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, } } -static void send_goaway(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_error *error) { +static void send_goaway(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error) { t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED; grpc_http2_error_code http_error; grpc_slice slice; @@ -1761,8 +1764,8 @@ static void send_goaway(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, GRPC_ERROR_UNREF(error); } -void grpc_chttp2_add_ping_strike(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { +void grpc_chttp2_add_ping_strike(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { t->ping_recv_state.ping_strikes++; if (++t->ping_recv_state.ping_strikes > t->ping_policy.max_ping_strikes && t->ping_policy.max_ping_strikes != 0) { @@ -1772,19 +1775,20 @@ void grpc_chttp2_add_ping_strike(grpc_exec_ctx *exec_ctx, GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); /*The transport will be closed after the write is done */ close_transport_locked( - exec_ctx, t, grpc_error_set_int( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many pings"), - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE)); + exec_ctx, t, + grpc_error_set_int( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many pings"), + GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE)); } } -static void perform_transport_op_locked(grpc_exec_ctx *exec_ctx, - void *stream_op, - grpc_error *error_ignored) { - grpc_transport_op *op = (grpc_transport_op *)stream_op; - grpc_chttp2_transport *t = - (grpc_chttp2_transport *)op->handler_private.extra_arg; - grpc_error *close_transport = op->disconnect_with_error; +static void perform_transport_op_locked(grpc_exec_ctx* exec_ctx, + void* stream_op, + grpc_error* error_ignored) { + grpc_transport_op* op = (grpc_transport_op*)stream_op; + grpc_chttp2_transport* t = + (grpc_chttp2_transport*)op->handler_private.extra_arg; + grpc_error* close_transport = op->disconnect_with_error; if (op->goaway_error) { send_goaway(exec_ctx, t, op->goaway_error); @@ -1825,10 +1829,10 @@ static void perform_transport_op_locked(grpc_exec_ctx *exec_ctx, GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "transport_op"); } -static void perform_transport_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_transport_op *op) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt; - char *msg = grpc_transport_op_string(op); +static void perform_transport_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_transport_op* op) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; + char* msg = grpc_transport_op_string(op); gpr_free(msg); op->handler_private.extra_arg = gt; GRPC_CHTTP2_REF_TRANSPORT(t, "transport_op"); @@ -1843,9 +1847,9 @@ static void perform_transport_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, * INPUT PROCESSING - GENERAL */ -void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { if (s->recv_initial_metadata_ready != NULL && s->published_metadata[0] != GRPC_METADATA_NOT_PUBLISHED) { if (s->seen_error) { @@ -1862,10 +1866,10 @@ void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx *exec_ctx, } } -void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { - grpc_error *error = GRPC_ERROR_NONE; +void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { + grpc_error* error = GRPC_ERROR_NONE; if (s->recv_message_ready != NULL) { *s->recv_message = NULL; if (s->final_metadata_requested && s->seen_error) { @@ -1946,9 +1950,9 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx *exec_ctx, } } -void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); if (s->recv_trailing_metadata_finished != NULL && s->read_closed && s->write_closed) { @@ -2000,10 +2004,10 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx *exec_ctx, } } -static void remove_stream(grpc_exec_ctx *exec_ctx, 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); +static void remove_stream(grpc_exec_ctx* exec_ctx, 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); GPR_ASSERT(s); if (t->incoming_stream == s) { t->incoming_stream = NULL; @@ -2011,7 +2015,7 @@ static void remove_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, } if (s->pending_byte_stream) { if (s->on_next != NULL) { - grpc_chttp2_incoming_byte_stream *bs = s->data_parser.parsing_frame; + grpc_chttp2_incoming_byte_stream* bs = s->data_parser.parsing_frame; if (error == GRPC_ERROR_NONE) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Truncated message"); } @@ -2042,9 +2046,9 @@ static void remove_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, maybe_start_some_streams(exec_ctx, t); } -void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, grpc_chttp2_stream *s, - grpc_error *due_to_error) { +void grpc_chttp2_cancel_stream(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, + grpc_error* due_to_error) { if (!t->is_client && !s->sent_trailing_metadata && grpc_error_has_clear_grpc_status(due_to_error)) { close_from_api(exec_ctx, t, s, due_to_error); @@ -2069,8 +2073,8 @@ void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, due_to_error); } -void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_stream *s, grpc_error *error) { +void grpc_chttp2_fake_status(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_error* error) { grpc_status_code status; grpc_slice slice; grpc_error_get_status(exec_ctx, error, s->deadline, &status, &slice, NULL); @@ -2109,7 +2113,7 @@ void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, GRPC_ERROR_UNREF(error); } -static void add_error(grpc_error *error, grpc_error **refs, size_t *nrefs) { +static void add_error(grpc_error* error, grpc_error** refs, size_t* nrefs) { if (error == GRPC_ERROR_NONE) return; for (size_t i = 0; i < *nrefs; i++) { if (error == refs[i]) { @@ -2120,14 +2124,14 @@ static void add_error(grpc_error *error, grpc_error **refs, size_t *nrefs) { ++*nrefs; } -static grpc_error *removal_error(grpc_error *extra_error, grpc_chttp2_stream *s, - const char *master_error_msg) { - grpc_error *refs[3]; +static grpc_error* removal_error(grpc_error* extra_error, grpc_chttp2_stream* s, + const char* master_error_msg) { + grpc_error* refs[3]; size_t nrefs = 0; add_error(s->read_closed_error, refs, &nrefs); add_error(s->write_closed_error, refs, &nrefs); add_error(extra_error, refs, &nrefs); - grpc_error *error = GRPC_ERROR_NONE; + grpc_error* error = GRPC_ERROR_NONE; if (nrefs > 0) { error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(master_error_msg, refs, nrefs); @@ -2136,11 +2140,11 @@ static grpc_error *removal_error(grpc_error *extra_error, grpc_chttp2_stream *s, return error; } -static void flush_write_list(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_stream *s, grpc_chttp2_write_cb **list, - grpc_error *error) { +static void flush_write_list(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_chttp2_write_cb** list, + grpc_error* error) { while (*list) { - grpc_chttp2_write_cb *cb = *list; + grpc_chttp2_write_cb* cb = *list; *list = cb->next; grpc_chttp2_complete_closure_step(exec_ctx, t, s, &cb->closure, GRPC_ERROR_REF(error), @@ -2151,9 +2155,9 @@ static void flush_write_list(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, GRPC_ERROR_UNREF(error); } -void grpc_chttp2_fail_pending_writes(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, grpc_error *error) { +void grpc_chttp2_fail_pending_writes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_error* error) { error = removal_error(error, s, "Pending writes failed due to stream closure"); s->send_initial_metadata = NULL; @@ -2175,10 +2179,10 @@ void grpc_chttp2_fail_pending_writes(grpc_exec_ctx *exec_ctx, flush_write_list(exec_ctx, t, s, &s->on_flow_controlled_cbs, error); } -void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, int close_reads, - int close_writes, grpc_error *error) { +void grpc_chttp2_mark_stream_closed(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, int close_reads, + int close_writes, grpc_error* error) { if (s->read_closed && s->write_closed) { /* already closed */ grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); @@ -2199,7 +2203,7 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, } if (s->read_closed && s->write_closed) { became_closed = true; - grpc_error *overall_error = + grpc_error* overall_error = removal_error(GRPC_ERROR_REF(error), s, "Stream removed"); if (s->id != 0) { remove_stream(exec_ctx, t, s->id, GRPC_ERROR_REF(overall_error)); @@ -2227,14 +2231,14 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, GRPC_ERROR_UNREF(error); } -static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_stream *s, grpc_error *error) { +static void close_from_api(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_error* error) { grpc_slice hdr; grpc_slice status_hdr; grpc_slice http_status_hdr; grpc_slice content_type_hdr; grpc_slice message_pfx; - uint8_t *p; + uint8_t* p; uint32_t len = 0; grpc_status_code grpc_status; grpc_slice slice; @@ -2387,20 +2391,20 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, } typedef struct { - grpc_exec_ctx *exec_ctx; - grpc_error *error; - grpc_chttp2_transport *t; + grpc_exec_ctx* exec_ctx; + grpc_error* error; + grpc_chttp2_transport* t; } 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; +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; grpc_chttp2_cancel_stream(args->exec_ctx, args->t, s, GRPC_ERROR_REF(args->error)); } -static void end_all_the_calls(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_error *error) { +static void end_all_the_calls(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error) { cancel_stream_cb_args args = {exec_ctx, error, t}; grpc_chttp2_stream_map_for_each(&t->stream_map, cancel_stream_cb, &args); GRPC_ERROR_UNREF(error); @@ -2411,7 +2415,7 @@ static void end_all_the_calls(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, */ template <class F> -static void WithUrgency(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, +static void WithUrgency(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_core::chttp2::FlowControlAction::Urgency urgency, grpc_chttp2_initiate_write_reason reason, F action) { switch (urgency) { @@ -2427,8 +2431,8 @@ static void WithUrgency(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, } void grpc_chttp2_act_on_flowctl_action( - grpc_exec_ctx *exec_ctx, const grpc_core::chttp2::FlowControlAction &action, - grpc_chttp2_transport *t, grpc_chttp2_stream *s) { + grpc_exec_ctx* exec_ctx, const grpc_core::chttp2::FlowControlAction& action, + grpc_chttp2_transport* t, grpc_chttp2_stream* s) { WithUrgency( exec_ctx, t, action.send_stream_update(), GRPC_CHTTP2_INITIATE_WRITE_STREAM_FLOW_CONTROL, @@ -2450,17 +2454,17 @@ void grpc_chttp2_act_on_flowctl_action( }); } -static grpc_error *try_http_parsing(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { +static grpc_error* try_http_parsing(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { grpc_http_parser parser; size_t i = 0; - grpc_error *error = GRPC_ERROR_NONE; + grpc_error* error = GRPC_ERROR_NONE; grpc_http_response response; memset(&response, 0, sizeof(response)); grpc_http_parser_init(&parser, GRPC_HTTP_RESPONSE, &response); - grpc_error *parse_error = GRPC_ERROR_NONE; + grpc_error* parse_error = GRPC_ERROR_NONE; for (; i < t->read_buffer.count && parse_error == GRPC_ERROR_NONE; i++) { parse_error = grpc_http_parser_parse(&parser, t->read_buffer.slices[i], NULL); @@ -2480,27 +2484,27 @@ static grpc_error *try_http_parsing(grpc_exec_ctx *exec_ctx, return error; } -static void read_action_locked(grpc_exec_ctx *exec_ctx, void *tp, - grpc_error *error) { +static void read_action_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { GPR_TIMER_BEGIN("reading_action_locked", 0); - grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; + grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; GRPC_ERROR_REF(error); - grpc_error *err = error; + grpc_error* err = error; if (err != GRPC_ERROR_NONE) { err = grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Endpoint read failed", &err, 1), GRPC_ERROR_INT_OCCURRED_DURING_WRITE, t->write_state); } - GPR_SWAP(grpc_error *, err, 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); size_t i = 0; - grpc_error *errors[3] = {GRPC_ERROR_REF(error), GRPC_ERROR_NONE, + grpc_error* errors[3] = {GRPC_ERROR_REF(error), GRPC_ERROR_NONE, GRPC_ERROR_NONE}; for (; i < t->read_buffer.count && errors[1] == GRPC_ERROR_NONE; i++) { t->flow_control->bdp_estimator()->AddIncomingBytes( @@ -2522,7 +2526,7 @@ static void read_action_locked(grpc_exec_ctx *exec_ctx, void *tp, GPR_TIMER_BEGIN("post_parse_locked", 0); if (t->initial_window_update != 0) { if (t->initial_window_update > 0) { - grpc_chttp2_stream *s; + grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_stalled_by_stream(t, &s)) { grpc_chttp2_mark_stream_writable(exec_ctx, t, s); grpc_chttp2_initiate_write( @@ -2569,16 +2573,16 @@ static void read_action_locked(grpc_exec_ctx *exec_ctx, void *tp, // t is reffed prior to calling the first time, and once the callback chain // that kicks off finishes, it's unreffed -static void schedule_bdp_ping_locked(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { +static void schedule_bdp_ping_locked(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { t->flow_control->bdp_estimator()->SchedulePing(); send_ping_locked(exec_ctx, t, &t->start_bdp_ping_locked, &t->finish_bdp_ping_locked); } -static void start_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, - grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; +static void start_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; if (GRPC_TRACER_ON(grpc_http_trace)) { gpr_log(GPR_DEBUG, "%s: Start BDP ping err=%s", t->peer_string, grpc_error_string(error)); @@ -2590,9 +2594,9 @@ static void start_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, t->flow_control->bdp_estimator()->StartPing(); } -static void finish_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, - grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; +static void finish_bdp_ping_locked(grpc_exec_ctx* exec_ctx, void* tp, + grpc_error* error) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; if (GRPC_TRACER_ON(grpc_http_trace)) { gpr_log(GPR_DEBUG, "%s: Complete BDP ping err=%s", t->peer_string, grpc_error_string(error)); @@ -2611,9 +2615,9 @@ static void finish_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, &t->next_bdp_ping_timer_expired_locked); } -static void next_bdp_ping_timer_expired_locked(grpc_exec_ctx *exec_ctx, - void *tp, grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; +static void next_bdp_ping_timer_expired_locked(grpc_exec_ctx* exec_ctx, + void* tp, grpc_error* error) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; GPR_ASSERT(t->have_next_bdp_ping_timer); t->have_next_bdp_ping_timer = false; if (error != GRPC_ERROR_NONE) { @@ -2623,7 +2627,7 @@ static void next_bdp_ping_timer_expired_locked(grpc_exec_ctx *exec_ctx, schedule_bdp_ping_locked(exec_ctx, t); } -void grpc_chttp2_config_default_keepalive_args(grpc_channel_args *args, +void grpc_chttp2_config_default_keepalive_args(grpc_channel_args* args, bool is_client) { size_t i; if (args) { @@ -2681,9 +2685,9 @@ void grpc_chttp2_config_default_keepalive_args(grpc_channel_args *args, } } -static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)arg; +static void init_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_chttp2_transport* t = (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; @@ -2712,18 +2716,18 @@ static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg, GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "init keepalive ping"); } -static void start_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)arg; +static void start_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)arg; GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog"); grpc_timer_init(exec_ctx, &t->keepalive_watchdog_timer, grpc_exec_ctx_now(exec_ctx) + t->keepalive_time, &t->keepalive_watchdog_fired_locked); } -static void finish_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)arg; +static void finish_keepalive_ping_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_chttp2_transport* t = (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; @@ -2737,9 +2741,9 @@ static void finish_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg, GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keepalive ping end"); } -static void keepalive_watchdog_fired_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)arg; +static void keepalive_watchdog_fired_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_chttp2_transport* t = (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; @@ -2764,10 +2768,10 @@ static void keepalive_watchdog_fired_locked(grpc_exec_ctx *exec_ctx, void *arg, * CALLBACK LOOP */ -static void connectivity_state_set(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +static void connectivity_state_set(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_connectivity_state state, - grpc_error *error, const char *reason) { + grpc_error* error, const char* reason) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_DEBUG, "set connectivity_state=%d", state)); grpc_connectivity_state_set(exec_ctx, &t->channel_callback.state_tracker, @@ -2778,15 +2782,15 @@ static void connectivity_state_set(grpc_exec_ctx *exec_ctx, * POLLSET STUFF */ -static void set_pollset(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, grpc_pollset *pollset) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt; +static void set_pollset(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_pollset* pollset) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; grpc_endpoint_add_to_pollset(exec_ctx, t->ep, pollset); } -static void set_pollset_set(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, grpc_pollset_set *pollset_set) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt; +static void set_pollset_set(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_pollset_set* pollset_set) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; grpc_endpoint_add_to_pollset_set(exec_ctx, t->ep, pollset_set); } @@ -2794,9 +2798,9 @@ static void set_pollset_set(grpc_exec_ctx *exec_ctx, grpc_transport *gt, * BYTE STREAM */ -static void reset_byte_stream(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_chttp2_stream *s = (grpc_chttp2_stream *)arg; +static void reset_byte_stream(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_chttp2_stream* s = (grpc_chttp2_stream*)arg; s->pending_byte_stream = false; if (error == GRPC_ERROR_NONE) { @@ -2813,20 +2817,20 @@ static void reset_byte_stream(grpc_exec_ctx *exec_ctx, void *arg, } } -static void incoming_byte_stream_unref(grpc_exec_ctx *exec_ctx, - grpc_chttp2_incoming_byte_stream *bs) { +static void incoming_byte_stream_unref(grpc_exec_ctx* exec_ctx, + grpc_chttp2_incoming_byte_stream* bs) { if (gpr_unref(&bs->refs)) { gpr_free(bs); } } -static void incoming_byte_stream_next_locked(grpc_exec_ctx *exec_ctx, - void *argp, - grpc_error *error_ignored) { - grpc_chttp2_incoming_byte_stream *bs = - (grpc_chttp2_incoming_byte_stream *)argp; - grpc_chttp2_transport *t = bs->transport; - grpc_chttp2_stream *s = bs->stream; +static void incoming_byte_stream_next_locked(grpc_exec_ctx* exec_ctx, + void* argp, + grpc_error* error_ignored) { + grpc_chttp2_incoming_byte_stream* bs = + (grpc_chttp2_incoming_byte_stream*)argp; + grpc_chttp2_transport* t = bs->transport; + grpc_chttp2_stream* s = bs->stream; size_t cur_length = s->frame_storage.length; if (!s->read_closed) { @@ -2868,14 +2872,14 @@ static void incoming_byte_stream_next_locked(grpc_exec_ctx *exec_ctx, incoming_byte_stream_unref(exec_ctx, bs); } -static bool incoming_byte_stream_next(grpc_exec_ctx *exec_ctx, - grpc_byte_stream *byte_stream, +static bool incoming_byte_stream_next(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, size_t max_size_hint, - grpc_closure *on_complete) { + grpc_closure* on_complete) { GPR_TIMER_BEGIN("incoming_byte_stream_next", 0); - grpc_chttp2_incoming_byte_stream *bs = - (grpc_chttp2_incoming_byte_stream *)byte_stream; - grpc_chttp2_stream *s = bs->stream; + grpc_chttp2_incoming_byte_stream* bs = + (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; @@ -2894,14 +2898,14 @@ static bool incoming_byte_stream_next(grpc_exec_ctx *exec_ctx, } } -static grpc_error *incoming_byte_stream_pull(grpc_exec_ctx *exec_ctx, - grpc_byte_stream *byte_stream, - grpc_slice *slice) { +static grpc_error* incoming_byte_stream_pull(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, + grpc_slice* slice) { GPR_TIMER_BEGIN("incoming_byte_stream_pull", 0); - grpc_chttp2_incoming_byte_stream *bs = - (grpc_chttp2_incoming_byte_stream *)byte_stream; - grpc_chttp2_stream *s = bs->stream; - grpc_error *error; + grpc_chttp2_incoming_byte_stream* bs = + (grpc_chttp2_incoming_byte_stream*)byte_stream; + grpc_chttp2_stream* s = bs->stream; + grpc_error* error; if (s->unprocessed_incoming_frames_buffer.length > 0) { if (!s->unprocessed_incoming_frames_decompressed) { @@ -2945,27 +2949,28 @@ static grpc_error *incoming_byte_stream_pull(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -static void incoming_byte_stream_destroy_locked(grpc_exec_ctx *exec_ctx, - void *byte_stream, - grpc_error *error_ignored); +static void incoming_byte_stream_destroy_locked(grpc_exec_ctx* exec_ctx, + void* byte_stream, + grpc_error* error_ignored); -static void incoming_byte_stream_destroy(grpc_exec_ctx *exec_ctx, - grpc_byte_stream *byte_stream) { +static void incoming_byte_stream_destroy(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream) { GPR_TIMER_BEGIN("incoming_byte_stream_destroy", 0); - grpc_chttp2_incoming_byte_stream *bs = - (grpc_chttp2_incoming_byte_stream *)byte_stream; + grpc_chttp2_incoming_byte_stream* bs = + (grpc_chttp2_incoming_byte_stream*)byte_stream; GRPC_CLOSURE_SCHED( - exec_ctx, GRPC_CLOSURE_INIT( - &bs->destroy_action, incoming_byte_stream_destroy_locked, - bs, grpc_combiner_scheduler(bs->transport->combiner)), + exec_ctx, + 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( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs, - grpc_error *error) { - grpc_chttp2_stream *s = bs->stream; + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_error* error) { + grpc_chttp2_stream* s = bs->stream; GPR_ASSERT(error != GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(exec_ctx, s->on_next, GRPC_ERROR_REF(error)); @@ -2976,13 +2981,13 @@ static void incoming_byte_stream_publish_error( GRPC_ERROR_REF(error)); } -grpc_error *grpc_chttp2_incoming_byte_stream_push( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs, - grpc_slice slice, grpc_slice *slice_out) { - grpc_chttp2_stream *s = bs->stream; +grpc_error* grpc_chttp2_incoming_byte_stream_push( + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_slice slice, grpc_slice* slice_out) { + grpc_chttp2_stream* s = bs->stream; if (bs->remaining_bytes < GRPC_SLICE_LENGTH(slice)) { - grpc_error *error = + grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many bytes in stream"); GRPC_CLOSURE_SCHED(exec_ctx, &s->reset_byte_stream, GRPC_ERROR_REF(error)); @@ -2997,10 +3002,10 @@ grpc_error *grpc_chttp2_incoming_byte_stream_push( } } -grpc_error *grpc_chttp2_incoming_byte_stream_finished( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs, - grpc_error *error, bool reset_on_error) { - grpc_chttp2_stream *s = bs->stream; +grpc_error* grpc_chttp2_incoming_byte_stream_finished( + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_error* error, bool reset_on_error) { + grpc_chttp2_stream* s = bs->stream; if (error == GRPC_ERROR_NONE) { if (bs->remaining_bytes != 0) { @@ -3014,11 +3019,11 @@ grpc_error *grpc_chttp2_incoming_byte_stream_finished( return error; } -static void incoming_byte_stream_shutdown(grpc_exec_ctx *exec_ctx, - grpc_byte_stream *byte_stream, - grpc_error *error) { - grpc_chttp2_incoming_byte_stream *bs = - (grpc_chttp2_incoming_byte_stream *)byte_stream; +static void incoming_byte_stream_shutdown(grpc_exec_ctx* exec_ctx, + grpc_byte_stream* byte_stream, + grpc_error* error) { + grpc_chttp2_incoming_byte_stream* bs = + (grpc_chttp2_incoming_byte_stream*)byte_stream; GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( exec_ctx, bs, error, true /* reset_on_error */)); } @@ -3027,13 +3032,13 @@ static const grpc_byte_stream_vtable grpc_chttp2_incoming_byte_stream_vtable = { incoming_byte_stream_next, incoming_byte_stream_pull, incoming_byte_stream_shutdown, incoming_byte_stream_destroy}; -static void incoming_byte_stream_destroy_locked(grpc_exec_ctx *exec_ctx, - void *byte_stream, - grpc_error *error_ignored) { - grpc_chttp2_incoming_byte_stream *bs = - (grpc_chttp2_incoming_byte_stream *)byte_stream; - grpc_chttp2_stream *s = bs->stream; - grpc_chttp2_transport *t = s->t; +static void incoming_byte_stream_destroy_locked(grpc_exec_ctx* exec_ctx, + void* byte_stream, + grpc_error* error_ignored) { + grpc_chttp2_incoming_byte_stream* bs = + (grpc_chttp2_incoming_byte_stream*)byte_stream; + grpc_chttp2_stream* s = bs->stream; + grpc_chttp2_transport* t = s->t; GPR_ASSERT(bs->base.vtable == &grpc_chttp2_incoming_byte_stream_vtable); incoming_byte_stream_unref(exec_ctx, bs); @@ -3042,11 +3047,11 @@ static void incoming_byte_stream_destroy_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } -grpc_chttp2_incoming_byte_stream *grpc_chttp2_incoming_byte_stream_create( - grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s, +grpc_chttp2_incoming_byte_stream* grpc_chttp2_incoming_byte_stream_create( + grpc_exec_ctx* exec_ctx, 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( + grpc_chttp2_incoming_byte_stream* incoming_byte_stream = + (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; @@ -3064,8 +3069,8 @@ grpc_chttp2_incoming_byte_stream *grpc_chttp2_incoming_byte_stream_create( * RESOURCE QUOTAS */ -static void post_benign_reclaimer(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { +static void post_benign_reclaimer(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { if (!t->benign_reclaimer_registered) { t->benign_reclaimer_registered = true; GRPC_CHTTP2_REF_TRANSPORT(t, "benign_reclaimer"); @@ -3075,8 +3080,8 @@ static void post_benign_reclaimer(grpc_exec_ctx *exec_ctx, } } -static void post_destructive_reclaimer(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { +static void post_destructive_reclaimer(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { if (!t->destructive_reclaimer_registered) { t->destructive_reclaimer_registered = true; GRPC_CHTTP2_REF_TRANSPORT(t, "destructive_reclaimer"); @@ -3086,9 +3091,9 @@ static void post_destructive_reclaimer(grpc_exec_ctx *exec_ctx, } } -static void benign_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)arg; +static void benign_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_chttp2_transport* t = (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 @@ -3116,14 +3121,14 @@ static void benign_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg, GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "benign_reclaimer"); } -static void destructive_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)arg; +static void destructive_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + grpc_chttp2_transport* t = (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 = + (grpc_chttp2_stream*)grpc_chttp2_stream_map_rand(&t->stream_map); if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { gpr_log(GPR_DEBUG, "HTTP2: %s - abandon stream id %d", t->peer_string, s->id); @@ -3152,7 +3157,7 @@ static void destructive_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg, * MONITORING */ -const char *grpc_chttp2_initiate_write_reason_string( +const char* grpc_chttp2_initiate_write_reason_string( grpc_chttp2_initiate_write_reason reason) { switch (reason) { case GRPC_CHTTP2_INITIATE_WRITE_INITIAL_WRITE: @@ -3199,9 +3204,9 @@ const char *grpc_chttp2_initiate_write_reason_string( GPR_UNREACHABLE_CODE(return "unknown"); } -static grpc_endpoint *chttp2_get_endpoint(grpc_exec_ctx *exec_ctx, - grpc_transport *t) { - return ((grpc_chttp2_transport *)t)->ep; +static grpc_endpoint* chttp2_get_endpoint(grpc_exec_ctx* exec_ctx, + grpc_transport* t) { + return ((grpc_chttp2_transport*)t)->ep; } static const grpc_transport_vtable vtable = {sizeof(grpc_chttp2_stream), @@ -3215,21 +3220,21 @@ static const grpc_transport_vtable vtable = {sizeof(grpc_chttp2_stream), destroy_transport, chttp2_get_endpoint}; -static const grpc_transport_vtable *get_vtable(void) { return &vtable; } +static const grpc_transport_vtable* get_vtable(void) { return &vtable; } -grpc_transport *grpc_create_chttp2_transport( - grpc_exec_ctx *exec_ctx, const grpc_channel_args *channel_args, - grpc_endpoint *ep, int is_client) { - grpc_chttp2_transport *t = - (grpc_chttp2_transport *)gpr_zalloc(sizeof(grpc_chttp2_transport)); +grpc_transport* grpc_create_chttp2_transport( + grpc_exec_ctx* exec_ctx, const grpc_channel_args* channel_args, + grpc_endpoint* ep, int is_client) { + grpc_chttp2_transport* t = + (grpc_chttp2_transport*)gpr_zalloc(sizeof(grpc_chttp2_transport)); init_transport(exec_ctx, t, channel_args, ep, is_client != 0); return &t->base; } -void grpc_chttp2_transport_start_reading(grpc_exec_ctx *exec_ctx, - grpc_transport *transport, - grpc_slice_buffer *read_buffer) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)transport; +void grpc_chttp2_transport_start_reading(grpc_exec_ctx* exec_ctx, + grpc_transport* transport, + grpc_slice_buffer* read_buffer) { + grpc_chttp2_transport* t = (grpc_chttp2_transport*)transport; GRPC_CHTTP2_REF_TRANSPORT( t, "reading_action"); /* matches unref inside reading_action */ if (read_buffer != NULL) { diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.h b/src/core/ext/transport/chttp2/transport/chttp2_transport.h index 321fca4c82..972104f62c 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.h +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.h @@ -35,15 +35,15 @@ extern grpc_tracer_flag grpc_trace_http2_stream_state; extern grpc_tracer_flag grpc_trace_chttp2_refcount; #endif -grpc_transport *grpc_create_chttp2_transport( - grpc_exec_ctx *exec_ctx, const grpc_channel_args *channel_args, - grpc_endpoint *ep, int is_client); +grpc_transport* grpc_create_chttp2_transport( + grpc_exec_ctx* exec_ctx, const grpc_channel_args* channel_args, + grpc_endpoint* ep, int is_client); /// Takes ownership of \a read_buffer, which (if non-NULL) contains /// leftover bytes previously read from the endpoint (e.g., by handshakers). -void grpc_chttp2_transport_start_reading(grpc_exec_ctx *exec_ctx, - grpc_transport *transport, - grpc_slice_buffer *read_buffer); +void grpc_chttp2_transport_start_reading(grpc_exec_ctx* exec_ctx, + grpc_transport* transport, + grpc_slice_buffer* read_buffer); #ifdef __cplusplus } diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index 40545bc74b..64f6b3c917 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -224,9 +224,9 @@ grpc_error* StreamFlowControl::RecvData(int64_t incoming_frame_size) { incoming_frame_size, acked_stream_window, sent_stream_window); } else { char* msg; - gpr_asprintf(&msg, "frame of size %" PRId64 - " overflows local window of %" PRId64, - incoming_frame_size, acked_stream_window); + gpr_asprintf( + &msg, "frame of size %" PRId64 " overflows local window of %" PRId64, + incoming_frame_size, acked_stream_window); grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; diff --git a/src/core/ext/transport/chttp2/transport/frame_data.cc b/src/core/ext/transport/chttp2/transport/frame_data.cc index 73aaab1802..7d2c7f5ab9 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.cc +++ b/src/core/ext/transport/chttp2/transport/frame_data.cc @@ -30,14 +30,14 @@ #include "src/core/lib/support/string.h" #include "src/core/lib/transport/transport.h" -grpc_error *grpc_chttp2_data_parser_init(grpc_chttp2_data_parser *parser) { +grpc_error* grpc_chttp2_data_parser_init(grpc_chttp2_data_parser* parser) { parser->state = GRPC_CHTTP2_DATA_FH_0; parser->parsing_frame = NULL; return GRPC_ERROR_NONE; } -void grpc_chttp2_data_parser_destroy(grpc_exec_ctx *exec_ctx, - grpc_chttp2_data_parser *parser) { +void grpc_chttp2_data_parser_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_data_parser* parser) { if (parser->parsing_frame != NULL) { GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( exec_ctx, parser->parsing_frame, @@ -46,14 +46,14 @@ void grpc_chttp2_data_parser_destroy(grpc_exec_ctx *exec_ctx, GRPC_ERROR_UNREF(parser->error); } -grpc_error *grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser *parser, +grpc_error* grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser* parser, uint8_t flags, uint32_t stream_id, - grpc_chttp2_stream *s) { + grpc_chttp2_stream* s) { if (flags & ~GRPC_CHTTP2_DATA_FLAG_END_STREAM) { - char *msg; + char* msg; gpr_asprintf(&msg, "unsupported data flags: 0x%02x", flags); - grpc_error *err = + grpc_error* err = grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg), GRPC_ERROR_INT_STREAM_ID, (intptr_t)stream_id); gpr_free(msg); @@ -69,12 +69,12 @@ grpc_error *grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser *parser, return GRPC_ERROR_NONE; } -void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer *inbuf, +void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer* inbuf, uint32_t write_bytes, int is_eof, - grpc_transport_one_way_stats *stats, - grpc_slice_buffer *outbuf) { + grpc_transport_one_way_stats* stats, + grpc_slice_buffer* outbuf) { grpc_slice hdr; - uint8_t *p; + uint8_t* p; static const size_t header_size = 9; hdr = GRPC_SLICE_MALLOC(header_size); @@ -97,17 +97,17 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer *inbuf, stats->data_bytes += write_bytes; } -grpc_error *grpc_deframe_unprocessed_incoming_frames( - grpc_exec_ctx *exec_ctx, grpc_chttp2_data_parser *p, grpc_chttp2_stream *s, - grpc_slice_buffer *slices, grpc_slice *slice_out, - grpc_byte_stream **stream_out) { - grpc_error *error = GRPC_ERROR_NONE; - grpc_chttp2_transport *t = s->t; +grpc_error* grpc_deframe_unprocessed_incoming_frames( + grpc_exec_ctx* exec_ctx, grpc_chttp2_data_parser* p, grpc_chttp2_stream* s, + grpc_slice_buffer* slices, grpc_slice* slice_out, + grpc_byte_stream** stream_out) { + grpc_error* error = GRPC_ERROR_NONE; + grpc_chttp2_transport* t = s->t; while (slices->count > 0) { - uint8_t *beg = NULL; - uint8_t *end = NULL; - uint8_t *cur = NULL; + uint8_t* beg = NULL; + uint8_t* end = NULL; + uint8_t* cur = NULL; grpc_slice slice = grpc_slice_buffer_take_first(slices); @@ -115,7 +115,7 @@ grpc_error *grpc_deframe_unprocessed_incoming_frames( end = GRPC_SLICE_END_PTR(slice); cur = beg; uint32_t message_flags; - char *msg; + char* msg; if (cur == end) { grpc_slice_unref_internal(exec_ctx, slice); @@ -289,9 +289,9 @@ grpc_error *grpc_deframe_unprocessed_incoming_frames( return GRPC_ERROR_NONE; } -grpc_error *grpc_chttp2_data_parser_parse(grpc_exec_ctx *exec_ctx, void *parser, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +grpc_error* grpc_chttp2_data_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last) { if (!s->pending_byte_stream) { grpc_slice_ref_internal(slice); diff --git a/src/core/ext/transport/chttp2/transport/frame_data.h b/src/core/ext/transport/chttp2/transport/frame_data.h index 81ec5361a3..96f823a0ad 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.h +++ b/src/core/ext/transport/chttp2/transport/frame_data.h @@ -49,40 +49,40 @@ typedef struct { grpc_chttp2_stream_state state; uint8_t frame_type; uint32_t frame_size; - grpc_error *error; + grpc_error* error; bool is_frame_compressed; - grpc_chttp2_incoming_byte_stream *parsing_frame; + grpc_chttp2_incoming_byte_stream* parsing_frame; } grpc_chttp2_data_parser; /* initialize per-stream state for data frame parsing */ -grpc_error *grpc_chttp2_data_parser_init(grpc_chttp2_data_parser *parser); +grpc_error* grpc_chttp2_data_parser_init(grpc_chttp2_data_parser* parser); -void grpc_chttp2_data_parser_destroy(grpc_exec_ctx *exec_ctx, - grpc_chttp2_data_parser *parser); +void grpc_chttp2_data_parser_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_data_parser* parser); /* start processing a new data frame */ -grpc_error *grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser *parser, +grpc_error* grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser* parser, uint8_t flags, uint32_t stream_id, - grpc_chttp2_stream *s); + grpc_chttp2_stream* s); /* handle a slice of a data frame - is_last indicates the last slice of a frame */ -grpc_error *grpc_chttp2_data_parser_parse(grpc_exec_ctx *exec_ctx, void *parser, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +grpc_error* grpc_chttp2_data_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last); -void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer *inbuf, +void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer* inbuf, uint32_t write_bytes, int is_eof, - grpc_transport_one_way_stats *stats, - grpc_slice_buffer *outbuf); + grpc_transport_one_way_stats* stats, + grpc_slice_buffer* outbuf); -grpc_error *grpc_deframe_unprocessed_incoming_frames( - grpc_exec_ctx *exec_ctx, grpc_chttp2_data_parser *p, grpc_chttp2_stream *s, - grpc_slice_buffer *slices, grpc_slice *slice_out, - grpc_byte_stream **stream_out); +grpc_error* grpc_deframe_unprocessed_incoming_frames( + grpc_exec_ctx* exec_ctx, grpc_chttp2_data_parser* p, grpc_chttp2_stream* s, + grpc_slice_buffer* slices, grpc_slice* slice_out, + grpc_byte_stream** stream_out); #ifdef __cplusplus } diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.cc b/src/core/ext/transport/chttp2/transport/frame_goaway.cc index 78ec08e177..6be1d0e0f0 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.cc +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.cc @@ -25,42 +25,42 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> -void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser *p) { +void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser* p) { p->debug_data = NULL; } -void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser *p) { +void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser* p) { gpr_free(p->debug_data); } -grpc_error *grpc_chttp2_goaway_parser_begin_frame(grpc_chttp2_goaway_parser *p, +grpc_error* grpc_chttp2_goaway_parser_begin_frame(grpc_chttp2_goaway_parser* p, uint32_t length, uint8_t flags) { if (length < 8) { - char *msg; + char* msg; gpr_asprintf(&msg, "goaway frame too short (%d bytes)", length); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } gpr_free(p->debug_data); p->debug_length = length - 8; - p->debug_data = (char *)gpr_malloc(p->debug_length); + p->debug_data = (char*)gpr_malloc(p->debug_length); p->debug_pos = 0; p->state = GRPC_CHTTP2_GOAWAY_LSI0; return GRPC_ERROR_NONE; } -grpc_error *grpc_chttp2_goaway_parser_parse(grpc_exec_ctx *exec_ctx, - void *parser, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +grpc_error* grpc_chttp2_goaway_parser_parse(grpc_exec_ctx* exec_ctx, + void* parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last) { - 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; + 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; switch (p->state) { case GRPC_CHTTP2_GOAWAY_LSI0: @@ -147,9 +147,9 @@ grpc_error *grpc_chttp2_goaway_parser_parse(grpc_exec_ctx *exec_ctx, void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code, grpc_slice debug_data, - grpc_slice_buffer *slice_buffer) { + grpc_slice_buffer* slice_buffer) { grpc_slice header = GRPC_SLICE_MALLOC(9 + 4 + 4); - uint8_t *p = GRPC_SLICE_START_PTR(header); + 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); diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.h b/src/core/ext/transport/chttp2/transport/frame_goaway.h index 7b3aa45f3f..9790d0b08d 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.h +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.h @@ -45,24 +45,24 @@ typedef struct { grpc_chttp2_goaway_parse_state state; uint32_t last_stream_id; uint32_t error_code; - char *debug_data; + char* debug_data; uint32_t debug_length; uint32_t debug_pos; } grpc_chttp2_goaway_parser; -void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser *p); -void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser *p); -grpc_error *grpc_chttp2_goaway_parser_begin_frame( - grpc_chttp2_goaway_parser *parser, uint32_t length, uint8_t flags); -grpc_error *grpc_chttp2_goaway_parser_parse(grpc_exec_ctx *exec_ctx, - void *parser, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser* p); +void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser* p); +grpc_error* grpc_chttp2_goaway_parser_begin_frame( + grpc_chttp2_goaway_parser* parser, uint32_t length, uint8_t flags); +grpc_error* grpc_chttp2_goaway_parser_parse(grpc_exec_ctx* exec_ctx, + void* parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last); void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code, grpc_slice debug_data, - grpc_slice_buffer *slice_buffer); + grpc_slice_buffer* slice_buffer); #ifdef __cplusplus } diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.cc b/src/core/ext/transport/chttp2/transport/frame_ping.cc index 1cfa883ee1..d0feb51922 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.cc +++ b/src/core/ext/transport/chttp2/transport/frame_ping.cc @@ -29,7 +29,7 @@ static bool g_disable_ping_ack = false; grpc_slice grpc_chttp2_ping_create(uint8_t ack, uint64_t opaque_8bytes) { grpc_slice slice = GRPC_SLICE_MALLOC(9 + 8); - uint8_t *p = GRPC_SLICE_START_PTR(slice); + uint8_t* p = GRPC_SLICE_START_PTR(slice); *p++ = 0; *p++ = 0; @@ -52,13 +52,13 @@ grpc_slice grpc_chttp2_ping_create(uint8_t ack, uint64_t opaque_8bytes) { return slice; } -grpc_error *grpc_chttp2_ping_parser_begin_frame(grpc_chttp2_ping_parser *parser, +grpc_error* grpc_chttp2_ping_parser_begin_frame(grpc_chttp2_ping_parser* parser, uint32_t length, uint8_t flags) { if (flags & 0xfe || length != 8) { - char *msg; + char* msg; gpr_asprintf(&msg, "invalid ping: length=%d, flags=%02x", length, flags); - grpc_error *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return error; } @@ -68,14 +68,14 @@ grpc_error *grpc_chttp2_ping_parser_begin_frame(grpc_chttp2_ping_parser *parser, return GRPC_ERROR_NONE; } -grpc_error *grpc_chttp2_ping_parser_parse(grpc_exec_ctx *exec_ctx, void *parser, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +grpc_error* grpc_chttp2_ping_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last) { - 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; + 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; while (p->byte != 8 && cur != end) { p->opaque_8bytes |= (((uint64_t)*cur) << (56 - 8 * p->byte)); @@ -112,7 +112,7 @@ grpc_error *grpc_chttp2_ping_parser_parse(grpc_exec_ctx *exec_ctx, 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 = (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; diff --git a/src/core/ext/transport/chttp2/transport/frame_ping.h b/src/core/ext/transport/chttp2/transport/frame_ping.h index ffc2f0cf2f..034aad002e 100644 --- a/src/core/ext/transport/chttp2/transport/frame_ping.h +++ b/src/core/ext/transport/chttp2/transport/frame_ping.h @@ -35,11 +35,11 @@ typedef struct { grpc_slice grpc_chttp2_ping_create(uint8_t ack, uint64_t opaque_8bytes); -grpc_error *grpc_chttp2_ping_parser_begin_frame(grpc_chttp2_ping_parser *parser, +grpc_error* grpc_chttp2_ping_parser_begin_frame(grpc_chttp2_ping_parser* parser, uint32_t length, uint8_t flags); -grpc_error *grpc_chttp2_ping_parser_parse(grpc_exec_ctx *exec_ctx, void *parser, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +grpc_error* grpc_chttp2_ping_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last); /* Test-only function for disabling ping ack */ 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 0133b6efa2..05a7f056a4 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc @@ -27,11 +27,11 @@ #include "src/core/lib/transport/http2_errors.h" grpc_slice grpc_chttp2_rst_stream_create(uint32_t id, uint32_t code, - grpc_transport_one_way_stats *stats) { + grpc_transport_one_way_stats* stats) { static const size_t frame_size = 13; grpc_slice slice = GRPC_SLICE_MALLOC(frame_size); stats->framing_bytes += frame_size; - uint8_t *p = GRPC_SLICE_START_PTR(slice); + uint8_t* p = GRPC_SLICE_START_PTR(slice); // Frame size. *p++ = 0; @@ -55,13 +55,13 @@ grpc_slice grpc_chttp2_rst_stream_create(uint32_t id, uint32_t code, return slice; } -grpc_error *grpc_chttp2_rst_stream_parser_begin_frame( - grpc_chttp2_rst_stream_parser *parser, uint32_t length, uint8_t flags) { +grpc_error* grpc_chttp2_rst_stream_parser_begin_frame( + grpc_chttp2_rst_stream_parser* parser, uint32_t length, uint8_t flags) { if (length != 4) { - char *msg; + char* msg; gpr_asprintf(&msg, "invalid rst_stream: length=%d, flags=%02x", length, flags); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } @@ -69,15 +69,15 @@ grpc_error *grpc_chttp2_rst_stream_parser_begin_frame( return GRPC_ERROR_NONE; } -grpc_error *grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx *exec_ctx, - void *parser, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +grpc_error* grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx* exec_ctx, + void* parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last) { - 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; + 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; while (p->byte != 4 && cur != end) { p->reason_bytes[p->byte] = *cur; @@ -92,9 +92,9 @@ grpc_error *grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx *exec_ctx, (((uint32_t)p->reason_bytes[1]) << 16) | (((uint32_t)p->reason_bytes[2]) << 8) | (((uint32_t)p->reason_bytes[3])); - grpc_error *error = GRPC_ERROR_NONE; + grpc_error* error = GRPC_ERROR_NONE; if (reason != GRPC_HTTP2_NO_ERROR || s->metadata_buffer[1].size == 0) { - char *message; + char* message; gpr_asprintf(&message, "Received RST_STREAM with error code %d", reason); error = grpc_error_set_int( grpc_error_set_str(GRPC_ERROR_CREATE_FROM_STATIC_STRING("RST_STREAM"), diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.h b/src/core/ext/transport/chttp2/transport/frame_rst_stream.h index 102ffdb3f3..3f5417e993 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.h @@ -34,14 +34,14 @@ typedef struct { } grpc_chttp2_rst_stream_parser; grpc_slice grpc_chttp2_rst_stream_create(uint32_t stream_id, uint32_t code, - grpc_transport_one_way_stats *stats); - -grpc_error *grpc_chttp2_rst_stream_parser_begin_frame( - grpc_chttp2_rst_stream_parser *parser, uint32_t length, uint8_t flags); -grpc_error *grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx *exec_ctx, - void *parser, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, + grpc_transport_one_way_stats* stats); + +grpc_error* grpc_chttp2_rst_stream_parser_begin_frame( + grpc_chttp2_rst_stream_parser* parser, uint32_t length, uint8_t flags); +grpc_error* grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx* exec_ctx, + void* parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last); #ifdef __cplusplus diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index db0245bb57..d33da721a5 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -31,7 +31,7 @@ #include "src/core/lib/debug/trace.h" #include "src/core/lib/transport/http2_errors.h" -static uint8_t *fill_header(uint8_t *out, uint32_t length, uint8_t flags) { +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); @@ -44,13 +44,13 @@ static uint8_t *fill_header(uint8_t *out, uint32_t length, uint8_t flags) { return out; } -grpc_slice grpc_chttp2_settings_create(uint32_t *old_settings, - const uint32_t *new_settings, +grpc_slice grpc_chttp2_settings_create(uint32_t* old_settings, + const uint32_t* new_settings, uint32_t force_mask, size_t count) { size_t i; uint32_t n = 0; grpc_slice output; - uint8_t *p; + uint8_t* p; for (i = 0; i < count; i++) { n += (new_settings[i] != old_settings[i] || (force_mask & (1u << i)) != 0); @@ -82,9 +82,9 @@ grpc_slice grpc_chttp2_settings_ack_create(void) { return output; } -grpc_error *grpc_chttp2_settings_parser_begin_frame( - grpc_chttp2_settings_parser *parser, uint32_t length, uint8_t flags, - uint32_t *settings) { +grpc_error* grpc_chttp2_settings_parser_begin_frame( + grpc_chttp2_settings_parser* parser, uint32_t length, uint8_t flags, + uint32_t* settings) { parser->target_settings = settings; memcpy(parser->incoming_settings, settings, GRPC_CHTTP2_NUM_SETTINGS * sizeof(uint32_t)); @@ -108,14 +108,14 @@ grpc_error *grpc_chttp2_settings_parser_begin_frame( } } -grpc_error *grpc_chttp2_settings_parser_parse(grpc_exec_ctx *exec_ctx, void *p, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +grpc_error* grpc_chttp2_settings_parser_parse(grpc_exec_ctx* exec_ctx, 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; - const uint8_t *cur = GRPC_SLICE_START_PTR(slice); - const uint8_t *end = GRPC_SLICE_END_PTR(slice); - char *msg; + grpc_chttp2_settings_parser* parser = (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; grpc_chttp2_setting_id id; if (parser->is_ack) { @@ -180,7 +180,7 @@ grpc_error *grpc_chttp2_settings_parser_parse(grpc_exec_ctx *exec_ctx, void *p, cur++; if (grpc_wire_id_to_setting_id(parser->id, &id)) { - const grpc_chttp2_setting_parameters *sp = + const grpc_chttp2_setting_parameters* sp = &grpc_chttp2_settings_parameters[id]; if (parser->value < sp->min_value || parser->value > sp->max_value) { switch (sp->invalid_value_behavior) { @@ -195,7 +195,7 @@ grpc_error *grpc_chttp2_settings_parser_parse(grpc_exec_ctx *exec_ctx, void *p, &t->qbuf); gpr_asprintf(&msg, "invalid value %u passed for %s", parser->value, sp->name); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.h b/src/core/ext/transport/chttp2/transport/frame_settings.h index 3364da1520..18bde92815 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.h +++ b/src/core/ext/transport/chttp2/transport/frame_settings.h @@ -40,7 +40,7 @@ typedef enum { typedef struct { grpc_chttp2_settings_parse_state state; - uint32_t *target_settings; + uint32_t* target_settings; uint8_t is_ack; uint16_t id; uint32_t value; @@ -48,18 +48,18 @@ typedef struct { } grpc_chttp2_settings_parser; /* Create a settings frame by diffing old & new, and updating old to be new */ -grpc_slice grpc_chttp2_settings_create(uint32_t *old, const uint32_t *newval, +grpc_slice grpc_chttp2_settings_create(uint32_t* old, const uint32_t* newval, uint32_t force_mask, size_t count); /* Create an ack settings frame */ grpc_slice grpc_chttp2_settings_ack_create(void); -grpc_error *grpc_chttp2_settings_parser_begin_frame( - grpc_chttp2_settings_parser *parser, uint32_t length, uint8_t flags, - uint32_t *settings); -grpc_error *grpc_chttp2_settings_parser_parse(grpc_exec_ctx *exec_ctx, - void *parser, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +grpc_error* grpc_chttp2_settings_parser_begin_frame( + grpc_chttp2_settings_parser* parser, uint32_t length, uint8_t flags, + uint32_t* settings); +grpc_error* grpc_chttp2_settings_parser_parse(grpc_exec_ctx* exec_ctx, + void* parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last); #ifdef __cplusplus 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 15eaf59285..62a4587ac6 100644 --- a/src/core/ext/transport/chttp2/transport/frame_window_update.cc +++ b/src/core/ext/transport/chttp2/transport/frame_window_update.cc @@ -24,11 +24,11 @@ #include <grpc/support/string_util.h> grpc_slice grpc_chttp2_window_update_create( - uint32_t id, uint32_t window_update, grpc_transport_one_way_stats *stats) { + uint32_t id, uint32_t window_update, grpc_transport_one_way_stats* stats) { static const size_t frame_size = 13; grpc_slice slice = GRPC_SLICE_MALLOC(frame_size); stats->header_bytes += frame_size; - uint8_t *p = GRPC_SLICE_START_PTR(slice); + uint8_t* p = GRPC_SLICE_START_PTR(slice); GPR_ASSERT(window_update); @@ -49,13 +49,13 @@ grpc_slice grpc_chttp2_window_update_create( return slice; } -grpc_error *grpc_chttp2_window_update_parser_begin_frame( - grpc_chttp2_window_update_parser *parser, uint32_t length, uint8_t flags) { +grpc_error* grpc_chttp2_window_update_parser_begin_frame( + grpc_chttp2_window_update_parser* parser, uint32_t length, uint8_t flags) { if (flags || length != 4) { - char *msg; + char* msg; gpr_asprintf(&msg, "invalid window update: length=%d, flags=%02x", length, flags); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } @@ -64,14 +64,14 @@ grpc_error *grpc_chttp2_window_update_parser_begin_frame( return GRPC_ERROR_NONE; } -grpc_error *grpc_chttp2_window_update_parser_parse( - grpc_exec_ctx *exec_ctx, void *parser, grpc_chttp2_transport *t, - grpc_chttp2_stream *s, grpc_slice slice, int is_last) { - uint8_t *const beg = GRPC_SLICE_START_PTR(slice); - 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; +grpc_error* grpc_chttp2_window_update_parser_parse( + grpc_exec_ctx* exec_ctx, void* parser, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last) { + uint8_t* const beg = GRPC_SLICE_START_PTR(slice); + 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; while (p->byte != 4 && cur != end) { p->amount |= ((uint32_t)*cur) << (8 * (3 - p->byte)); @@ -86,9 +86,9 @@ grpc_error *grpc_chttp2_window_update_parser_parse( if (p->byte == 4) { uint32_t received_update = p->amount; if (received_update == 0 || (received_update & 0x80000000u)) { - char *msg; + char* msg; gpr_asprintf(&msg, "invalid window update bytes: %d", p->amount); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } diff --git a/src/core/ext/transport/chttp2/transport/frame_window_update.h b/src/core/ext/transport/chttp2/transport/frame_window_update.h index 400f9f5398..daf7d2da6b 100644 --- a/src/core/ext/transport/chttp2/transport/frame_window_update.h +++ b/src/core/ext/transport/chttp2/transport/frame_window_update.h @@ -35,13 +35,13 @@ typedef struct { } grpc_chttp2_window_update_parser; grpc_slice grpc_chttp2_window_update_create( - uint32_t id, uint32_t window_delta, grpc_transport_one_way_stats *stats); + uint32_t id, uint32_t window_delta, grpc_transport_one_way_stats* stats); -grpc_error *grpc_chttp2_window_update_parser_begin_frame( - grpc_chttp2_window_update_parser *parser, uint32_t length, uint8_t flags); -grpc_error *grpc_chttp2_window_update_parser_parse( - grpc_exec_ctx *exec_ctx, void *parser, grpc_chttp2_transport *t, - grpc_chttp2_stream *s, grpc_slice slice, int is_last); +grpc_error* grpc_chttp2_window_update_parser_begin_frame( + grpc_chttp2_window_update_parser* parser, uint32_t length, uint8_t flags); +grpc_error* grpc_chttp2_window_update_parser_parse( + grpc_exec_ctx* exec_ctx, void* parser, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last); #ifdef __cplusplus } diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index 0ea50e394b..3636440905 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -70,15 +70,15 @@ typedef struct { uint8_t seen_regular_header; /* output stream id */ uint32_t stream_id; - grpc_slice_buffer *output; - grpc_transport_one_way_stats *stats; + grpc_slice_buffer* output; + grpc_transport_one_way_stats* stats; /* maximum size of a frame */ size_t max_frame_size; bool use_true_binary_metadata; } framer_state; /* fills p (which is expected to be 9 bytes long) with a data frame header */ -static void fill_header(uint8_t *p, uint8_t type, uint32_t id, size_t len, +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); @@ -93,7 +93,7 @@ static void fill_header(uint8_t *p, uint8_t type, uint32_t id, size_t len, } /* finish a frame - fill in the previously reserved header */ -static void finish_frame(framer_state *st, int is_header_boundary, +static void finish_frame(framer_state* st, int is_header_boundary, int is_last_in_stream) { uint8_t type = 0xff; type = st->is_first_frame ? GRPC_CHTTP2_FRAME_HEADER @@ -109,7 +109,7 @@ static void finish_frame(framer_state *st, int is_header_boundary, /* begin a new frame: reserve off header space, remember how many bytes we'd output before beginning */ -static void begin_frame(framer_state *st) { +static void begin_frame(framer_state* st) { st->header_idx = grpc_slice_buffer_add_indexed(st->output, GRPC_SLICE_MALLOC(9)); st->output_length_at_start_of_frame = st->output->length; @@ -118,7 +118,7 @@ static void begin_frame(framer_state *st) { /* make sure that the current frame is of the type desired, and has sufficient space to add at least about_to_add bytes -- finishes the current frame if needed */ -static void ensure_space(framer_state *st, size_t need_bytes) { +static void ensure_space(framer_state* st, size_t need_bytes) { if (st->output->length - st->output_length_at_start_of_frame + need_bytes <= st->max_frame_size) { return; @@ -128,7 +128,7 @@ static void ensure_space(framer_state *st, size_t need_bytes) { } /* increment a filter count, halve all counts if one element reaches max */ -static void inc_filter(uint8_t idx, uint32_t *sum, uint8_t *elems) { +static void inc_filter(uint8_t idx, uint32_t* sum, uint8_t* elems) { elems[idx]++; if (elems[idx] < 255) { (*sum)++; @@ -142,7 +142,7 @@ static void inc_filter(uint8_t idx, uint32_t *sum, uint8_t *elems) { } } -static void add_header_data(framer_state *st, grpc_slice slice) { +static void add_header_data(framer_state* st, grpc_slice slice) { size_t len = GRPC_SLICE_LENGTH(slice); size_t remaining; if (len == 0) return; @@ -160,13 +160,13 @@ static void add_header_data(framer_state *st, grpc_slice slice) { } } -static uint8_t *add_tiny_header_data(framer_state *st, size_t len) { +static uint8_t* add_tiny_header_data(framer_state* st, size_t len) { ensure_space(st, len); st->stats->header_bytes += len; return grpc_slice_buffer_tiny_add(st->output, len); } -static void evict_entry(grpc_chttp2_hpack_compressor *c) { +static void evict_entry(grpc_chttp2_hpack_compressor* c) { c->tail_remote_index++; GPR_ASSERT(c->tail_remote_index > 0); GPR_ASSERT(c->table_size >= @@ -181,7 +181,7 @@ static void evict_entry(grpc_chttp2_hpack_compressor *c) { // Reserve space in table for the new element, evict entries if needed. // Return the new index of the element. Return 0 to indicate not adding to // table. -static uint32_t prepare_space_for_new_elem(grpc_chttp2_hpack_compressor *c, +static uint32_t prepare_space_for_new_elem(grpc_chttp2_hpack_compressor* c, size_t elem_size) { uint32_t new_index = c->tail_remote_index + c->table_elems + 1; GPR_ASSERT(elem_size < 65536); @@ -208,14 +208,14 @@ static uint32_t prepare_space_for_new_elem(grpc_chttp2_hpack_compressor *c, } /* dummy function */ -static void add_nothing(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c, grpc_mdelem elem, +static void add_nothing(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, size_t elem_size) {} // Add a key to the dynamic table. Both key and value will be added to table at // the decoder. -static void add_key_with_index(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c, +static void add_key_with_index(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, uint32_t new_index) { if (new_index == 0) { return; @@ -257,8 +257,8 @@ static void add_key_with_index(grpc_exec_ctx *exec_ctx, } /* add an element to the decoder table */ -static void add_elem_with_index(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c, +static void add_elem_with_index(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, uint32_t new_index) { if (new_index == 0) { return; @@ -301,21 +301,21 @@ static void add_elem_with_index(grpc_exec_ctx *exec_ctx, add_key_with_index(exec_ctx, c, elem, new_index); } -static void add_elem(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, +static void add_elem(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, size_t elem_size) { uint32_t new_index = prepare_space_for_new_elem(c, elem_size); add_elem_with_index(exec_ctx, c, elem, new_index); } -static void add_key(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, +static void add_key(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, grpc_mdelem elem, size_t elem_size) { uint32_t new_index = prepare_space_for_new_elem(c, elem_size); add_key_with_index(exec_ctx, c, elem, new_index); } -static void emit_indexed(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c, uint32_t elem_index, - framer_state *st) { +static void emit_indexed(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, uint32_t elem_index, + framer_state* st) { GRPC_STATS_INC_HPACK_SEND_INDEXED(exec_ctx); uint32_t len = GRPC_CHTTP2_VARINT_LENGTH(elem_index, 1); GRPC_CHTTP2_WRITE_VARINT(elem_index, 1, 0x80, add_tiny_header_data(st, len), @@ -328,7 +328,7 @@ typedef struct { bool insert_null_before_wire_value; } wire_value; -static wire_value get_wire_value(grpc_exec_ctx *exec_ctx, grpc_mdelem elem, +static wire_value get_wire_value(grpc_exec_ctx* exec_ctx, grpc_mdelem elem, bool true_binary_enabled) { wire_value wire_val; if (grpc_is_binary_header(GRPC_MDKEY(elem))) { @@ -359,15 +359,15 @@ static size_t wire_value_length(wire_value v) { return GPR_SLICE_LENGTH(v.data) + v.insert_null_before_wire_value; } -static void add_wire_value(framer_state *st, wire_value v) { +static void add_wire_value(framer_state* st, wire_value v) { if (v.insert_null_before_wire_value) *add_tiny_header_data(st, 1) = 0; add_header_data(st, v.data); } -static void emit_lithdr_incidx(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c, +static void emit_lithdr_incidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, uint32_t key_index, grpc_mdelem elem, - framer_state *st) { + framer_state* st) { GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX(exec_ctx); uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2); wire_value value = @@ -383,10 +383,10 @@ static void emit_lithdr_incidx(grpc_exec_ctx *exec_ctx, add_wire_value(st, value); } -static void emit_lithdr_noidx(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c, +static void emit_lithdr_noidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, uint32_t key_index, grpc_mdelem elem, - framer_state *st) { + framer_state* st) { GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX(exec_ctx); uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4); wire_value value = @@ -402,10 +402,10 @@ static void emit_lithdr_noidx(grpc_exec_ctx *exec_ctx, add_wire_value(st, value); } -static void emit_lithdr_incidx_v(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c, +static void emit_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, uint32_t unused_index, grpc_mdelem elem, - framer_state *st) { + framer_state* st) { GPR_ASSERT(unused_index == 0); GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V(exec_ctx); GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(exec_ctx); @@ -426,10 +426,10 @@ static void emit_lithdr_incidx_v(grpc_exec_ctx *exec_ctx, add_wire_value(st, value); } -static void emit_lithdr_noidx_v(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c, +static void emit_lithdr_noidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, uint32_t unused_index, grpc_mdelem elem, - framer_state *st) { + framer_state* st) { GPR_ASSERT(unused_index == 0); GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V(exec_ctx); GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED(exec_ctx); @@ -450,22 +450,22 @@ static void emit_lithdr_noidx_v(grpc_exec_ctx *exec_ctx, add_wire_value(st, value); } -static void emit_advertise_table_size_change(grpc_chttp2_hpack_compressor *c, - framer_state *st) { +static void emit_advertise_table_size_change(grpc_chttp2_hpack_compressor* c, + framer_state* st) { uint32_t len = GRPC_CHTTP2_VARINT_LENGTH(c->max_table_size, 3); GRPC_CHTTP2_WRITE_VARINT(c->max_table_size, 3, 0x20, add_tiny_header_data(st, len), len); c->advertise_table_size_change = 0; } -static uint32_t dynidx(grpc_chttp2_hpack_compressor *c, uint32_t elem_index) { +static uint32_t dynidx(grpc_chttp2_hpack_compressor* c, uint32_t elem_index) { return 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY + c->tail_remote_index + c->table_elems - elem_index; } /* encode an mdelem */ -static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, - grpc_mdelem elem, framer_state *st) { +static void hpack_enc(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, + grpc_mdelem elem, framer_state* st) { GPR_ASSERT(GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)) > 0); if (GRPC_SLICE_START_PTR(GRPC_MDKEY(elem))[0] != ':') { /* regular header */ st->seen_regular_header = 1; @@ -476,8 +476,8 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, } if (GRPC_TRACER_ON(grpc_http_trace)) { - char *k = grpc_slice_to_c_string(GRPC_MDKEY(elem)); - char *v = NULL; + char* k = grpc_slice_to_c_string(GRPC_MDKEY(elem)); + char* v = NULL; if (grpc_is_binary_header(GRPC_MDKEY(elem))) { v = grpc_dump_slice(GRPC_MDVALUE(elem), GPR_DUMP_HEX); } else { @@ -540,11 +540,10 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, decoder_space_usage < MAX_DECODER_SPACE_USAGE && c->filter_elems[HASH_FRAGMENT_1(elem_hash)] >= c->filter_elems_sum / ONE_ON_ADD_PROBABILITY; - void (*maybe_add)(grpc_exec_ctx *, grpc_chttp2_hpack_compressor *, - grpc_mdelem, size_t) = - should_add_elem ? add_elem : add_nothing; - void (*emit)(grpc_exec_ctx *, grpc_chttp2_hpack_compressor *, uint32_t, - grpc_mdelem, framer_state *) = + void (*maybe_add)(grpc_exec_ctx*, grpc_chttp2_hpack_compressor*, grpc_mdelem, + size_t) = should_add_elem ? add_elem : add_nothing; + void (*emit)(grpc_exec_ctx*, grpc_chttp2_hpack_compressor*, uint32_t, + grpc_mdelem, framer_state*) = should_add_elem ? emit_lithdr_incidx : emit_lithdr_noidx; /* no hits for the elem... maybe there's a key? */ @@ -582,9 +581,9 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, #define STRLEN_LIT(x) (sizeof(x) - 1) #define TIMEOUT_KEY "grpc-timeout" -static void deadline_enc(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c, grpc_millis deadline, - framer_state *st) { +static void deadline_enc(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, grpc_millis deadline, + framer_state* st) { char timeout_str[GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE]; grpc_mdelem mdelem; grpc_http2_encode_timeout(deadline - grpc_exec_ctx_now(exec_ctx), @@ -597,14 +596,14 @@ static void deadline_enc(grpc_exec_ctx *exec_ctx, static uint32_t elems_for_bytes(uint32_t bytes) { return (bytes + 31) / 32; } -void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c) { +void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor* c) { memset(c, 0, sizeof(*c)); c->max_table_size = GRPC_CHTTP2_HPACKC_INITIAL_TABLE_SIZE; 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); + (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++) { @@ -612,8 +611,8 @@ void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c) { } } -void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c) { +void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c) { int i; for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_VALUES; i++) { if (c->entries_keys[i].refcount != &terminal_slice_refcount) { @@ -625,15 +624,15 @@ void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx *exec_ctx, } void grpc_chttp2_hpack_compressor_set_max_usable_size( - grpc_chttp2_hpack_compressor *c, uint32_t max_table_size) { + grpc_chttp2_hpack_compressor* c, uint32_t max_table_size) { c->max_usable_size = max_table_size; grpc_chttp2_hpack_compressor_set_max_table_size( c, GPR_MIN(c->max_table_size, max_table_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 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); uint32_t i; memset(table_elem_size, 0, sizeof(*table_elem_size) * new_cap); @@ -651,7 +650,7 @@ static void rebuild_elems(grpc_chttp2_hpack_compressor *c, uint32_t new_cap) { } void grpc_chttp2_hpack_compressor_set_max_table_size( - grpc_chttp2_hpack_compressor *c, uint32_t max_table_size) { + grpc_chttp2_hpack_compressor* c, uint32_t max_table_size) { max_table_size = GPR_MIN(max_table_size, c->max_usable_size); if (max_table_size == c->max_table_size) { return; @@ -675,13 +674,13 @@ void grpc_chttp2_hpack_compressor_set_max_table_size( } } -void grpc_chttp2_encode_header(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c, - grpc_mdelem **extra_headers, +void grpc_chttp2_encode_header(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, + grpc_mdelem** extra_headers, size_t extra_headers_size, - grpc_metadata_batch *metadata, - const grpc_encode_header_options *options, - grpc_slice_buffer *outbuf) { + grpc_metadata_batch* metadata, + const grpc_encode_header_options* options, + grpc_slice_buffer* outbuf) { GPR_ASSERT(options->stream_id != 0); framer_state st; @@ -705,7 +704,7 @@ void grpc_chttp2_encode_header(grpc_exec_ctx *exec_ctx, hpack_enc(exec_ctx, c, *extra_headers[i], &st); } grpc_metadata_batch_assert_ok(metadata); - for (grpc_linked_mdelem *l = metadata->list.head; l; l = l->next) { + for (grpc_linked_mdelem* l = metadata->list.head; l; l = l->next) { hpack_enc(exec_ctx, c, l->md, &st); } grpc_millis deadline = metadata->deadline; diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.h b/src/core/ext/transport/chttp2/transport/hpack_encoder.h index 16316b63f7..fd01d1621a 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.h +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.h @@ -68,32 +68,32 @@ typedef struct { uint32_t indices_keys[GRPC_CHTTP2_HPACKC_NUM_VALUES]; uint32_t indices_elems[GRPC_CHTTP2_HPACKC_NUM_VALUES]; - uint16_t *table_elem_size; + uint16_t* table_elem_size; } grpc_chttp2_hpack_compressor; -void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c); -void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c); +void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor* c); +void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c); void grpc_chttp2_hpack_compressor_set_max_table_size( - grpc_chttp2_hpack_compressor *c, uint32_t max_table_size); + grpc_chttp2_hpack_compressor* c, uint32_t max_table_size); void grpc_chttp2_hpack_compressor_set_max_usable_size( - grpc_chttp2_hpack_compressor *c, uint32_t max_table_size); + grpc_chttp2_hpack_compressor* c, uint32_t max_table_size); typedef struct { uint32_t stream_id; bool is_eof; bool use_true_binary_metadata; size_t max_frame_size; - grpc_transport_one_way_stats *stats; + grpc_transport_one_way_stats* stats; } grpc_encode_header_options; -void grpc_chttp2_encode_header(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_compressor *c, - grpc_mdelem **extra_headers, +void grpc_chttp2_encode_header(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_compressor* c, + grpc_mdelem** extra_headers, size_t extra_headers_size, - grpc_metadata_batch *metadata, - const grpc_encode_header_options *options, - grpc_slice_buffer *outbuf); + grpc_metadata_batch* metadata, + const grpc_encode_header_options* options, + grpc_slice_buffer* outbuf); #ifdef __cplusplus } diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 7c17229122..1181402918 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -61,97 +61,97 @@ typedef enum { a set of indirect jumps, and so not waste stack space. */ /* forward declarations for parsing states */ -static grpc_error *parse_begin(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_error(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end, grpc_error *error); -static grpc_error *still_parse_error(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end); -static grpc_error *parse_illegal_op(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end); - -static grpc_error *parse_string_prefix(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end); -static grpc_error *parse_key_string(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end); -static grpc_error *parse_value_string_with_indexed_key( - grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_value_string_with_literal_key( - grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end); - -static grpc_error *parse_value0(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_value1(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_value2(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_value3(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_value4(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_value5up(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end); - -static grpc_error *parse_indexed_field(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end); -static grpc_error *parse_indexed_field_x(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_lithdr_incidx(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end); -static grpc_error *parse_lithdr_incidx_x(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_lithdr_incidx_v(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_lithdr_notidx(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end); -static grpc_error *parse_lithdr_notidx_x(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_lithdr_notidx_v(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_lithdr_nvridx(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end); -static grpc_error *parse_lithdr_nvridx_x(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end); -static grpc_error *parse_max_tbl_size(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end); -static grpc_error *parse_max_tbl_size_x(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end); +static grpc_error* parse_begin(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_error(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end, grpc_error* error); +static grpc_error* still_parse_error(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end); +static grpc_error* parse_illegal_op(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end); + +static grpc_error* parse_string_prefix(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end); +static grpc_error* parse_key_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end); +static grpc_error* parse_value_string_with_indexed_key( + grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_value_string_with_literal_key( + grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end); + +static grpc_error* parse_value0(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_value1(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_value2(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_value3(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_value4(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_value5up(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end); + +static grpc_error* parse_indexed_field(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end); +static grpc_error* parse_indexed_field_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_lithdr_incidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end); +static grpc_error* parse_lithdr_incidx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_lithdr_notidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end); +static grpc_error* parse_lithdr_notidx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_lithdr_notidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_lithdr_nvridx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end); +static grpc_error* parse_lithdr_nvridx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_lithdr_nvridx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end); +static grpc_error* parse_max_tbl_size(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end); +static grpc_error* parse_max_tbl_size_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end); /* we translate the first byte of a hpack field into one of these decoding cases, then use a lookup table to jump directly to the appropriate parser. @@ -649,11 +649,11 @@ static const uint8_t inverse_base64[256] = { }; /* emission helpers */ -static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, +static grpc_error* on_hdr(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, grpc_mdelem md, int add_to_table) { if (GRPC_TRACER_ON(grpc_http_trace)) { - char *k = grpc_slice_to_c_string(GRPC_MDKEY(md)); - char *v = NULL; + char* k = grpc_slice_to_c_string(GRPC_MDKEY(md)); + char* v = NULL; if (grpc_is_binary_header(GRPC_MDKEY(md))) { v = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX); } else { @@ -671,7 +671,7 @@ static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, if (add_to_table) { GPR_ASSERT(GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_INTERNED || GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC); - grpc_error *err = grpc_chttp2_hptbl_add(exec_ctx, &p->table, md); + grpc_error* err = grpc_chttp2_hptbl_add(exec_ctx, &p->table, md); if (err != GRPC_ERROR_NONE) return err; } if (p->on_header == NULL) { @@ -682,9 +682,9 @@ static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, return GRPC_ERROR_NONE; } -static grpc_slice take_string(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - grpc_chttp2_hpack_parser_string *str, +static grpc_slice take_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + grpc_chttp2_hpack_parser_string* str, bool intern) { grpc_slice s; if (!str->copied) { @@ -708,18 +708,18 @@ static grpc_slice take_string(grpc_exec_ctx *exec_ctx, } /* jump to the next state */ -static grpc_error *parse_next(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_next(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { p->state = *p->next_state++; return p->state(exec_ctx, p, cur, end); } /* begin parsing a header: all functionality is encoded into lookup tables above */ -static grpc_error *parse_begin(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_begin(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { if (cur == end) { p->state = parse_begin; return GRPC_ERROR_NONE; @@ -729,9 +729,9 @@ static grpc_error *parse_begin(grpc_exec_ctx *exec_ctx, } /* stream dependency and prioritization data: we just skip it */ -static grpc_error *parse_stream_weight(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_stream_weight(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_weight; return GRPC_ERROR_NONE; @@ -740,9 +740,9 @@ static grpc_error *parse_stream_weight(grpc_exec_ctx *exec_ctx, return p->after_prioritization(exec_ctx, p, cur + 1, end); } -static grpc_error *parse_stream_dep3(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_stream_dep3(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep3; return GRPC_ERROR_NONE; @@ -751,9 +751,9 @@ static grpc_error *parse_stream_dep3(grpc_exec_ctx *exec_ctx, return parse_stream_weight(exec_ctx, p, cur + 1, end); } -static grpc_error *parse_stream_dep2(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_stream_dep2(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep2; return GRPC_ERROR_NONE; @@ -762,9 +762,9 @@ static grpc_error *parse_stream_dep2(grpc_exec_ctx *exec_ctx, return parse_stream_dep3(exec_ctx, p, cur + 1, end); } -static grpc_error *parse_stream_dep1(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_stream_dep1(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep1; return GRPC_ERROR_NONE; @@ -773,9 +773,9 @@ static grpc_error *parse_stream_dep1(grpc_exec_ctx *exec_ctx, return parse_stream_dep2(exec_ctx, p, cur + 1, end); } -static grpc_error *parse_stream_dep0(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_stream_dep0(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_stream_dep0; return GRPC_ERROR_NONE; @@ -785,10 +785,10 @@ static grpc_error *parse_stream_dep0(grpc_exec_ctx *exec_ctx, } /* emit an indexed field; jumps to begin the next field on completion */ -static grpc_error *finish_indexed_field(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* finish_indexed_field(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); if (GRPC_MDISNULL(md)) { return grpc_error_set_int( @@ -799,25 +799,25 @@ static grpc_error *finish_indexed_field(grpc_exec_ctx *exec_ctx, } GRPC_MDELEM_REF(md); GRPC_STATS_INC_HPACK_RECV_INDEXED(exec_ctx); - grpc_error *err = on_hdr(exec_ctx, p, md, 0); + grpc_error* err = on_hdr(exec_ctx, p, md, 0); if (err != GRPC_ERROR_NONE) return err; return parse_begin(exec_ctx, p, cur, end); } /* parse an indexed field with index < 127 */ -static grpc_error *parse_indexed_field(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_indexed_field(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { p->dynamic_table_update_allowed = 0; p->index = (*cur) & 0x7f; return finish_indexed_field(exec_ctx, p, cur + 1, end); } /* parse an indexed field with index >= 127 */ -static grpc_error *parse_indexed_field_x(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_indexed_field_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { finish_indexed_field}; p->dynamic_table_update_allowed = 0; @@ -828,14 +828,14 @@ static grpc_error *parse_indexed_field_x(grpc_exec_ctx *exec_ctx, } /* finish a literal header with incremental indexing */ -static grpc_error *finish_lithdr_incidx(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* finish_lithdr_incidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX(exec_ctx); - grpc_error *err = on_hdr( + grpc_error* err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), take_string(exec_ctx, p, &p->value, true)), @@ -845,12 +845,12 @@ static grpc_error *finish_lithdr_incidx(grpc_exec_ctx *exec_ctx, } /* finish a literal header with incremental indexing with no index */ -static grpc_error *finish_lithdr_incidx_v(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* finish_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V(exec_ctx); - grpc_error *err = on_hdr( + grpc_error* err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), take_string(exec_ctx, p, &p->value, true)), @@ -860,9 +860,9 @@ static grpc_error *finish_lithdr_incidx_v(grpc_exec_ctx *exec_ctx, } /* parse a literal header with incremental indexing; index < 63 */ -static grpc_error *parse_lithdr_incidx(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_lithdr_incidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_value_string_with_indexed_key, finish_lithdr_incidx}; p->dynamic_table_update_allowed = 0; @@ -872,10 +872,10 @@ static grpc_error *parse_lithdr_incidx(grpc_exec_ctx *exec_ctx, } /* parse a literal header with incremental indexing; index >= 63 */ -static grpc_error *parse_lithdr_incidx_x(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_lithdr_incidx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_string_prefix, parse_value_string_with_indexed_key, finish_lithdr_incidx}; @@ -887,10 +887,10 @@ static grpc_error *parse_lithdr_incidx_x(grpc_exec_ctx *exec_ctx, } /* parse a literal header with incremental indexing; index = 0 */ -static grpc_error *parse_lithdr_incidx_v(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_lithdr_incidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_key_string, parse_string_prefix, parse_value_string_with_literal_key, finish_lithdr_incidx_v}; @@ -900,14 +900,14 @@ static grpc_error *parse_lithdr_incidx_v(grpc_exec_ctx *exec_ctx, } /* finish a literal header without incremental indexing */ -static grpc_error *finish_lithdr_notidx(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* finish_lithdr_notidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX(exec_ctx); - grpc_error *err = on_hdr( + grpc_error* err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), take_string(exec_ctx, p, &p->value, false)), @@ -917,12 +917,12 @@ static grpc_error *finish_lithdr_notidx(grpc_exec_ctx *exec_ctx, } /* finish a literal header without incremental indexing with index = 0 */ -static grpc_error *finish_lithdr_notidx_v(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* finish_lithdr_notidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V(exec_ctx); - grpc_error *err = on_hdr( + grpc_error* err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), take_string(exec_ctx, p, &p->value, false)), @@ -932,9 +932,9 @@ static grpc_error *finish_lithdr_notidx_v(grpc_exec_ctx *exec_ctx, } /* parse a literal header without incremental indexing; index < 15 */ -static grpc_error *parse_lithdr_notidx(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_lithdr_notidx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_value_string_with_indexed_key, finish_lithdr_notidx}; p->dynamic_table_update_allowed = 0; @@ -944,10 +944,10 @@ static grpc_error *parse_lithdr_notidx(grpc_exec_ctx *exec_ctx, } /* parse a literal header without incremental indexing; index >= 15 */ -static grpc_error *parse_lithdr_notidx_x(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_lithdr_notidx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_string_prefix, parse_value_string_with_indexed_key, finish_lithdr_notidx}; @@ -959,10 +959,10 @@ static grpc_error *parse_lithdr_notidx_x(grpc_exec_ctx *exec_ctx, } /* parse a literal header without incremental indexing; index == 0 */ -static grpc_error *parse_lithdr_notidx_v(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_lithdr_notidx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_key_string, parse_string_prefix, parse_value_string_with_literal_key, finish_lithdr_notidx_v}; @@ -972,14 +972,14 @@ static grpc_error *parse_lithdr_notidx_v(grpc_exec_ctx *exec_ctx, } /* finish a literal header that is never indexed */ -static grpc_error *finish_lithdr_nvridx(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* finish_lithdr_nvridx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX(exec_ctx); - grpc_error *err = on_hdr( + grpc_error* err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), take_string(exec_ctx, p, &p->value, false)), @@ -989,12 +989,12 @@ static grpc_error *finish_lithdr_nvridx(grpc_exec_ctx *exec_ctx, } /* finish a literal header that is never indexed with an extra value */ -static grpc_error *finish_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* finish_lithdr_nvridx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V(exec_ctx); - grpc_error *err = on_hdr( + grpc_error* err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), take_string(exec_ctx, p, &p->value, false)), @@ -1004,9 +1004,9 @@ static grpc_error *finish_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx, } /* parse a literal header that is never indexed; index < 15 */ -static grpc_error *parse_lithdr_nvridx(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_lithdr_nvridx(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_value_string_with_indexed_key, finish_lithdr_nvridx}; p->dynamic_table_update_allowed = 0; @@ -1016,10 +1016,10 @@ static grpc_error *parse_lithdr_nvridx(grpc_exec_ctx *exec_ctx, } /* parse a literal header that is never indexed; index >= 15 */ -static grpc_error *parse_lithdr_nvridx_x(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_lithdr_nvridx_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_string_prefix, parse_value_string_with_indexed_key, finish_lithdr_nvridx}; @@ -1031,10 +1031,10 @@ static grpc_error *parse_lithdr_nvridx_x(grpc_exec_ctx *exec_ctx, } /* parse a literal header that is never indexed; index == 0 */ -static grpc_error *parse_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_lithdr_nvridx_v(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { parse_key_string, parse_string_prefix, parse_value_string_with_literal_key, finish_lithdr_nvridx_v}; @@ -1044,22 +1044,22 @@ static grpc_error *parse_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx, } /* finish parsing a max table size change */ -static grpc_error *finish_max_tbl_size(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* finish_max_tbl_size(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { if (GRPC_TRACER_ON(grpc_http_trace)) { gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index); } - grpc_error *err = + grpc_error* err = grpc_chttp2_hptbl_set_current_table_size(exec_ctx, &p->table, p->index); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } /* parse a max table size change, max size < 15 */ -static grpc_error *parse_max_tbl_size(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_max_tbl_size(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { if (p->dynamic_table_update_allowed == 0) { return parse_error( exec_ctx, p, cur, end, @@ -1072,10 +1072,10 @@ static grpc_error *parse_max_tbl_size(grpc_exec_ctx *exec_ctx, } /* parse a max table size change, max size >= 15 */ -static grpc_error *parse_max_tbl_size_x(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_max_tbl_size_x(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, + const uint8_t* end) { static const grpc_chttp2_hpack_parser_state and_then[] = { finish_max_tbl_size}; if (p->dynamic_table_update_allowed == 0) { @@ -1092,9 +1092,9 @@ static grpc_error *parse_max_tbl_size_x(grpc_exec_ctx *exec_ctx, } /* a parse error: jam the parse state into parse_error, and return error */ -static grpc_error *parse_error(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end, grpc_error *err) { +static grpc_error* parse_error(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end, grpc_error* err) { GPR_ASSERT(err != GRPC_ERROR_NONE); if (p->last_error == GRPC_ERROR_NONE) { p->last_error = GRPC_ERROR_REF(err); @@ -1103,28 +1103,28 @@ static grpc_error *parse_error(grpc_exec_ctx *exec_ctx, return err; } -static grpc_error *still_parse_error(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* still_parse_error(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { return GRPC_ERROR_REF(p->last_error); } -static grpc_error *parse_illegal_op(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_illegal_op(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { GPR_ASSERT(cur != end); - char *msg; + char* msg; gpr_asprintf(&msg, "Illegal hpack op code %d", *cur); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return parse_error(exec_ctx, p, cur, end, err); } /* parse the 1st byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error *parse_value0(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_value0(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { if (cur == end) { p->state = parse_value0; return GRPC_ERROR_NONE; @@ -1141,9 +1141,9 @@ static grpc_error *parse_value0(grpc_exec_ctx *exec_ctx, /* parse the 2nd byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error *parse_value1(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_value1(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { if (cur == end) { p->state = parse_value1; return GRPC_ERROR_NONE; @@ -1160,9 +1160,9 @@ static grpc_error *parse_value1(grpc_exec_ctx *exec_ctx, /* parse the 3rd byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error *parse_value2(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_value2(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { if (cur == end) { p->state = parse_value2; return GRPC_ERROR_NONE; @@ -1179,9 +1179,9 @@ static grpc_error *parse_value2(grpc_exec_ctx *exec_ctx, /* parse the 4th byte of a varint into p->parsing.value no overflow is possible */ -static grpc_error *parse_value3(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_value3(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { if (cur == end) { p->state = parse_value3; return GRPC_ERROR_NONE; @@ -1198,13 +1198,13 @@ static grpc_error *parse_value3(grpc_exec_ctx *exec_ctx, /* parse the 5th byte of a varint into p->parsing.value depending on the byte, we may overflow, and care must be taken */ -static grpc_error *parse_value4(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_value4(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { uint8_t c; uint32_t cur_value; uint32_t add_value; - char *msg; + char* msg; if (cur == end) { p->state = parse_value4; @@ -1235,7 +1235,7 @@ error: "integer overflow in hpack integer decoding: have 0x%08x, " "got byte 0x%02x on byte 5", *p->parsing.value, *cur); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return parse_error(exec_ctx, p, cur, end, err); } @@ -1243,9 +1243,9 @@ error: /* parse any trailing bytes in a varint: it's possible to append an arbitrary number of 0x80's and not affect the value - a zero will terminate - and anything else will overflow */ -static grpc_error *parse_value5up(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_value5up(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { while (cur != end && *cur == 0x80) { ++cur; } @@ -1259,20 +1259,20 @@ static grpc_error *parse_value5up(grpc_exec_ctx *exec_ctx, return parse_next(exec_ctx, p, cur + 1, end); } - char *msg; + char* msg; gpr_asprintf(&msg, "integer overflow in hpack integer decoding: have 0x%08x, " "got byte 0x%02x sometime after byte 5", *p->parsing.value, *cur); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return parse_error(exec_ctx, p, cur, end, err); } /* parse a string prefix */ -static grpc_error *parse_string_prefix(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_string_prefix(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { if (cur == end) { p->state = parse_string_prefix; return GRPC_ERROR_NONE; @@ -1289,24 +1289,24 @@ static grpc_error *parse_string_prefix(grpc_exec_ctx *exec_ctx, } /* append some bytes to a string */ -static void append_bytes(grpc_chttp2_hpack_parser_string *str, - const uint8_t *data, size_t length) { +static void append_bytes(grpc_chttp2_hpack_parser_string* str, + const uint8_t* data, size_t length) { 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); + (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; } -static grpc_error *append_string(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { - grpc_chttp2_hpack_parser_string *str = p->parsing.str; +static grpc_error* append_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { + grpc_chttp2_hpack_parser_string* str = p->parsing.str; uint32_t bits; uint8_t decoded[3]; switch ((binary_state)p->binary) { @@ -1403,12 +1403,12 @@ static grpc_error *append_string(grpc_exec_ctx *exec_ctx, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Should never reach here"))); } -static grpc_error *finish_str(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end) { +static grpc_error* finish_str(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { uint8_t decoded[2]; uint32_t bits; - grpc_chttp2_hpack_parser_string *str = p->parsing.str; + grpc_chttp2_hpack_parser_string* str = p->parsing.str; switch ((binary_state)p->binary) { case NOT_BINARY: break; @@ -1423,10 +1423,10 @@ static grpc_error *finish_str(grpc_exec_ctx *exec_ctx, case B64_BYTE2: bits = p->base64_buffer; if (bits & 0xffff) { - char *msg; + char* msg; gpr_asprintf(&msg, "trailing bits in base64 encoding: 0x%04x", bits & 0xffff); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return parse_error(exec_ctx, p, cur, end, err); } @@ -1436,10 +1436,10 @@ static grpc_error *finish_str(grpc_exec_ctx *exec_ctx, case B64_BYTE3: bits = p->base64_buffer; if (bits & 0xff) { - char *msg; + char* msg; gpr_asprintf(&msg, "trailing bits in base64 encoding: 0x%02x", bits & 0xff); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return parse_error(exec_ctx, p, cur, end, err); } @@ -1452,14 +1452,14 @@ static grpc_error *finish_str(grpc_exec_ctx *exec_ctx, } /* decode a nibble from a huffman encoded stream */ -static grpc_error *huff_nibble(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, uint8_t nibble) { +static grpc_error* huff_nibble(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, uint8_t nibble) { int16_t emit = emit_sub_tbl[16 * emit_tbl[p->huff_state] + 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; - grpc_error *err = append_string(exec_ctx, p, &c, (&c) + 1); + grpc_error* err = append_string(exec_ctx, p, &c, (&c) + 1); if (err != GRPC_ERROR_NONE) return err; } else { assert(emit == 256); @@ -1470,11 +1470,11 @@ static grpc_error *huff_nibble(grpc_exec_ctx *exec_ctx, } /* decode full bytes from a huffman encoded stream */ -static grpc_error *add_huff_bytes(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* add_huff_bytes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { for (; cur != end; ++cur) { - grpc_error *err = huff_nibble(exec_ctx, p, *cur >> 4); + grpc_error* err = huff_nibble(exec_ctx, p, *cur >> 4); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); err = huff_nibble(exec_ctx, p, *cur & 0xf); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); @@ -1484,9 +1484,9 @@ static grpc_error *add_huff_bytes(grpc_exec_ctx *exec_ctx, /* decode some string bytes based on the current decoding mode (huffman or not) */ -static grpc_error *add_str_bytes(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* add_str_bytes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { if (p->huff) { return add_huff_bytes(exec_ctx, p, cur, end); } else { @@ -1495,19 +1495,19 @@ static grpc_error *add_str_bytes(grpc_exec_ctx *exec_ctx, } /* parse a string - tries to do large chunks at a time */ -static grpc_error *parse_string(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_string(grpc_exec_ctx* exec_ctx, + 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); if (remaining <= given) { - grpc_error *err = add_str_bytes(exec_ctx, p, cur, cur + remaining); + grpc_error* err = add_str_bytes(exec_ctx, p, cur, cur + remaining); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); err = finish_str(exec_ctx, p, cur + remaining, end); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_next(exec_ctx, p, cur + remaining, end); } else { - grpc_error *err = add_str_bytes(exec_ctx, p, cur, cur + given); + grpc_error* err = add_str_bytes(exec_ctx, p, cur, cur + given); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); GPR_ASSERT(given <= UINT32_MAX - p->strgot); p->strgot += (uint32_t)given; @@ -1517,17 +1517,17 @@ static grpc_error *parse_string(grpc_exec_ctx *exec_ctx, } /* begin parsing a string - performs setup, calls parse_string */ -static grpc_error *begin_parse_string(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end, +static grpc_error* begin_parse_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end, uint8_t binary, - grpc_chttp2_hpack_parser_string *str) { + grpc_chttp2_hpack_parser_string* str) { if (!p->huff && binary == NOT_BINARY && (end - cur) >= (intptr_t)p->strlen && p->current_slice_refcount != NULL) { GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(exec_ctx); 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 = (uint8_t*)cur; str->data.referenced.data.refcounted.length = p->strlen; grpc_slice_ref_internal(str->data.referenced); return parse_next(exec_ctx, p, cur + p->strlen, end); @@ -1556,23 +1556,23 @@ static grpc_error *begin_parse_string(grpc_exec_ctx *exec_ctx, } /* parse the key string */ -static grpc_error *parse_key_string(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end) { +static grpc_error* parse_key_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end) { return begin_parse_string(exec_ctx, p, cur, end, NOT_BINARY, &p->key); } /* check if a key represents a binary header or not */ -static bool is_binary_literal_header(grpc_chttp2_hpack_parser *p) { +static bool is_binary_literal_header(grpc_chttp2_hpack_parser* p) { return grpc_is_binary_header( p->key.copied ? grpc_slice_from_static_buffer(p->key.data.copied.str, p->key.data.copied.length) : p->key.data.referenced); } -static grpc_error *is_binary_indexed_header(grpc_chttp2_hpack_parser *p, - bool *is) { +static grpc_error* is_binary_indexed_header(grpc_chttp2_hpack_parser* p, + bool* is) { grpc_mdelem elem = grpc_chttp2_hptbl_lookup(&p->table, p->index); if (GRPC_MDISNULL(elem)) { return grpc_error_set_int( @@ -1586,33 +1586,33 @@ static grpc_error *is_binary_indexed_header(grpc_chttp2_hpack_parser *p, } /* parse the value string */ -static grpc_error *parse_value_string(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - const uint8_t *cur, const uint8_t *end, +static grpc_error* parse_value_string(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, + const uint8_t* cur, const uint8_t* end, bool is_binary) { return begin_parse_string(exec_ctx, p, cur, end, is_binary ? BINARY_BEGIN : NOT_BINARY, &p->value); } -static grpc_error *parse_value_string_with_indexed_key( - grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_value_string_with_indexed_key( + grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { bool is_binary = false; - grpc_error *err = is_binary_indexed_header(p, &is_binary); + grpc_error* err = is_binary_indexed_header(p, &is_binary); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_value_string(exec_ctx, p, cur, end, is_binary); } -static grpc_error *parse_value_string_with_literal_key( - grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, - const uint8_t *end) { +static grpc_error* parse_value_string_with_literal_key( + grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* cur, + const uint8_t* end) { return parse_value_string(exec_ctx, p, cur, end, is_binary_literal_header(p)); } /* PUBLIC INTERFACE */ -void grpc_chttp2_hpack_parser_init(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p) { +void grpc_chttp2_hpack_parser_init(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p) { p->on_header = NULL; p->on_header_user_data = NULL; p->state = parse_begin; @@ -1629,13 +1629,13 @@ void grpc_chttp2_hpack_parser_init(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl_init(exec_ctx, &p->table); } -void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p) { +void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser* p) { p->after_prioritization = p->state; p->state = parse_stream_dep0; } -void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p) { +void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p) { grpc_chttp2_hptbl_destroy(exec_ctx, &p->table); GRPC_ERROR_UNREF(p->last_error); grpc_slice_unref_internal(exec_ctx, p->key.data.referenced); @@ -1644,18 +1644,18 @@ void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx *exec_ctx, gpr_free(p->value.data.copied.str); } -grpc_error *grpc_chttp2_hpack_parser_parse(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, +grpc_error* grpc_chttp2_hpack_parser_parse(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, grpc_slice slice) { /* max number of bytes to parse at a time... limits call stack depth on * compilers without TCO */ #define MAX_PARSE_LENGTH 1024 p->current_slice_refcount = slice.refcount; - uint8_t *start = GRPC_SLICE_START_PTR(slice); - uint8_t *end = GRPC_SLICE_END_PTR(slice); - grpc_error *error = GRPC_ERROR_NONE; + uint8_t* start = GRPC_SLICE_START_PTR(slice); + uint8_t* end = GRPC_SLICE_END_PTR(slice); + grpc_error* error = GRPC_ERROR_NONE; while (start != end && error == GRPC_ERROR_NONE) { - uint8_t *target = start + GPR_MIN(MAX_PARSE_LENGTH, end - start); + uint8_t* target = start + GPR_MIN(MAX_PARSE_LENGTH, end - start); error = p->state(exec_ctx, p, start, target); start = target; } @@ -1663,17 +1663,17 @@ grpc_error *grpc_chttp2_hpack_parser_parse(grpc_exec_ctx *exec_ctx, return error; } -typedef void (*maybe_complete_func_type)(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s); +typedef void (*maybe_complete_func_type)(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s); static const maybe_complete_func_type maybe_complete_funcs[] = { grpc_chttp2_maybe_complete_recv_initial_metadata, grpc_chttp2_maybe_complete_recv_trailing_metadata}; -static void force_client_rst_stream(grpc_exec_ctx *exec_ctx, void *sp, - grpc_error *error) { - grpc_chttp2_stream *s = (grpc_chttp2_stream *)sp; - grpc_chttp2_transport *t = s->t; +static void force_client_rst_stream(grpc_exec_ctx* exec_ctx, void* sp, + grpc_error* error) { + grpc_chttp2_stream* s = (grpc_chttp2_stream*)sp; + grpc_chttp2_transport* t = s->t; if (!s->write_closed) { grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_HTTP2_NO_ERROR, @@ -1685,10 +1685,10 @@ static void force_client_rst_stream(grpc_exec_ctx *exec_ctx, void *sp, GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "final_rst"); } -static void parse_stream_compression_md(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, - grpc_metadata_batch *initial_metadata) { +static void parse_stream_compression_md(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, + grpc_metadata_batch* initial_metadata) { if (initial_metadata->idx.named.content_encoding == NULL || grpc_stream_compression_method_parse( GRPC_MDVALUE(initial_metadata->idx.named.content_encoding->md), false, @@ -1698,17 +1698,17 @@ static void parse_stream_compression_md(grpc_exec_ctx *exec_ctx, } } -grpc_error *grpc_chttp2_header_parser_parse(grpc_exec_ctx *exec_ctx, - void *hpack_parser, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, + 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; + grpc_chttp2_hpack_parser* parser = (grpc_chttp2_hpack_parser*)hpack_parser; GPR_TIMER_BEGIN("grpc_chttp2_hpack_parser_parse", 0); if (s != NULL) { s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice); } - grpc_error *error = grpc_chttp2_hpack_parser_parse(exec_ctx, parser, slice); + grpc_error* error = grpc_chttp2_hpack_parser_parse(exec_ctx, parser, slice); if (error != GRPC_ERROR_NONE) { GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); return error; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.h b/src/core/ext/transport/chttp2/transport/hpack_parser.h index 52014175a0..838c482e4a 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.h @@ -33,16 +33,16 @@ extern "C" { typedef struct grpc_chttp2_hpack_parser grpc_chttp2_hpack_parser; -typedef grpc_error *(*grpc_chttp2_hpack_parser_state)( - grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *beg, - const uint8_t *end); +typedef grpc_error* (*grpc_chttp2_hpack_parser_state)( + grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, const uint8_t* beg, + const uint8_t* end); typedef struct { bool copied; struct { grpc_slice referenced; struct { - char *str; + char* str; uint32_t length; uint32_t capacity; } copied; @@ -51,23 +51,23 @@ typedef struct { struct grpc_chttp2_hpack_parser { /* user specified callback for each header output */ - void (*on_header)(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem md); - void *on_header_user_data; + void (*on_header)(grpc_exec_ctx* exec_ctx, void* user_data, grpc_mdelem md); + void* on_header_user_data; - grpc_error *last_error; + grpc_error* last_error; /* current parse state - or a function that implements it */ grpc_chttp2_hpack_parser_state state; /* future states dependent on the opening op code */ - const grpc_chttp2_hpack_parser_state *next_state; + const grpc_chttp2_hpack_parser_state* next_state; /* what to do after skipping prioritization data */ grpc_chttp2_hpack_parser_state after_prioritization; /* the refcount of the slice that we're currently parsing */ - grpc_slice_refcount *current_slice_refcount; + grpc_slice_refcount* current_slice_refcount; /* the value we're currently parsing */ union { - uint32_t *value; - grpc_chttp2_hpack_parser_string *str; + uint32_t* value; + grpc_chttp2_hpack_parser_string* str; } parsing; /* string parameters for each chunk */ grpc_chttp2_hpack_parser_string key; @@ -96,23 +96,23 @@ struct grpc_chttp2_hpack_parser { grpc_chttp2_hptbl table; }; -void grpc_chttp2_hpack_parser_init(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p); -void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p); +void grpc_chttp2_hpack_parser_init(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p); +void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p); -void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p); +void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser* p); -grpc_error *grpc_chttp2_hpack_parser_parse(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, +grpc_error* grpc_chttp2_hpack_parser_parse(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hpack_parser* p, grpc_slice slice); /* wraps grpc_chttp2_hpack_parser_parse to provide a frame level parser for the transport */ -grpc_error *grpc_chttp2_header_parser_parse(grpc_exec_ctx *exec_ctx, - void *hpack_parser, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, + void* hpack_parser, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_slice slice, int is_last); #ifdef __cplusplus diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.cc b/src/core/ext/transport/chttp2/transport/hpack_table.cc index 82c284b36e..1a2bc9224e 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_table.cc @@ -31,8 +31,8 @@ extern "C" grpc_tracer_flag grpc_http_trace; static struct { - const char *key; - const char *value; + const char* key; + const char* value; } static_table[] = { /* 0: */ {NULL, NULL}, @@ -165,7 +165,7 @@ static uint32_t entries_for_bytes(uint32_t bytes) { GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; } -void grpc_chttp2_hptbl_init(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) { +void grpc_chttp2_hptbl_init(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl) { size_t i; memset(tbl, 0, sizeof(*tbl)); @@ -173,7 +173,7 @@ void grpc_chttp2_hptbl_init(grpc_exec_ctx *exec_ctx, 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 = (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( @@ -184,8 +184,8 @@ void grpc_chttp2_hptbl_init(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) { } } -void grpc_chttp2_hptbl_destroy(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hptbl *tbl) { +void grpc_chttp2_hptbl_destroy(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl) { size_t i; for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { GRPC_MDELEM_UNREF(exec_ctx, tbl->static_ents[i]); @@ -197,7 +197,7 @@ void grpc_chttp2_hptbl_destroy(grpc_exec_ctx *exec_ctx, gpr_free(tbl->ents); } -grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, +grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl* tbl, uint32_t tbl_index) { /* Static table comes first, just return an entry from it */ if (tbl_index <= GRPC_CHTTP2_LAST_STATIC_ENTRY) { @@ -215,7 +215,7 @@ grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, } /* Evict one element from the table */ -static void evict1(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) { +static void evict1(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl) { grpc_mdelem first_ent = tbl->ents[tbl->first_ent]; size_t elem_bytes = GRPC_SLICE_LENGTH(GRPC_MDKEY(first_ent)) + GRPC_SLICE_LENGTH(GRPC_MDVALUE(first_ent)) + @@ -227,8 +227,8 @@ static void evict1(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) { GRPC_MDELEM_UNREF(exec_ctx, 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); +static void rebuild_ents(grpc_chttp2_hptbl* tbl, uint32_t new_cap) { + grpc_mdelem* ents = (grpc_mdelem*)gpr_malloc(sizeof(*ents) * new_cap); uint32_t i; for (i = 0; i < tbl->num_ents; i++) { @@ -240,8 +240,8 @@ static void rebuild_ents(grpc_chttp2_hptbl *tbl, uint32_t new_cap) { tbl->first_ent = 0; } -void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hptbl *tbl, +void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, uint32_t max_bytes) { if (tbl->max_bytes == max_bytes) { return; @@ -255,18 +255,18 @@ void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx *exec_ctx, tbl->max_bytes = max_bytes; } -grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hptbl *tbl, +grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, uint32_t bytes) { if (tbl->current_table_bytes == bytes) { return GRPC_ERROR_NONE; } if (bytes > tbl->max_bytes) { - char *msg; + char* msg; gpr_asprintf(&msg, "Attempt to make hpack table %d bytes when max is %d bytes", bytes, tbl->max_bytes); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } @@ -289,21 +289,21 @@ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hptbl *tbl, grpc_mdelem md) { +grpc_error* grpc_chttp2_hptbl_add(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, grpc_mdelem md) { /* determine how many bytes of buffer this entry represents */ size_t elem_bytes = GRPC_SLICE_LENGTH(GRPC_MDKEY(md)) + GRPC_SLICE_LENGTH(GRPC_MDVALUE(md)) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; if (tbl->current_table_bytes > tbl->max_bytes) { - char *msg; + char* msg; gpr_asprintf( &msg, "HPACK max table size reduced to %d but not reflected by hpack " "stream (still at %d)", tbl->max_bytes, tbl->current_table_bytes); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } @@ -341,7 +341,7 @@ grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx, } grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( - const grpc_chttp2_hptbl *tbl, grpc_mdelem md) { + const grpc_chttp2_hptbl* tbl, grpc_mdelem md) { grpc_chttp2_hptbl_find_result r = {0, 0}; uint32_t i; diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.h b/src/core/ext/transport/chttp2/transport/hpack_table.h index a3ce2730a8..ddc8888f86 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.h +++ b/src/core/ext/transport/chttp2/transport/hpack_table.h @@ -68,26 +68,26 @@ typedef struct { /* a circular buffer of headers - this is stored in the opposite order to what hpack specifies, in order to simplify table management a little... meaning lookups need to SUBTRACT from the end position */ - grpc_mdelem *ents; + grpc_mdelem* ents; grpc_mdelem static_ents[GRPC_CHTTP2_LAST_STATIC_ENTRY]; } grpc_chttp2_hptbl; /* initialize a hpack table */ -void grpc_chttp2_hptbl_init(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl); -void grpc_chttp2_hptbl_destroy(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl); -void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hptbl *tbl, +void grpc_chttp2_hptbl_init(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl); +void grpc_chttp2_hptbl_destroy(grpc_exec_ctx* exec_ctx, grpc_chttp2_hptbl* tbl); +void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, uint32_t max_bytes); -grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hptbl *tbl, +grpc_error* grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, uint32_t bytes); /* lookup a table entry based on its hpack index */ -grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, +grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl* tbl, uint32_t index); /* add a table entry to the index */ -grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hptbl *tbl, +grpc_error* grpc_chttp2_hptbl_add(grpc_exec_ctx* exec_ctx, + grpc_chttp2_hptbl* tbl, grpc_mdelem md) GRPC_MUST_USE_RESULT; /* Find a key/value pair in the table... returns the index in the table of the most similar entry, or 0 if the value was not found */ @@ -96,7 +96,7 @@ typedef struct { int has_value; } grpc_chttp2_hptbl_find_result; grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( - const grpc_chttp2_hptbl *tbl, grpc_mdelem md); + const grpc_chttp2_hptbl* tbl, grpc_mdelem md); #ifdef __cplusplus } diff --git a/src/core/ext/transport/chttp2/transport/http2_settings.cc b/src/core/ext/transport/chttp2/transport/http2_settings.cc index 46b7c0c49c..0aab864400 100644 --- a/src/core/ext/transport/chttp2/transport/http2_settings.cc +++ b/src/core/ext/transport/chttp2/transport/http2_settings.cc @@ -25,7 +25,7 @@ const uint16_t grpc_setting_id_to_wire_id[] = {1, 2, 3, 4, 5, 6, 65027}; -bool grpc_wire_id_to_setting_id(uint32_t wire_id, grpc_chttp2_setting_id *out) { +bool grpc_wire_id_to_setting_id(uint32_t wire_id, grpc_chttp2_setting_id* out) { uint32_t i = wire_id - 1; uint32_t x = i % 256; uint32_t y = i / 256; diff --git a/src/core/ext/transport/chttp2/transport/http2_settings.h b/src/core/ext/transport/chttp2/transport/http2_settings.h index 0f76106dce..86069b498b 100644 --- a/src/core/ext/transport/chttp2/transport/http2_settings.h +++ b/src/core/ext/transport/chttp2/transport/http2_settings.h @@ -41,7 +41,7 @@ extern "C" { #endif extern const uint16_t grpc_setting_id_to_wire_id[]; -bool grpc_wire_id_to_setting_id(uint32_t wire_id, grpc_chttp2_setting_id *out); +bool grpc_wire_id_to_setting_id(uint32_t wire_id, grpc_chttp2_setting_id* out); typedef enum { GRPC_CHTTP2_CLAMP_INVALID_VALUE, @@ -49,7 +49,7 @@ typedef enum { } grpc_chttp2_invalid_value_behavior; typedef struct { - const char *name; + const char* name; uint32_t default_value; uint32_t min_value; uint32_t max_value; diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc index 187ce0ea87..15f80fb8a1 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc @@ -26,31 +26,32 @@ #include <grpc/support/log.h> void grpc_chttp2_incoming_metadata_buffer_init( - grpc_chttp2_incoming_metadata_buffer *buffer, gpr_arena *arena) { + grpc_chttp2_incoming_metadata_buffer* buffer, gpr_arena* arena) { buffer->arena = arena; grpc_metadata_batch_init(&buffer->batch); buffer->batch.deadline = GRPC_MILLIS_INF_FUTURE; } void grpc_chttp2_incoming_metadata_buffer_destroy( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer) { grpc_metadata_batch_destroy(exec_ctx, &buffer->batch); } -grpc_error *grpc_chttp2_incoming_metadata_buffer_add( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, +grpc_error* grpc_chttp2_incoming_metadata_buffer_add( + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) { buffer->size += GRPC_MDELEM_LENGTH(elem); return grpc_metadata_batch_add_tail( - exec_ctx, &buffer->batch, (grpc_linked_mdelem *)gpr_arena_alloc( - buffer->arena, sizeof(grpc_linked_mdelem)), + exec_ctx, &buffer->batch, + (grpc_linked_mdelem*)gpr_arena_alloc(buffer->arena, + sizeof(grpc_linked_mdelem)), elem); } -grpc_error *grpc_chttp2_incoming_metadata_buffer_replace_or_add( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, +grpc_error* grpc_chttp2_incoming_metadata_buffer_replace_or_add( + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) { - for (grpc_linked_mdelem *l = buffer->batch.list.head; l != NULL; + for (grpc_linked_mdelem* l = buffer->batch.list.head; l != NULL; l = l->next) { if (grpc_slice_eq(GRPC_MDKEY(l->md), GRPC_MDKEY(elem))) { GRPC_MDELEM_UNREF(exec_ctx, l->md); @@ -62,13 +63,13 @@ grpc_error *grpc_chttp2_incoming_metadata_buffer_replace_or_add( } void grpc_chttp2_incoming_metadata_buffer_set_deadline( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_millis deadline) { + grpc_chttp2_incoming_metadata_buffer* buffer, grpc_millis deadline) { buffer->batch.deadline = deadline; } void grpc_chttp2_incoming_metadata_buffer_publish( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, - grpc_metadata_batch *batch) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, + grpc_metadata_batch* batch) { *batch = buffer->batch; grpc_metadata_batch_init(&buffer->batch); } diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.h b/src/core/ext/transport/chttp2/transport/incoming_metadata.h index a0e01f2c4d..7ccb4a0126 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.h +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.h @@ -26,28 +26,28 @@ extern "C" { #endif typedef struct { - gpr_arena *arena; + gpr_arena* arena; grpc_metadata_batch batch; size_t size; // total size of metadata } grpc_chttp2_incoming_metadata_buffer; /** assumes everything initially zeroed */ void grpc_chttp2_incoming_metadata_buffer_init( - grpc_chttp2_incoming_metadata_buffer *buffer, gpr_arena *arena); + grpc_chttp2_incoming_metadata_buffer* buffer, gpr_arena* arena); void grpc_chttp2_incoming_metadata_buffer_destroy( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer); + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer); void grpc_chttp2_incoming_metadata_buffer_publish( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, - grpc_metadata_batch *batch); + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, + grpc_metadata_batch* batch); -grpc_error *grpc_chttp2_incoming_metadata_buffer_add( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, +grpc_error* grpc_chttp2_incoming_metadata_buffer_add( + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) GRPC_MUST_USE_RESULT; -grpc_error *grpc_chttp2_incoming_metadata_buffer_replace_or_add( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, +grpc_error* grpc_chttp2_incoming_metadata_buffer_replace_or_add( + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) GRPC_MUST_USE_RESULT; void grpc_chttp2_incoming_metadata_buffer_set_deadline( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_millis deadline); + grpc_chttp2_incoming_metadata_buffer* buffer, grpc_millis deadline); #ifdef __cplusplus } diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 9e0796e820..a5a0a804a2 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -100,7 +100,7 @@ typedef enum { GRPC_CHTTP2_INITIATE_WRITE_FORCE_RST_STREAM, } grpc_chttp2_initiate_write_reason; -const char *grpc_chttp2_initiate_write_reason_string( +const char* grpc_chttp2_initiate_write_reason_string( grpc_chttp2_initiate_write_reason reason); typedef struct { @@ -171,13 +171,13 @@ typedef enum { } grpc_chttp2_deframe_transport_state; typedef struct { - grpc_chttp2_stream *head; - grpc_chttp2_stream *tail; + grpc_chttp2_stream* head; + grpc_chttp2_stream* tail; } grpc_chttp2_stream_list; typedef struct { - grpc_chttp2_stream *next; - grpc_chttp2_stream *prev; + grpc_chttp2_stream* next; + grpc_chttp2_stream* prev; } grpc_chttp2_stream_link; /* We keep several sets of connection wide parameters */ @@ -201,8 +201,8 @@ typedef enum { typedef struct grpc_chttp2_write_cb { int64_t call_at_byte; - grpc_closure *closure; - struct grpc_chttp2_write_cb *next; + grpc_closure* closure; + struct grpc_chttp2_write_cb* next; } grpc_chttp2_write_cb; /* forward declared in frame_data.h */ @@ -210,8 +210,8 @@ struct grpc_chttp2_incoming_byte_stream { grpc_byte_stream base; gpr_refcount refs; - grpc_chttp2_transport *transport; /* immutable */ - grpc_chttp2_stream *stream; /* immutable */ + grpc_chttp2_transport* transport; /* immutable */ + grpc_chttp2_stream* stream; /* immutable */ /* Accessed only by transport thread when stream->pending_byte_stream == false * Accessed only by application thread when stream->pending_byte_stream == @@ -224,7 +224,7 @@ struct grpc_chttp2_incoming_byte_stream { struct { grpc_closure closure; size_t max_size_hint; - grpc_closure *on_complete; + grpc_closure* on_complete; } next_action; grpc_closure destroy_action; grpc_closure finished_action; @@ -240,10 +240,10 @@ typedef enum { struct grpc_chttp2_transport { grpc_transport base; /* must be first */ gpr_refcount refs; - grpc_endpoint *ep; - char *peer_string; + grpc_endpoint* ep; + char* peer_string; - grpc_combiner *combiner; + grpc_combiner* combiner; /** write execution state of the transport */ grpc_chttp2_write_state write_state; @@ -255,7 +255,7 @@ struct grpc_chttp2_transport { /** is the transport destroying itself? */ uint8_t destroying; /** has the upper layer closed the transport? */ - grpc_error *closed_with_error; + grpc_error* closed_with_error; /** is there a read request to the endpoint outstanding? */ uint8_t endpoint_reading; @@ -280,13 +280,13 @@ struct grpc_chttp2_transport { /** address to place a newly accepted stream - set and unset by grpc_chttp2_parsing_accept_stream; used by init_stream to publish the accepted server stream */ - grpc_chttp2_stream **accepting_stream; + grpc_chttp2_stream** accepting_stream; struct { /* accept stream callback */ - void (*accept_stream)(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_transport *transport, const void *server_data); - void *accept_stream_user_data; + void (*accept_stream)(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_transport* transport, const void* server_data); + void* accept_stream_user_data; /** connectivity tracking */ grpc_connectivity_state_tracker state_tracker; @@ -337,7 +337,7 @@ struct grpc_chttp2_transport { /** ping acks */ size_t ping_ack_count; size_t ping_ack_capacity; - uint64_t *ping_acks; + uint64_t* ping_acks; grpc_chttp2_server_ping_recv_state ping_recv_state; /** parser for headers */ @@ -370,10 +370,10 @@ struct grpc_chttp2_transport { uint32_t incoming_stream_id; /* active parser */ - void *parser_data; - grpc_chttp2_stream *incoming_stream; - grpc_error *(*parser)(grpc_exec_ctx *exec_ctx, void *parser_user_data, - grpc_chttp2_transport *t, grpc_chttp2_stream *s, + void* parser_data; + grpc_chttp2_stream* incoming_stream; + grpc_error* (*parser)(grpc_exec_ctx* exec_ctx, void* parser_user_data, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last); /* goaway data */ @@ -381,7 +381,7 @@ struct grpc_chttp2_transport { uint32_t goaway_last_stream_index; grpc_slice goaway_text; - grpc_chttp2_write_cb *write_cb_pool; + grpc_chttp2_write_cb* write_cb_pool; /* bdp estimator */ grpc_closure next_bdp_ping_timer_expired_locked; @@ -390,7 +390,7 @@ struct grpc_chttp2_transport { /* if non-NULL, close the transport with this error when writes are finished */ - grpc_error *close_transport_on_writes_finished; + grpc_error* close_transport_on_writes_finished; /* a list of closures to run after writes are finished */ grpc_closure_list run_after_write; @@ -440,11 +440,11 @@ typedef enum { } grpc_published_metadata_method; struct grpc_chttp2_stream { - grpc_chttp2_transport *t; - grpc_stream_refcount *refcount; + grpc_chttp2_transport* t; + grpc_stream_refcount* refcount; grpc_closure destroy_stream; - grpc_closure *destroy_stream_arg; + grpc_closure* destroy_stream_arg; grpc_chttp2_stream_link links[STREAM_LIST_COUNT]; uint8_t included[STREAM_LIST_COUNT]; @@ -453,29 +453,29 @@ struct grpc_chttp2_stream { uint32_t id; /** things the upper layers would like to send */ - grpc_metadata_batch *send_initial_metadata; - grpc_closure *send_initial_metadata_finished; - grpc_metadata_batch *send_trailing_metadata; - grpc_closure *send_trailing_metadata_finished; + grpc_metadata_batch* send_initial_metadata; + grpc_closure* send_initial_metadata_finished; + grpc_metadata_batch* send_trailing_metadata; + grpc_closure* send_trailing_metadata_finished; - grpc_byte_stream *fetching_send_message; + grpc_byte_stream* fetching_send_message; uint32_t fetched_send_message_length; grpc_slice fetching_slice; int64_t next_message_end_offset; int64_t flow_controlled_bytes_written; int64_t flow_controlled_bytes_flowed; grpc_closure complete_fetch_locked; - grpc_closure *fetching_send_message_finished; + grpc_closure* fetching_send_message_finished; - grpc_metadata_batch *recv_initial_metadata; - grpc_closure *recv_initial_metadata_ready; - bool *trailing_metadata_available; - grpc_byte_stream **recv_message; - grpc_closure *recv_message_ready; - grpc_metadata_batch *recv_trailing_metadata; - grpc_closure *recv_trailing_metadata_finished; + grpc_metadata_batch* recv_initial_metadata; + grpc_closure* recv_initial_metadata_ready; + bool* trailing_metadata_available; + grpc_byte_stream** recv_message; + grpc_closure* recv_message_ready; + grpc_metadata_batch* recv_trailing_metadata; + grpc_closure* recv_trailing_metadata_finished; - grpc_transport_stream_stats *collecting_stats; + grpc_transport_stream_stats* collecting_stats; grpc_transport_stream_stats stats; /** Is this stream closed for writing. */ @@ -494,9 +494,9 @@ struct grpc_chttp2_stream { bool received_trailing_metadata; /** the error that resulted in this stream being read-closed */ - grpc_error *read_closed_error; + grpc_error* read_closed_error; /** the error that resulted in this stream being write-closed */ - grpc_error *write_closed_error; + grpc_error* write_closed_error; grpc_published_metadata_method published_metadata[2]; bool final_metadata_requested; @@ -509,16 +509,16 @@ struct grpc_chttp2_stream { * Accessed only by application thread when stream->pending_byte_stream == * true */ grpc_slice_buffer unprocessed_incoming_frames_buffer; - grpc_closure *on_next; /* protected by t combiner */ + grpc_closure* on_next; /* protected by t combiner */ bool pending_byte_stream; /* protected by t combiner */ grpc_closure reset_byte_stream; - grpc_error *byte_stream_error; /* protected by t combiner */ + grpc_error* byte_stream_error; /* protected by t combiner */ bool received_last_frame; /* protected by t combiner */ grpc_millis deadline; /** saw some stream level error */ - grpc_error *forced_close_error; + grpc_error* forced_close_error; /** how many header frames have we received? */ uint8_t header_frames_received; /** parsing state for data frames */ @@ -537,9 +537,9 @@ struct grpc_chttp2_stream { grpc_slice_buffer flow_controlled_buffer; - grpc_chttp2_write_cb *on_flow_controlled_cbs; - grpc_chttp2_write_cb *on_write_finished_cbs; - grpc_chttp2_write_cb *finish_after_write; + grpc_chttp2_write_cb* on_flow_controlled_cbs; + grpc_chttp2_write_cb* on_write_finished_cbs; + grpc_chttp2_write_cb* finish_after_write; size_t sending_bytes; /* Stream compression method to be used. */ @@ -547,9 +547,9 @@ struct grpc_chttp2_stream { /* Stream decompression method to be used. */ grpc_stream_compression_method stream_decompression_method; /** Stream compression decompress context */ - grpc_stream_compression_context *stream_decompression_ctx; + grpc_stream_compression_context* stream_decompression_ctx; /** Stream compression compress context */ - grpc_stream_compression_context *stream_compression_ctx; + grpc_stream_compression_context* stream_compression_ctx; /** Buffer storing data that is compressed but not sent */ grpc_slice_buffer compressed_data_buffer; @@ -577,8 +577,8 @@ struct grpc_chttp2_stream { The actual call chain is documented in the implementation of this function. */ -void grpc_chttp2_initiate_write(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +void grpc_chttp2_initiate_write(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_initiate_write_reason reason); typedef struct { @@ -591,85 +591,85 @@ typedef struct { } grpc_chttp2_begin_write_result; grpc_chttp2_begin_write_result grpc_chttp2_begin_write( - grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t); -void grpc_chttp2_end_write(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_error *error); + grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t); +void grpc_chttp2_end_write(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error); /** Process one slice of incoming data; return 1 if the connection is still viable after reading, or 0 if the connection should be torn down */ -grpc_error *grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_slice slice); -bool grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s); +bool grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream* s); /** Get a writable stream returns non-zero if there was a stream available */ -bool grpc_chttp2_list_pop_writable_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream **s); -bool grpc_chttp2_list_remove_writable_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s); - -bool grpc_chttp2_list_add_writing_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s); -bool grpc_chttp2_list_have_writing_streams(grpc_chttp2_transport *t); -bool grpc_chttp2_list_pop_writing_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream **s); - -void grpc_chttp2_list_add_written_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s); -bool grpc_chttp2_list_pop_written_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream **s); - -void grpc_chttp2_list_add_waiting_for_concurrency(grpc_chttp2_transport *t, - grpc_chttp2_stream *s); -bool grpc_chttp2_list_pop_waiting_for_concurrency(grpc_chttp2_transport *t, - grpc_chttp2_stream **s); -void grpc_chttp2_list_remove_waiting_for_concurrency(grpc_chttp2_transport *t, - grpc_chttp2_stream *s); - -void grpc_chttp2_list_add_stalled_by_transport(grpc_chttp2_transport *t, - grpc_chttp2_stream *s); -bool grpc_chttp2_list_pop_stalled_by_transport(grpc_chttp2_transport *t, - grpc_chttp2_stream **s); -void grpc_chttp2_list_remove_stalled_by_transport(grpc_chttp2_transport *t, - grpc_chttp2_stream *s); - -void grpc_chttp2_list_add_stalled_by_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s); -bool grpc_chttp2_list_pop_stalled_by_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream **s); -bool grpc_chttp2_list_remove_stalled_by_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s); +bool grpc_chttp2_list_pop_writable_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream** s); +bool grpc_chttp2_list_remove_writable_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream* s); + +bool grpc_chttp2_list_add_writing_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream* s); +bool grpc_chttp2_list_have_writing_streams(grpc_chttp2_transport* t); +bool grpc_chttp2_list_pop_writing_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream** s); + +void grpc_chttp2_list_add_written_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream* s); +bool grpc_chttp2_list_pop_written_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream** s); + +void grpc_chttp2_list_add_waiting_for_concurrency(grpc_chttp2_transport* t, + grpc_chttp2_stream* s); +bool grpc_chttp2_list_pop_waiting_for_concurrency(grpc_chttp2_transport* t, + grpc_chttp2_stream** s); +void grpc_chttp2_list_remove_waiting_for_concurrency(grpc_chttp2_transport* t, + grpc_chttp2_stream* s); + +void grpc_chttp2_list_add_stalled_by_transport(grpc_chttp2_transport* t, + grpc_chttp2_stream* s); +bool grpc_chttp2_list_pop_stalled_by_transport(grpc_chttp2_transport* t, + grpc_chttp2_stream** s); +void grpc_chttp2_list_remove_stalled_by_transport(grpc_chttp2_transport* t, + grpc_chttp2_stream* s); + +void grpc_chttp2_list_add_stalled_by_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream* s); +bool grpc_chttp2_list_pop_stalled_by_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream** s); +bool grpc_chttp2_list_remove_stalled_by_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream* s); /********* Flow Control ***************/ // Takes in a flow control action and performs all the needed operations. void grpc_chttp2_act_on_flowctl_action( - grpc_exec_ctx *exec_ctx, const grpc_core::chttp2::FlowControlAction &action, - grpc_chttp2_transport *t, grpc_chttp2_stream *s); + grpc_exec_ctx* exec_ctx, const grpc_core::chttp2::FlowControlAction& action, + grpc_chttp2_transport* t, grpc_chttp2_stream* s); /********* End of Flow Control ***************/ -grpc_chttp2_stream *grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport *t, +grpc_chttp2_stream* grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport* t, uint32_t id); -grpc_chttp2_stream *grpc_chttp2_parsing_accept_stream(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, uint32_t id); -void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, uint32_t goaway_error, grpc_slice goaway_text); -void grpc_chttp2_parsing_become_skip_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); +void grpc_chttp2_parsing_become_skip_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); -void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, - grpc_closure **pclosure, - grpc_error *error, const char *desc); +void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, + grpc_closure** pclosure, + grpc_error* error, const char* desc); #define GRPC_HEADER_SIZE_IN_BYTES 5 #define MAX_SIZE_T (~(size_t)0) @@ -685,31 +685,31 @@ extern grpc_tracer_flag grpc_flowctl_trace; if (!(GRPC_TRACER_ON(grpc_http_trace))) \ ; \ else \ - stmt + stmt -void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_stream *stream, grpc_error *error); -void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, int close_reads, - int close_writes, grpc_error *error); -void grpc_chttp2_start_writing(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); +void grpc_chttp2_fake_status(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* stream, grpc_error* error); +void grpc_chttp2_mark_stream_closed(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, int close_reads, + int close_writes, grpc_error* error); +void grpc_chttp2_start_writing(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); #ifndef NDEBUG #define GRPC_CHTTP2_STREAM_REF(stream, reason) \ grpc_chttp2_stream_ref(stream, reason) #define GRPC_CHTTP2_STREAM_UNREF(exec_ctx, stream, reason) \ grpc_chttp2_stream_unref(exec_ctx, stream, reason) -void grpc_chttp2_stream_ref(grpc_chttp2_stream *s, const char *reason); -void grpc_chttp2_stream_unref(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream *s, - const char *reason); +void grpc_chttp2_stream_ref(grpc_chttp2_stream* s, const char* reason); +void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s, + const char* reason); #else #define GRPC_CHTTP2_STREAM_REF(stream, reason) grpc_chttp2_stream_ref(stream) #define GRPC_CHTTP2_STREAM_UNREF(exec_ctx, stream, reason) \ grpc_chttp2_stream_unref(exec_ctx, stream) -void grpc_chttp2_stream_ref(grpc_chttp2_stream *s); -void grpc_chttp2_stream_unref(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream *s); +void grpc_chttp2_stream_ref(grpc_chttp2_stream* s); +void grpc_chttp2_stream_unref(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s); #endif #ifndef NDEBUG @@ -717,69 +717,69 @@ void grpc_chttp2_stream_unref(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream *s); grpc_chttp2_ref_transport(t, r, __FILE__, __LINE__) #define GRPC_CHTTP2_UNREF_TRANSPORT(cl, t, r) \ grpc_chttp2_unref_transport(cl, t, r, __FILE__, __LINE__) -void grpc_chttp2_unref_transport(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, const char *reason, - const char *file, int line); -void grpc_chttp2_ref_transport(grpc_chttp2_transport *t, const char *reason, - const char *file, int line); +void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, const char* reason, + const char* file, int line); +void grpc_chttp2_ref_transport(grpc_chttp2_transport* t, const char* reason, + const char* file, int line); #else #define GRPC_CHTTP2_REF_TRANSPORT(t, r) grpc_chttp2_ref_transport(t) #define GRPC_CHTTP2_UNREF_TRANSPORT(cl, t, r) grpc_chttp2_unref_transport(cl, t) -void grpc_chttp2_unref_transport(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); -void grpc_chttp2_ref_transport(grpc_chttp2_transport *t); +void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +void grpc_chttp2_ref_transport(grpc_chttp2_transport* t); #endif -grpc_chttp2_incoming_byte_stream *grpc_chttp2_incoming_byte_stream_create( - grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s, +grpc_chttp2_incoming_byte_stream* grpc_chttp2_incoming_byte_stream_create( + grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* s, uint32_t frame_size, uint32_t flags); -grpc_error *grpc_chttp2_incoming_byte_stream_push( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs, - grpc_slice slice, grpc_slice *slice_out); -grpc_error *grpc_chttp2_incoming_byte_stream_finished( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs, - grpc_error *error, bool reset_on_error); +grpc_error* grpc_chttp2_incoming_byte_stream_push( + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_slice slice, grpc_slice* slice_out); +grpc_error* grpc_chttp2_incoming_byte_stream_finished( + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_error* error, bool reset_on_error); void grpc_chttp2_incoming_byte_stream_notify( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs, - grpc_error *error); + grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_byte_stream* bs, + grpc_error* error); -void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, +void grpc_chttp2_ack_ping(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, uint64_t id); /** Add a new ping strike to ping_recv_state.ping_strikes. If ping_recv_state.ping_strikes > ping_policy.max_ping_strikes, it sends GOAWAY with error code ENHANCE_YOUR_CALM and additional debug data resembling "too_many_pings" followed by immediately closing the connection. */ -void grpc_chttp2_add_ping_strike(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); +void grpc_chttp2_add_ping_strike(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); /** add a ref to the stream and add it to the writable list; ref will be dropped in writing.c */ -void grpc_chttp2_mark_stream_writable(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s); - -void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, grpc_chttp2_stream *s, - grpc_error *due_to_error); - -void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s); -void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s); -void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s); - -void grpc_chttp2_fail_pending_writes(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, - grpc_chttp2_stream *s, grpc_error *error); +void grpc_chttp2_mark_stream_writable(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s); + +void grpc_chttp2_cancel_stream(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, + grpc_error* due_to_error); + +void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s); +void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s); +void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s); + +void grpc_chttp2_fail_pending_writes(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_error* error); /** Set the default keepalive configurations, must only be called at initialization */ -void grpc_chttp2_config_default_keepalive_args(grpc_channel_args *args, +void grpc_chttp2_config_default_keepalive_args(grpc_channel_args* args, bool is_client); #ifdef __cplusplus diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index efa5791d3f..8a3774d688 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -31,38 +31,38 @@ #include "src/core/lib/transport/status_conversion.h" #include "src/core/lib/transport/timeout_encoding.h" -static grpc_error *init_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); -static grpc_error *init_header_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +static grpc_error* init_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, int is_continuation); -static grpc_error *init_data_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); -static grpc_error *init_rst_stream_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); -static grpc_error *init_settings_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); -static grpc_error *init_window_update_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); -static grpc_error *init_ping_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); -static grpc_error *init_goaway_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t); -static grpc_error *init_skip_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +static grpc_error* init_data_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_rst_stream_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_settings_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_window_update_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_ping_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_goaway_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t); +static grpc_error* init_skip_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, int is_header); -static grpc_error *parse_frame_slice(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, grpc_slice slice, +static grpc_error* parse_frame_slice(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_slice slice, int is_last); -grpc_error *grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_slice slice) { - uint8_t *beg = GRPC_SLICE_START_PTR(slice); - uint8_t *end = GRPC_SLICE_END_PTR(slice); - uint8_t *cur = beg; - grpc_error *err; + uint8_t* beg = GRPC_SLICE_START_PTR(slice); + uint8_t* end = GRPC_SLICE_END_PTR(slice); + uint8_t* cur = beg; + grpc_error* err; if (cur == end) return GRPC_ERROR_NONE; @@ -93,7 +93,7 @@ grpc_error *grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, case GRPC_DTS_CLIENT_PREFIX_23: while (cur != end && t->deframe_state != GRPC_DTS_FH_0) { if (*cur != GRPC_CHTTP2_CLIENT_CONNECT_STRING[t->deframe_state]) { - char *msg; + char* msg; gpr_asprintf( &msg, "Connect string mismatch: expected '%c' (%d) got '%c' (%d) " @@ -200,7 +200,7 @@ grpc_error *grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, } else if (t->incoming_frame_size > t->settings[GRPC_ACKED_SETTINGS] [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE]) { - char *msg; + char* msg; gpr_asprintf(&msg, "Frame size %d is larger than max frame size %d", t->incoming_frame_size, t->settings[GRPC_ACKED_SETTINGS] @@ -216,10 +216,11 @@ grpc_error *grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, case GRPC_DTS_FRAME: GPR_ASSERT(cur < end); if ((uint32_t)(end - cur) == t->incoming_frame_size) { - err = parse_frame_slice( - exec_ctx, t, grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), - (size_t)(end - beg)), - 1); + err = + parse_frame_slice(exec_ctx, t, + grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), + (size_t)(end - beg)), + 1); if (err != GRPC_ERROR_NONE) { return err; } @@ -240,10 +241,11 @@ grpc_error *grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, t->incoming_stream = NULL; goto dts_fh_0; /* loop */ } else { - err = parse_frame_slice( - exec_ctx, t, grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), - (size_t)(end - beg)), - 0); + err = + parse_frame_slice(exec_ctx, t, + grpc_slice_sub_no_ref(slice, (size_t)(cur - beg), + (size_t)(end - beg)), + 0); if (err != GRPC_ERROR_NONE) { return err; } @@ -256,36 +258,36 @@ grpc_error *grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, GPR_UNREACHABLE_CODE(return 0); } -static grpc_error *init_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { +static grpc_error* init_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { if (t->is_first_frame && t->incoming_frame_type != GRPC_CHTTP2_FRAME_SETTINGS) { - char *msg; + char* msg; gpr_asprintf( &msg, "Expected SETTINGS frame as the first frame, got frame type %d", t->incoming_frame_type); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } t->is_first_frame = false; if (t->expect_continuation_stream_id != 0) { if (t->incoming_frame_type != GRPC_CHTTP2_FRAME_CONTINUATION) { - char *msg; + char* msg; gpr_asprintf(&msg, "Expected CONTINUATION frame, got frame type %02x", t->incoming_frame_type); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } if (t->expect_continuation_stream_id != t->incoming_stream_id) { - char *msg; + char* msg; gpr_asprintf( &msg, "Expected CONTINUATION frame for grpc_chttp2_stream %08x, got " "grpc_chttp2_stream %08x", t->expect_continuation_stream_id, t->incoming_stream_id); - grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); return err; } @@ -317,18 +319,18 @@ static grpc_error *init_frame_parser(grpc_exec_ctx *exec_ctx, } } -static grpc_error *skip_parser(grpc_exec_ctx *exec_ctx, void *parser, - grpc_chttp2_transport *t, grpc_chttp2_stream *s, +static grpc_error* skip_parser(grpc_exec_ctx* exec_ctx, void* parser, + grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_slice slice, int is_last) { return GRPC_ERROR_NONE; } -static void skip_header(grpc_exec_ctx *exec_ctx, void *tp, grpc_mdelem md) { +static void skip_header(grpc_exec_ctx* exec_ctx, void* tp, grpc_mdelem md) { GRPC_MDELEM_UNREF(exec_ctx, md); } -static grpc_error *init_skip_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +static grpc_error* init_skip_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, int is_header) { if (is_header) { uint8_t is_eoh = t->expect_continuation_stream_id != 0; @@ -344,17 +346,17 @@ static grpc_error *init_skip_frame_parser(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -void grpc_chttp2_parsing_become_skip_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { +void grpc_chttp2_parsing_become_skip_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { init_skip_frame_parser(exec_ctx, t, t->parser == grpc_chttp2_header_parser_parse); } -static grpc_error *init_data_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { - grpc_chttp2_stream *s = +static grpc_error* init_data_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { + grpc_chttp2_stream* s = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); - grpc_error *err = GRPC_ERROR_NONE; + grpc_error* err = GRPC_ERROR_NONE; grpc_core::chttp2::FlowControlAction action; if (s == nullptr) { err = t->flow_control->RecvData(t->incoming_frame_size); @@ -404,20 +406,20 @@ error_handler: } } -static void free_timeout(void *p) { gpr_free(p); } +static void free_timeout(void* p) { gpr_free(p); } -static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, +static void on_initial_header(grpc_exec_ctx* exec_ctx, void* tp, grpc_mdelem md) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; - grpc_chttp2_stream *s = t->incoming_stream; + grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_stream* s = t->incoming_stream; GPR_TIMER_BEGIN("on_initial_header", 0); GPR_ASSERT(s != NULL); if (GRPC_TRACER_ON(grpc_http_trace)) { - char *key = grpc_slice_to_c_string(GRPC_MDKEY(md)); - char *value = + char* key = grpc_slice_to_c_string(GRPC_MDKEY(md)); + char* value = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_INFO, "HTTP:%d:HDR:%s: %s: %s", s->id, t->is_client ? "CLI" : "SVR", key, value); @@ -432,21 +434,21 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, } if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_TIMEOUT)) { - grpc_millis *cached_timeout = - static_cast<grpc_millis *>(grpc_mdelem_get_user_data(md, free_timeout)); + grpc_millis* cached_timeout = + static_cast<grpc_millis*>(grpc_mdelem_get_user_data(md, free_timeout)); grpc_millis timeout; if (cached_timeout != NULL) { timeout = *cached_timeout; } else { if (!grpc_http2_decode_timeout(GRPC_MDVALUE(md), &timeout)) { - char *val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); + char* val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'", val); gpr_free(val); timeout = GRPC_MILLIS_INF_FUTURE; } if (GRPC_MDELEM_IS_INTERNED(md)) { /* store the result */ - cached_timeout = (grpc_millis *)gpr_malloc(sizeof(grpc_millis)); + cached_timeout = (grpc_millis*)gpr_malloc(sizeof(grpc_millis)); *cached_timeout = timeout; grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); } @@ -476,7 +478,7 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, s->seen_error = true; GRPC_MDELEM_UNREF(exec_ctx, md); } else { - grpc_error *error = grpc_chttp2_incoming_metadata_buffer_add( + grpc_error* error = grpc_chttp2_incoming_metadata_buffer_add( exec_ctx, &s->metadata_buffer[0], md); if (error != GRPC_ERROR_NONE) { grpc_chttp2_cancel_stream(exec_ctx, t, s, error); @@ -490,18 +492,18 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, GPR_TIMER_END("on_initial_header", 0); } -static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp, +static void on_trailing_header(grpc_exec_ctx* exec_ctx, void* tp, grpc_mdelem md) { - grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; - grpc_chttp2_stream *s = t->incoming_stream; + grpc_chttp2_transport* t = (grpc_chttp2_transport*)tp; + grpc_chttp2_stream* s = t->incoming_stream; GPR_TIMER_BEGIN("on_trailing_header", 0); GPR_ASSERT(s != NULL); if (GRPC_TRACER_ON(grpc_http_trace)) { - char *key = grpc_slice_to_c_string(GRPC_MDKEY(md)); - char *value = + char* key = grpc_slice_to_c_string(GRPC_MDKEY(md)); + char* value = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_INFO, "HTTP:%d:TRL:%s: %s: %s", s->id, t->is_client ? "CLI" : "SVR", key, value); @@ -534,7 +536,7 @@ static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp, s->seen_error = true; GRPC_MDELEM_UNREF(exec_ctx, md); } else { - grpc_error *error = grpc_chttp2_incoming_metadata_buffer_add( + grpc_error* error = grpc_chttp2_incoming_metadata_buffer_add( exec_ctx, &s->metadata_buffer[1], md); if (error != GRPC_ERROR_NONE) { grpc_chttp2_cancel_stream(exec_ctx, t, s, error); @@ -547,12 +549,12 @@ static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp, GPR_TIMER_END("on_trailing_header", 0); } -static grpc_error *init_header_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, +static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, int is_continuation) { uint8_t is_eoh = (t->incoming_frame_flags & GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0; - grpc_chttp2_stream *s; + grpc_chttp2_stream* s; /* TODO(ctiller): when to increment header_frames_received? */ @@ -662,14 +664,14 @@ static grpc_error *init_header_frame_parser(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error *init_window_update_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { - grpc_error *err = grpc_chttp2_window_update_parser_begin_frame( +static grpc_error* init_window_update_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { + grpc_error* err = grpc_chttp2_window_update_parser_begin_frame( &t->simple.window_update, t->incoming_frame_size, t->incoming_frame_flags); if (err != GRPC_ERROR_NONE) return err; if (t->incoming_stream_id != 0) { - grpc_chttp2_stream *s = t->incoming_stream = + grpc_chttp2_stream* s = t->incoming_stream = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); if (s == NULL) { return init_skip_frame_parser(exec_ctx, t, 0); @@ -681,9 +683,9 @@ static grpc_error *init_window_update_frame_parser(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error *init_ping_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { - grpc_error *err = grpc_chttp2_ping_parser_begin_frame( +static grpc_error* init_ping_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { + grpc_error* err = grpc_chttp2_ping_parser_begin_frame( &t->simple.ping, t->incoming_frame_size, t->incoming_frame_flags); if (err != GRPC_ERROR_NONE) return err; t->parser = grpc_chttp2_ping_parser_parse; @@ -691,12 +693,12 @@ static grpc_error *init_ping_parser(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error *init_rst_stream_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { - grpc_error *err = grpc_chttp2_rst_stream_parser_begin_frame( +static grpc_error* init_rst_stream_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { + grpc_error* err = grpc_chttp2_rst_stream_parser_begin_frame( &t->simple.rst_stream, t->incoming_frame_size, t->incoming_frame_flags); if (err != GRPC_ERROR_NONE) return err; - grpc_chttp2_stream *s = t->incoming_stream = + grpc_chttp2_stream* s = t->incoming_stream = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); if (!t->incoming_stream) { return init_skip_frame_parser(exec_ctx, t, 0); @@ -707,9 +709,9 @@ static grpc_error *init_rst_stream_parser(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error *init_goaway_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { - grpc_error *err = grpc_chttp2_goaway_parser_begin_frame( +static grpc_error* init_goaway_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { + grpc_error* err = grpc_chttp2_goaway_parser_begin_frame( &t->goaway_parser, t->incoming_frame_size, t->incoming_frame_flags); if (err != GRPC_ERROR_NONE) return err; t->parser = grpc_chttp2_goaway_parser_parse; @@ -717,14 +719,14 @@ static grpc_error *init_goaway_parser(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error *init_settings_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { +static grpc_error* init_settings_frame_parser(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { if (t->incoming_stream_id != 0) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Settings frame received for grpc_chttp2_stream"); } - grpc_error *err = grpc_chttp2_settings_parser_begin_frame( + grpc_error* err = grpc_chttp2_settings_parser_begin_frame( &t->simple.settings, t->incoming_frame_size, t->incoming_frame_flags, t->settings[GRPC_PEER_SETTINGS]); if (err != GRPC_ERROR_NONE) { @@ -744,16 +746,16 @@ static grpc_error *init_settings_frame_parser(grpc_exec_ctx *exec_ctx, return GRPC_ERROR_NONE; } -static grpc_error *parse_frame_slice(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t, grpc_slice slice, +static grpc_error* parse_frame_slice(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t, grpc_slice slice, int is_last) { - grpc_chttp2_stream *s = t->incoming_stream; - grpc_error *err = t->parser(exec_ctx, t->parser_data, t, s, slice, is_last); + grpc_chttp2_stream* s = t->incoming_stream; + grpc_error* err = t->parser(exec_ctx, t->parser_data, t, s, slice, is_last); if (err == GRPC_ERROR_NONE) { return err; } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, NULL)) { if (GRPC_TRACER_ON(grpc_http_trace)) { - const char *msg = grpc_error_string(err); + const char* msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); } grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); diff --git a/src/core/ext/transport/chttp2/transport/stream_lists.cc b/src/core/ext/transport/chttp2/transport/stream_lists.cc index 9f731a397f..8d25ab277d 100644 --- a/src/core/ext/transport/chttp2/transport/stream_lists.cc +++ b/src/core/ext/transport/chttp2/transport/stream_lists.cc @@ -21,7 +21,7 @@ #include <grpc/support/log.h> -static const char *stream_list_id_string(grpc_chttp2_stream_list_id id) { +static const char* stream_list_id_string(grpc_chttp2_stream_list_id id) { switch (id) { case GRPC_CHTTP2_LIST_WRITABLE: return "writable"; @@ -44,17 +44,17 @@ grpc_tracer_flag grpc_trace_http2_stream_state = /* core list management */ -static bool stream_list_empty(grpc_chttp2_transport *t, +static bool stream_list_empty(grpc_chttp2_transport* t, grpc_chttp2_stream_list_id id) { return t->lists[id].head == NULL; } -static bool stream_list_pop(grpc_chttp2_transport *t, - grpc_chttp2_stream **stream, +static bool stream_list_pop(grpc_chttp2_transport* t, + grpc_chttp2_stream** stream, grpc_chttp2_stream_list_id id) { - grpc_chttp2_stream *s = t->lists[id].head; + grpc_chttp2_stream* s = t->lists[id].head; if (s) { - grpc_chttp2_stream *new_head = s->links[id].next; + grpc_chttp2_stream* new_head = s->links[id].next; GPR_ASSERT(s->included[id]); if (new_head) { t->lists[id].head = new_head; @@ -73,7 +73,7 @@ static bool stream_list_pop(grpc_chttp2_transport *t, return s != 0; } -static void stream_list_remove(grpc_chttp2_transport *t, grpc_chttp2_stream *s, +static void stream_list_remove(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_chttp2_stream_list_id id) { GPR_ASSERT(s->included[id]); s->included[id] = 0; @@ -94,8 +94,8 @@ static void stream_list_remove(grpc_chttp2_transport *t, grpc_chttp2_stream *s, } } -static bool stream_list_maybe_remove(grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +static bool stream_list_maybe_remove(grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_chttp2_stream_list_id id) { if (s->included[id]) { stream_list_remove(t, s, id); @@ -105,10 +105,10 @@ static bool stream_list_maybe_remove(grpc_chttp2_transport *t, } } -static void stream_list_add_tail(grpc_chttp2_transport *t, - grpc_chttp2_stream *s, +static void stream_list_add_tail(grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_chttp2_stream_list_id id) { - grpc_chttp2_stream *old_tail; + grpc_chttp2_stream* old_tail; GPR_ASSERT(!s->included[id]); old_tail = t->lists[id].tail; s->links[id].next = NULL; @@ -126,7 +126,7 @@ static void stream_list_add_tail(grpc_chttp2_transport *t, } } -static bool stream_list_add(grpc_chttp2_transport *t, grpc_chttp2_stream *s, +static bool stream_list_add(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_chttp2_stream_list_id id) { if (s->included[id]) { return false; @@ -137,77 +137,77 @@ static bool stream_list_add(grpc_chttp2_transport *t, grpc_chttp2_stream *s, /* wrappers for specializations */ -bool grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +bool grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { GPR_ASSERT(s->id != 0); return stream_list_add(t, s, GRPC_CHTTP2_LIST_WRITABLE); } -bool grpc_chttp2_list_pop_writable_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream **s) { +bool grpc_chttp2_list_pop_writable_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream** s) { return stream_list_pop(t, s, GRPC_CHTTP2_LIST_WRITABLE); } -bool grpc_chttp2_list_remove_writable_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +bool grpc_chttp2_list_remove_writable_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { return stream_list_maybe_remove(t, s, GRPC_CHTTP2_LIST_WRITABLE); } -bool grpc_chttp2_list_add_writing_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +bool grpc_chttp2_list_add_writing_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { return stream_list_add(t, s, GRPC_CHTTP2_LIST_WRITING); } -bool grpc_chttp2_list_have_writing_streams(grpc_chttp2_transport *t) { +bool grpc_chttp2_list_have_writing_streams(grpc_chttp2_transport* t) { return !stream_list_empty(t, GRPC_CHTTP2_LIST_WRITING); } -bool grpc_chttp2_list_pop_writing_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream **s) { +bool grpc_chttp2_list_pop_writing_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream** s) { return stream_list_pop(t, s, GRPC_CHTTP2_LIST_WRITING); } -void grpc_chttp2_list_add_waiting_for_concurrency(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +void grpc_chttp2_list_add_waiting_for_concurrency(grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { stream_list_add(t, s, GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY); } -bool grpc_chttp2_list_pop_waiting_for_concurrency(grpc_chttp2_transport *t, - grpc_chttp2_stream **s) { +bool grpc_chttp2_list_pop_waiting_for_concurrency(grpc_chttp2_transport* t, + grpc_chttp2_stream** s) { return stream_list_pop(t, s, GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY); } -void grpc_chttp2_list_remove_waiting_for_concurrency(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +void grpc_chttp2_list_remove_waiting_for_concurrency(grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { stream_list_maybe_remove(t, s, GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY); } -void grpc_chttp2_list_add_stalled_by_transport(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +void grpc_chttp2_list_add_stalled_by_transport(grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { stream_list_add(t, s, GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT); } -bool grpc_chttp2_list_pop_stalled_by_transport(grpc_chttp2_transport *t, - grpc_chttp2_stream **s) { +bool grpc_chttp2_list_pop_stalled_by_transport(grpc_chttp2_transport* t, + grpc_chttp2_stream** s) { return stream_list_pop(t, s, GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT); } -void grpc_chttp2_list_remove_stalled_by_transport(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +void grpc_chttp2_list_remove_stalled_by_transport(grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { stream_list_maybe_remove(t, s, GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT); } -void grpc_chttp2_list_add_stalled_by_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +void grpc_chttp2_list_add_stalled_by_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { stream_list_add(t, s, GRPC_CHTTP2_LIST_STALLED_BY_STREAM); } -bool grpc_chttp2_list_pop_stalled_by_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream **s) { +bool grpc_chttp2_list_pop_stalled_by_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream** s) { return stream_list_pop(t, s, GRPC_CHTTP2_LIST_STALLED_BY_STREAM); } -bool grpc_chttp2_list_remove_stalled_by_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { +bool grpc_chttp2_list_remove_stalled_by_stream(grpc_chttp2_transport* t, + grpc_chttp2_stream* s) { return stream_list_maybe_remove(t, s, GRPC_CHTTP2_LIST_STALLED_BY_STREAM); } diff --git a/src/core/ext/transport/chttp2/transport/stream_map.cc b/src/core/ext/transport/chttp2/transport/stream_map.cc index d6079a9a33..c863191795 100644 --- a/src/core/ext/transport/chttp2/transport/stream_map.cc +++ b/src/core/ext/transport/chttp2/transport/stream_map.cc @@ -24,22 +24,22 @@ #include <grpc/support/log.h> #include <grpc/support/useful.h> -void grpc_chttp2_stream_map_init(grpc_chttp2_stream_map *map, +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 = (uint32_t*)gpr_malloc(sizeof(uint32_t) * initial_capacity); + map->values = (void**)gpr_malloc(sizeof(void*) * initial_capacity); map->count = 0; map->free = 0; map->capacity = initial_capacity; } -void grpc_chttp2_stream_map_destroy(grpc_chttp2_stream_map *map) { +void grpc_chttp2_stream_map_destroy(grpc_chttp2_stream_map* map) { gpr_free(map->keys); gpr_free(map->values); } -static size_t compact(uint32_t *keys, void **values, size_t count) { +static size_t compact(uint32_t* keys, void** values, size_t count) { size_t i, out; for (i = 0, out = 0; i < count; i++) { @@ -53,12 +53,12 @@ static size_t compact(uint32_t *keys, void **values, size_t count) { return out; } -void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map *map, uint32_t key, - void *value) { +void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map* map, uint32_t key, + void* value) { size_t count = map->count; size_t capacity = map->capacity; - uint32_t *keys = map->keys; - void **values = map->values; + uint32_t* keys = map->keys; + void** values = map->values; GPR_ASSERT(count == 0 || keys[count - 1] < key); GPR_ASSERT(value); @@ -73,9 +73,9 @@ void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map *map, uint32_t key, won't help much */ map->capacity = capacity = 3 * capacity / 2; map->keys = keys = - (uint32_t *)gpr_realloc(keys, capacity * sizeof(uint32_t)); + (uint32_t*)gpr_realloc(keys, capacity * sizeof(uint32_t)); map->values = values = - (void **)gpr_realloc(values, capacity * sizeof(void *)); + (void**)gpr_realloc(values, capacity * sizeof(void*)); } } @@ -84,12 +84,12 @@ void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map *map, uint32_t key, map->count = count + 1; } -static void **find(grpc_chttp2_stream_map *map, uint32_t key) { +static void** find(grpc_chttp2_stream_map* map, uint32_t key) { size_t min_idx = 0; size_t max_idx = map->count; size_t mid_idx; - uint32_t *keys = map->keys; - void **values = map->values; + uint32_t* keys = map->keys; + void** values = map->values; uint32_t mid_key; if (max_idx == 0) return NULL; @@ -112,9 +112,9 @@ static void **find(grpc_chttp2_stream_map *map, uint32_t key) { return NULL; } -void *grpc_chttp2_stream_map_delete(grpc_chttp2_stream_map *map, uint32_t key) { - void **pvalue = find(map, key); - void *out = NULL; +void* grpc_chttp2_stream_map_delete(grpc_chttp2_stream_map* map, uint32_t key) { + void** pvalue = find(map, key); + void* out = NULL; if (pvalue != NULL) { out = *pvalue; *pvalue = NULL; @@ -129,16 +129,16 @@ void *grpc_chttp2_stream_map_delete(grpc_chttp2_stream_map *map, uint32_t key) { return out; } -void *grpc_chttp2_stream_map_find(grpc_chttp2_stream_map *map, uint32_t key) { - void **pvalue = find(map, key); +void* grpc_chttp2_stream_map_find(grpc_chttp2_stream_map* map, uint32_t key) { + void** pvalue = find(map, key); return pvalue != NULL ? *pvalue : NULL; } -size_t grpc_chttp2_stream_map_size(grpc_chttp2_stream_map *map) { +size_t grpc_chttp2_stream_map_size(grpc_chttp2_stream_map* map) { return map->count - map->free; } -void *grpc_chttp2_stream_map_rand(grpc_chttp2_stream_map *map) { +void* grpc_chttp2_stream_map_rand(grpc_chttp2_stream_map* map) { if (map->count == map->free) { return NULL; } @@ -149,10 +149,10 @@ void *grpc_chttp2_stream_map_rand(grpc_chttp2_stream_map *map) { return map->values[((size_t)rand()) % map->count]; } -void grpc_chttp2_stream_map_for_each(grpc_chttp2_stream_map *map, - void (*f)(void *user_data, uint32_t key, - void *value), - void *user_data) { +void grpc_chttp2_stream_map_for_each(grpc_chttp2_stream_map* map, + void (*f)(void* user_data, uint32_t key, + void* value), + void* user_data) { size_t i; for (i = 0; i < map->count; i++) { diff --git a/src/core/ext/transport/chttp2/transport/stream_map.h b/src/core/ext/transport/chttp2/transport/stream_map.h index 7ab6a4f5ed..c89d20047c 100644 --- a/src/core/ext/transport/chttp2/transport/stream_map.h +++ b/src/core/ext/transport/chttp2/transport/stream_map.h @@ -34,40 +34,40 @@ extern "C" { Adds are restricted to strictly higher keys than previously seen (this is guaranteed by http2). */ typedef struct { - uint32_t *keys; - void **values; + uint32_t* keys; + void** values; size_t count; size_t free; size_t capacity; } grpc_chttp2_stream_map; -void grpc_chttp2_stream_map_init(grpc_chttp2_stream_map *map, +void grpc_chttp2_stream_map_init(grpc_chttp2_stream_map* map, size_t initial_capacity); -void grpc_chttp2_stream_map_destroy(grpc_chttp2_stream_map *map); +void grpc_chttp2_stream_map_destroy(grpc_chttp2_stream_map* map); /* Add a new key: given http2 semantics, new keys must always be greater than existing keys - this is asserted */ -void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map *map, uint32_t key, - void *value); +void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map* map, uint32_t key, + void* value); /* Delete an existing key - returns the previous value of the key if it existed, or NULL otherwise */ -void *grpc_chttp2_stream_map_delete(grpc_chttp2_stream_map *map, uint32_t key); +void* grpc_chttp2_stream_map_delete(grpc_chttp2_stream_map* map, uint32_t key); /* Return an existing key, or NULL if it does not exist */ -void *grpc_chttp2_stream_map_find(grpc_chttp2_stream_map *map, uint32_t key); +void* grpc_chttp2_stream_map_find(grpc_chttp2_stream_map* map, uint32_t key); /* Return a random entry */ -void *grpc_chttp2_stream_map_rand(grpc_chttp2_stream_map *map); +void* grpc_chttp2_stream_map_rand(grpc_chttp2_stream_map* map); /* How many (populated) entries are in the stream map? */ -size_t grpc_chttp2_stream_map_size(grpc_chttp2_stream_map *map); +size_t grpc_chttp2_stream_map_size(grpc_chttp2_stream_map* map); /* Callback on each stream */ -void grpc_chttp2_stream_map_for_each(grpc_chttp2_stream_map *map, - void (*f)(void *user_data, uint32_t key, - void *value), - void *user_data); +void grpc_chttp2_stream_map_for_each(grpc_chttp2_stream_map* map, + void (*f)(void* user_data, uint32_t key, + void* value), + void* user_data); #ifdef __cplusplus } diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index ff76a5fcdb..6154bdb682 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -27,24 +27,24 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/http2_errors.h" -static void add_to_write_list(grpc_chttp2_write_cb **list, - grpc_chttp2_write_cb *cb) { +static void add_to_write_list(grpc_chttp2_write_cb** list, + grpc_chttp2_write_cb* cb) { cb->next = *list; *list = cb; } -static void finish_write_cb(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_stream *s, grpc_chttp2_write_cb *cb, - grpc_error *error) { +static void finish_write_cb(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, grpc_chttp2_write_cb* cb, + grpc_error* error) { grpc_chttp2_complete_closure_step(exec_ctx, t, s, &cb->closure, error, "finish_write_cb"); cb->next = t->write_cb_pool; t->write_cb_pool = cb; } -static void maybe_initiate_ping(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport *t) { - grpc_chttp2_ping_queue *pq = &t->ping_queue; +static void maybe_initiate_ping(grpc_exec_ctx* exec_ctx, + grpc_chttp2_transport* t) { + grpc_chttp2_ping_queue* pq = &t->ping_queue; if (grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_NEXT])) { /* no ping needed: wait */ return; @@ -114,16 +114,16 @@ static void maybe_initiate_ping(grpc_exec_ctx *exec_ctx, (t->ping_state.pings_before_data_required != 0); } -static bool update_list(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_stream *s, int64_t send_bytes, - grpc_chttp2_write_cb **list, int64_t *ctr, - grpc_error *error) { +static bool update_list(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_chttp2_stream* s, int64_t send_bytes, + grpc_chttp2_write_cb** list, int64_t* ctr, + grpc_error* error) { bool sched_any = false; - grpc_chttp2_write_cb *cb = *list; + grpc_chttp2_write_cb* cb = *list; *list = NULL; *ctr += send_bytes; while (cb) { - grpc_chttp2_write_cb *next = cb->next; + grpc_chttp2_write_cb* next = cb->next; if (cb->call_at_byte <= *ctr) { sched_any = true; finish_write_cb(exec_ctx, t, s, cb, GRPC_ERROR_REF(error)); @@ -136,8 +136,8 @@ static bool update_list(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, return sched_any; } -static void report_stall(grpc_chttp2_transport *t, grpc_chttp2_stream *s, - const char *staller) { +static void report_stall(grpc_chttp2_transport* t, grpc_chttp2_stream* s, + const char* staller) { gpr_log( GPR_DEBUG, "%s:%p stream %d stalled by %s [fc:pending=%" PRIdPTR ":flowed=%" PRId64 @@ -155,7 +155,7 @@ static void report_stall(grpc_chttp2_transport *t, grpc_chttp2_stream *s, s->flow_control->remote_window_delta()); } -static bool stream_ref_if_not_destroyed(gpr_refcount *r) { +static bool stream_ref_if_not_destroyed(gpr_refcount* r) { gpr_atm count; do { count = gpr_atm_acq_load(&r->count); @@ -165,12 +165,12 @@ static bool stream_ref_if_not_destroyed(gpr_refcount *r) { } /* How many bytes would we like to put on the wire during a single syscall */ -static uint32_t target_write_size(grpc_chttp2_transport *t) { +static uint32_t target_write_size(grpc_chttp2_transport* t) { return 1024 * 1024; } // Returns true if initial_metadata contains only default headers. -static bool is_default_initial_metadata(grpc_metadata_batch *initial_metadata) { +static bool is_default_initial_metadata(grpc_metadata_batch* initial_metadata) { return initial_metadata->list.default_count == initial_metadata->list.count; } @@ -179,13 +179,13 @@ class StreamWriteContext; class WriteContext { public: - WriteContext(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) : t_(t) { + WriteContext(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t) : t_(t) { GRPC_STATS_INC_HTTP2_WRITES_BEGUN(exec_ctx); GPR_TIMER_BEGIN("grpc_chttp2_begin_write", 0); } // TODO(ctiller): make this the destructor - void FlushStats(grpc_exec_ctx *exec_ctx) { + void FlushStats(grpc_exec_ctx* exec_ctx) { GRPC_STATS_INC_HTTP2_SEND_INITIAL_METADATA_PER_WRITE( exec_ctx, initial_metadata_writes_); GRPC_STATS_INC_HTTP2_SEND_MESSAGE_PER_WRITE(exec_ctx, message_writes_); @@ -194,7 +194,7 @@ class WriteContext { GRPC_STATS_INC_HTTP2_SEND_FLOWCTL_PER_WRITE(exec_ctx, flow_control_writes_); } - void FlushSettings(grpc_exec_ctx *exec_ctx) { + void FlushSettings(grpc_exec_ctx* exec_ctx) { if (t_->dirtied_local_settings && !t_->sent_local_settings) { grpc_slice_buffer_add( &t_->outbuf, grpc_chttp2_settings_create( @@ -208,13 +208,13 @@ class WriteContext { } } - void FlushQueuedBuffers(grpc_exec_ctx *exec_ctx) { + void FlushQueuedBuffers(grpc_exec_ctx* exec_ctx) { /* simple writes are queued to qbuf, and flushed here */ grpc_slice_buffer_move_into(&t_->qbuf, &t_->outbuf); GPR_ASSERT(t_->qbuf.count == 0); } - void FlushWindowUpdates(grpc_exec_ctx *exec_ctx) { + void FlushWindowUpdates(grpc_exec_ctx* exec_ctx) { uint32_t transport_announce = t_->flow_control->MaybeSendUpdate(t_->outbuf.count > 0); if (transport_announce) { @@ -234,7 +234,7 @@ class WriteContext { t_->ping_ack_count = 0; } - void EnactHpackSettings(grpc_exec_ctx *exec_ctx) { + void EnactHpackSettings(grpc_exec_ctx* exec_ctx) { grpc_chttp2_hpack_compressor_set_max_table_size( &t_->hpack_compressor, t_->settings[GRPC_PEER_SETTINGS] @@ -242,7 +242,7 @@ class WriteContext { } void UpdateStreamsNoLongerStalled() { - grpc_chttp2_stream *s; + grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_stalled_by_transport(t_, &s)) { if (t_->closed_with_error == GRPC_ERROR_NONE && grpc_chttp2_list_add_writable_stream(t_, s)) { @@ -253,13 +253,13 @@ class WriteContext { } } - grpc_chttp2_stream *NextStream() { + grpc_chttp2_stream* NextStream() { if (t_->outbuf.length > target_write_size(t_)) { result_.partial = true; return nullptr; } - grpc_chttp2_stream *s; + grpc_chttp2_stream* s; if (!grpc_chttp2_list_pop_writable_stream(t_, &s)) { return nullptr; } @@ -281,7 +281,7 @@ class WriteContext { void NoteScheduledResults() { result_.early_results_scheduled = true; } - grpc_chttp2_transport *transport() const { return t_; } + grpc_chttp2_transport* transport() const { return t_; } grpc_chttp2_begin_write_result Result() { result_.writing = t_->outbuf.count > 0; @@ -289,7 +289,7 @@ class WriteContext { } private: - grpc_chttp2_transport *const t_; + grpc_chttp2_transport* const t_; /* stats histogram counters: we increment these throughout this function, and at the end publish to the central stats histograms */ @@ -302,8 +302,8 @@ class WriteContext { class DataSendContext { public: - DataSendContext(WriteContext *write_context, grpc_chttp2_transport *t, - grpc_chttp2_stream *s) + DataSendContext(WriteContext* write_context, grpc_chttp2_transport* t, + grpc_chttp2_stream* s) : write_context_(write_context), t_(t), s_(s), @@ -373,7 +373,7 @@ class DataSendContext { bool is_last_frame() const { return is_last_frame_; } - void CallCallbacks(grpc_exec_ctx *exec_ctx) { + void CallCallbacks(grpc_exec_ctx* exec_ctx) { if (update_list(exec_ctx, t_, s_, (int64_t)(s_->sending_bytes - sending_bytes_before_), &s_->on_flow_controlled_cbs, @@ -383,16 +383,16 @@ class DataSendContext { } private: - WriteContext *write_context_; - grpc_chttp2_transport *t_; - grpc_chttp2_stream *s_; + WriteContext* write_context_; + grpc_chttp2_transport* t_; + grpc_chttp2_stream* s_; const size_t sending_bytes_before_; bool is_last_frame_ = false; }; class StreamWriteContext { public: - StreamWriteContext(WriteContext *write_context, grpc_chttp2_stream *s) + StreamWriteContext(WriteContext* write_context, grpc_chttp2_stream* s) : write_context_(write_context), t_(write_context->transport()), s_(s) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_DEBUG, "W:%p %s[%d] im-(sent,send)=(%d,%d) announce=%d", t_, @@ -402,7 +402,7 @@ class StreamWriteContext { s->flow_control->announced_window_delta()))); } - void FlushInitialMetadata(grpc_exec_ctx *exec_ctx) { + void FlushInitialMetadata(grpc_exec_ctx* exec_ctx) { /* send initial metadata if it's available */ if (s_->sent_initial_metadata) return; if (s_->send_initial_metadata == nullptr) return; @@ -443,7 +443,7 @@ class StreamWriteContext { "send_initial_metadata_finished"); } - void FlushWindowUpdates(grpc_exec_ctx *exec_ctx) { + void FlushWindowUpdates(grpc_exec_ctx* exec_ctx) { /* send any window updates */ const uint32_t stream_announce = s_->flow_control->MaybeSendUpdate(); if (stream_announce == 0) return; @@ -455,7 +455,7 @@ class StreamWriteContext { write_context_->IncWindowUpdateWrites(); } - void FlushData(grpc_exec_ctx *exec_ctx) { + void FlushData(grpc_exec_ctx* exec_ctx) { if (!s_->sent_initial_metadata) return; if (s_->flow_controlled_buffer.length == 0 && @@ -499,7 +499,7 @@ class StreamWriteContext { write_context_->IncMessageWrites(); } - void FlushTrailingMetadata(grpc_exec_ctx *exec_ctx) { + void FlushTrailingMetadata(grpc_exec_ctx* exec_ctx) { if (!s_->sent_initial_metadata) return; if (s_->send_trailing_metadata == NULL) return; @@ -555,7 +555,7 @@ class StreamWriteContext { } } - void SentLastFrame(grpc_exec_ctx *exec_ctx) { + void SentLastFrame(grpc_exec_ctx* exec_ctx) { s_->send_trailing_metadata = NULL; s_->sent_trailing_metadata = true; @@ -568,17 +568,17 @@ class StreamWriteContext { GRPC_ERROR_NONE); } - WriteContext *const write_context_; - grpc_chttp2_transport *const t_; - grpc_chttp2_stream *const s_; + WriteContext* const write_context_; + grpc_chttp2_transport* const t_; + grpc_chttp2_stream* const s_; bool stream_became_writable_ = false; - grpc_mdelem *extra_headers_for_trailing_metadata_[2]; + grpc_mdelem* extra_headers_for_trailing_metadata_[2]; size_t num_extra_headers_for_trailing_metadata_ = 0; }; } // namespace grpc_chttp2_begin_write_result grpc_chttp2_begin_write( - grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) { + grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t) { WriteContext ctx(exec_ctx, t); ctx.FlushSettings(exec_ctx); ctx.FlushPingAcks(); @@ -591,7 +591,7 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write( /* for each grpc_chttp2_stream that's become writable, frame it's data (according to available window sizes) and add to the output buffer */ - while (grpc_chttp2_stream *s = ctx.NextStream()) { + while (grpc_chttp2_stream* s = ctx.NextStream()) { StreamWriteContext stream_ctx(&ctx, s); stream_ctx.FlushInitialMetadata(exec_ctx); stream_ctx.FlushWindowUpdates(exec_ctx); @@ -619,10 +619,10 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write( return ctx.Result(); } -void grpc_chttp2_end_write(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_error *error) { +void grpc_chttp2_end_write(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, + grpc_error* error) { GPR_TIMER_BEGIN("grpc_chttp2_end_write", 0); - grpc_chttp2_stream *s; + grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_writing_stream(t, &s)) { if (s->sending_bytes != 0) { diff --git a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc index b280487ca3..d590ba0371 100644 --- a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc +++ b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc @@ -33,20 +33,20 @@ // Cronet transport object typedef struct cronet_transport { grpc_transport base; // must be first element in this structure - void *engine; - char *host; + void* engine; + char* host; } cronet_transport; extern grpc_transport_vtable grpc_cronet_vtable; -GRPCAPI grpc_channel *grpc_cronet_secure_channel_create( - void *engine, const char *target, const grpc_channel_args *args, - void *reserved) { +GRPCAPI grpc_channel* grpc_cronet_secure_channel_create( + void* engine, const char* target, const grpc_channel_args* args, + void* reserved) { gpr_log(GPR_DEBUG, "grpc_create_cronet_transport: stream_engine = %p, target=%s", engine, target); - grpc_transport *ct = + grpc_transport* ct = grpc_create_cronet_transport(engine, target, args, reserved); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.cc b/src/core/ext/transport/cronet/transport/cronet_transport.cc index 97e4f7d72b..0b1ddf8839 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.cc +++ b/src/core/ext/transport/cronet/transport/cronet_transport.cc @@ -75,17 +75,17 @@ enum e_op_id { /* Cronet callbacks. See cronet_c_for_grpc.h for documentation for each. */ -static void on_stream_ready(bidirectional_stream *); +static void on_stream_ready(bidirectional_stream*); static void on_response_headers_received( - bidirectional_stream *, const bidirectional_stream_header_array *, - const char *); -static void on_write_completed(bidirectional_stream *, const char *); -static void on_read_completed(bidirectional_stream *, char *, int); + bidirectional_stream*, const bidirectional_stream_header_array*, + const char*); +static void on_write_completed(bidirectional_stream*, const char*); +static void on_read_completed(bidirectional_stream*, char*, int); static void on_response_trailers_received( - bidirectional_stream *, const bidirectional_stream_header_array *); -static void on_succeeded(bidirectional_stream *); -static void on_failed(bidirectional_stream *, int); -static void on_canceled(bidirectional_stream *); + bidirectional_stream*, const bidirectional_stream_header_array*); +static void on_succeeded(bidirectional_stream*); +static void on_failed(bidirectional_stream*, int); +static void on_canceled(bidirectional_stream*); static bidirectional_stream_callback cronet_callbacks = { on_stream_ready, on_response_headers_received, @@ -99,8 +99,8 @@ static bidirectional_stream_callback cronet_callbacks = { /* Cronet transport object */ struct grpc_cronet_transport { grpc_transport base; /* must be first element in this structure */ - stream_engine *engine; - char *host; + stream_engine* engine; + char* host; bool use_packet_coalescing; }; typedef struct grpc_cronet_transport grpc_cronet_transport; @@ -109,14 +109,14 @@ typedef struct grpc_cronet_transport grpc_cronet_transport; http://www.catb.org/esr/structure-packing/#_structure_reordering: */ struct read_state { /* vars to store data coming from server */ - char *read_buffer; + char* read_buffer; bool length_field_received; int received_bytes; int remaining_bytes; int length_field; bool compressed; char grpc_header_bytes[GRPC_HEADER_SIZE_IN_BYTES]; - char *payload_field; + char* payload_field; bool read_stream_closed; /* vars for holding data destined for the application */ @@ -132,7 +132,7 @@ struct read_state { }; struct write_state { - char *write_buffer; + char* write_buffer; }; /* track state of one stream op */ @@ -150,7 +150,7 @@ struct op_state { bool pending_recv_trailing_metadata; /* Cronet has not issued a callback of a bidirectional read */ bool pending_read_from_cronet; - grpc_error *cancel_error; + grpc_error* cancel_error; /* data structure for storing data coming from server */ struct read_state rs; /* data structure for storing data going to the server */ @@ -161,22 +161,22 @@ struct op_and_state { grpc_transport_stream_op_batch op; struct op_state state; bool done; - struct stream_obj *s; /* Pointer back to the stream object */ - struct op_and_state *next; /* next op_and_state in the linked list */ + struct stream_obj* s; /* Pointer back to the stream object */ + struct op_and_state* next; /* next op_and_state in the linked list */ }; struct op_storage { int num_pending_ops; - struct op_and_state *head; + struct op_and_state* head; }; struct stream_obj { - gpr_arena *arena; - struct op_and_state *oas; - grpc_transport_stream_op_batch *curr_op; - grpc_cronet_transport *curr_ct; - grpc_stream *curr_gs; - bidirectional_stream *cbs; + gpr_arena* arena; + struct op_and_state* oas; + grpc_transport_stream_op_batch* curr_op; + grpc_cronet_transport* curr_ct; + grpc_stream* curr_gs; + bidirectional_stream* cbs; bidirectional_stream_header_array header_array; /* Stream level state. Some state will be tracked both at stream and stream_op @@ -190,7 +190,7 @@ struct stream_obj { gpr_mu mu; /* Refcount object of the stream */ - grpc_stream_refcount *refcount; + grpc_stream_refcount* refcount; }; typedef struct stream_obj stream_obj; @@ -199,30 +199,30 @@ typedef struct stream_obj stream_obj; grpc_cronet_stream_ref((stream), (reason)) #define GRPC_CRONET_STREAM_UNREF(exec_ctx, stream, reason) \ grpc_cronet_stream_unref((exec_ctx), (stream), (reason)) -void grpc_cronet_stream_ref(stream_obj *s, const char *reason) { +void grpc_cronet_stream_ref(stream_obj* s, const char* reason) { grpc_stream_ref(s->refcount, reason); } -void grpc_cronet_stream_unref(grpc_exec_ctx *exec_ctx, stream_obj *s, - const char *reason) { +void grpc_cronet_stream_unref(grpc_exec_ctx* exec_ctx, stream_obj* s, + const char* reason) { grpc_stream_unref(exec_ctx, s->refcount, reason); } #else #define GRPC_CRONET_STREAM_REF(stream, reason) grpc_cronet_stream_ref((stream)) #define GRPC_CRONET_STREAM_UNREF(exec_ctx, stream, reason) \ grpc_cronet_stream_unref((exec_ctx), (stream)) -void grpc_cronet_stream_ref(stream_obj *s) { grpc_stream_ref(s->refcount); } -void grpc_cronet_stream_unref(grpc_exec_ctx *exec_ctx, stream_obj *s) { +void grpc_cronet_stream_ref(stream_obj* s) { grpc_stream_ref(s->refcount); } +void grpc_cronet_stream_unref(grpc_exec_ctx* exec_ctx, stream_obj* s) { grpc_stream_unref(exec_ctx, s->refcount); } #endif -static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, - struct op_and_state *oas); +static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, + struct op_and_state* oas); /* Utility function to translate enum into string for printing */ -static const char *op_result_string(enum e_op_result i) { +static const char* op_result_string(enum e_op_result i) { switch (i) { case ACTION_TAKEN_WITH_CALLBACK: return "ACTION_TAKEN_WITH_CALLBACK"; @@ -234,7 +234,7 @@ static const char *op_result_string(enum e_op_result i) { GPR_UNREACHABLE_CODE(return "UNKNOWN"); } -static const char *op_id_string(enum e_op_id i) { +static const char* op_id_string(enum e_op_id i) { switch (i) { case OP_SEND_INITIAL_METADATA: return "OP_SEND_INITIAL_METADATA"; @@ -268,7 +268,7 @@ static const char *op_id_string(enum e_op_id i) { return "UNKNOWN"; } -static void null_and_maybe_free_read_buffer(stream_obj *s) { +static void null_and_maybe_free_read_buffer(stream_obj* s) { if (s->state.rs.read_buffer && s->state.rs.read_buffer != s->state.rs.grpc_header_bytes) { gpr_free(s->state.rs.read_buffer); @@ -276,7 +276,7 @@ static void null_and_maybe_free_read_buffer(stream_obj *s) { s->state.rs.read_buffer = NULL; } -static void maybe_flush_read(stream_obj *s) { +static void maybe_flush_read(stream_obj* s) { /* To enter flush read state (discarding all the buffered messages in * transport layer), two conditions must be satisfied: 1) non-zero grpc status * has been received, and 2) an op requesting the status code @@ -289,7 +289,7 @@ 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 = (char *)gpr_malloc(GRPC_FLUSH_READ_SIZE); + s->state.rs.read_buffer = (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, @@ -300,8 +300,8 @@ static void maybe_flush_read(stream_obj *s) { } } -static grpc_error *make_error_with_desc(int error_code, const char *desc) { - grpc_error *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc); +static grpc_error* make_error_with_desc(int error_code, const char* desc) { + grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc); error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, error_code); return error; } @@ -309,13 +309,13 @@ static grpc_error *make_error_with_desc(int error_code, const char *desc) { /* Add a new stream op to op storage. */ -static void add_to_storage(struct stream_obj *s, - grpc_transport_stream_op_batch *op) { - struct op_storage *storage = &s->storage; +static void add_to_storage(struct stream_obj* s, + grpc_transport_stream_op_batch* op) { + 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 = - (struct op_and_state *)gpr_malloc(sizeof(struct op_and_state)); + struct op_and_state* new_op = + (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; @@ -339,9 +339,9 @@ static void add_to_storage(struct stream_obj *s, /* Traverse the linked list and delete op and free memory */ -static void remove_from_storage(struct stream_obj *s, - struct op_and_state *oas) { - struct op_and_state *curr; +static void remove_from_storage(struct stream_obj* s, + struct op_and_state* oas) { + struct op_and_state* curr; if (s->storage.head == NULL || oas == NULL) { return; } @@ -373,9 +373,9 @@ static void remove_from_storage(struct stream_obj *s, This can get executed from the Cronet network thread via cronet callback or on the application supplied thread via the perform_stream_op function. */ -static void execute_from_storage(grpc_exec_ctx *exec_ctx, stream_obj *s) { +static void execute_from_storage(grpc_exec_ctx* exec_ctx, stream_obj* s) { gpr_mu_lock(&s->mu); - for (struct op_and_state *curr = s->storage.head; curr != NULL;) { + for (struct op_and_state* curr = s->storage.head; curr != NULL;) { CRONET_LOG(GPR_DEBUG, "calling op at %p. done = %d", curr, curr->done); GPR_ASSERT(curr->done == 0); enum e_op_result result = execute_stream_op(exec_ctx, curr); @@ -383,7 +383,7 @@ static void execute_from_storage(grpc_exec_ctx *exec_ctx, stream_obj *s) { op_result_string(result)); /* if this op is done, then remove it and free memory */ if (curr->done) { - struct op_and_state *next = curr->next; + struct op_and_state* next = curr->next; remove_from_storage(s, curr); curr = next; } @@ -400,11 +400,11 @@ static void execute_from_storage(grpc_exec_ctx *exec_ctx, stream_obj *s) { /* Cronet callback */ -static void on_failed(bidirectional_stream *stream, int net_error) { +static void on_failed(bidirectional_stream* stream, int net_error) { CRONET_LOG(GPR_DEBUG, "on_failed(%p, %d)", stream, net_error); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - stream_obj *s = (stream_obj *)stream->annotation; + stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_FAILED] = true; @@ -427,11 +427,11 @@ static void on_failed(bidirectional_stream *stream, int net_error) { /* Cronet callback */ -static void on_canceled(bidirectional_stream *stream) { +static void on_canceled(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_canceled(%p)", stream); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - stream_obj *s = (stream_obj *)stream->annotation; + stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_CANCELED] = true; @@ -454,11 +454,11 @@ static void on_canceled(bidirectional_stream *stream) { /* Cronet callback */ -static void on_succeeded(bidirectional_stream *stream) { +static void on_succeeded(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "on_succeeded(%p)", stream); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - stream_obj *s = (stream_obj *)stream->annotation; + stream_obj* s = (stream_obj*)stream->annotation; gpr_mu_lock(&s->mu); bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_SUCCEEDED] = true; @@ -473,11 +473,11 @@ static void on_succeeded(bidirectional_stream *stream) { /* Cronet callback */ -static void on_stream_ready(bidirectional_stream *stream) { +static void on_stream_ready(bidirectional_stream* stream) { CRONET_LOG(GPR_DEBUG, "W: on_stream_ready(%p)", stream); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - stream_obj *s = (stream_obj *)stream->annotation; - grpc_cronet_transport *t = (grpc_cronet_transport *)s->curr_ct; + stream_obj* s = (stream_obj*)stream->annotation; + grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; gpr_mu_lock(&s->mu); s->state.state_op_done[OP_SEND_INITIAL_METADATA] = true; s->state.state_callback_received[OP_SEND_INITIAL_METADATA] = true; @@ -503,13 +503,13 @@ static void on_stream_ready(bidirectional_stream *stream) { Cronet callback */ static void on_response_headers_received( - bidirectional_stream *stream, - const bidirectional_stream_header_array *headers, - const char *negotiated_protocol) { + bidirectional_stream* stream, + const bidirectional_stream_header_array* headers, + const char* negotiated_protocol) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; CRONET_LOG(GPR_DEBUG, "R: on_response_headers_received(%p, %p, %s)", stream, headers, negotiated_protocol); - stream_obj *s = (stream_obj *)stream->annotation; + stream_obj* s = (stream_obj*)stream->annotation; /* Identify if this is a header or a trailer (in a trailer-only response case) */ @@ -526,15 +526,15 @@ static void on_response_headers_received( grpc_chttp2_incoming_metadata_buffer_init(&s->state.rs.initial_metadata, s->arena); for (size_t i = 0; i < headers->count; i++) { - GRPC_LOG_IF_ERROR( - "on_response_headers_received", - grpc_chttp2_incoming_metadata_buffer_add( - &exec_ctx, &s->state.rs.initial_metadata, - grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string( - headers->headers[i].key)), - grpc_slice_intern(grpc_slice_from_static_string( - headers->headers[i].value))))); + GRPC_LOG_IF_ERROR("on_response_headers_received", + grpc_chttp2_incoming_metadata_buffer_add( + &exec_ctx, &s->state.rs.initial_metadata, + grpc_mdelem_from_slices( + &exec_ctx, + grpc_slice_intern(grpc_slice_from_static_string( + headers->headers[i].key)), + grpc_slice_intern(grpc_slice_from_static_string( + headers->headers[i].value))))); } s->state.state_callback_received[OP_RECV_INITIAL_METADATA] = true; if (!(s->state.state_op_done[OP_CANCEL_ERROR] || @@ -559,9 +559,9 @@ static void on_response_headers_received( /* Cronet callback */ -static void on_write_completed(bidirectional_stream *stream, const char *data) { +static void on_write_completed(bidirectional_stream* stream, const char* data) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - stream_obj *s = (stream_obj *)stream->annotation; + stream_obj* s = (stream_obj*)stream->annotation; CRONET_LOG(GPR_DEBUG, "W: on_write_completed(%p, %s)", stream, data); gpr_mu_lock(&s->mu); if (s->state.ws.write_buffer) { @@ -577,10 +577,10 @@ static void on_write_completed(bidirectional_stream *stream, const char *data) { /* Cronet callback */ -static void on_read_completed(bidirectional_stream *stream, char *data, +static void on_read_completed(bidirectional_stream* stream, char* data, int count) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - stream_obj *s = (stream_obj *)stream->annotation; + stream_obj* s = (stream_obj*)stream->annotation; CRONET_LOG(GPR_DEBUG, "R: on_read_completed(%p, %p, %d)", stream, data, count); gpr_mu_lock(&s->mu); @@ -620,13 +620,13 @@ static void on_read_completed(bidirectional_stream *stream, char *data, Cronet callback */ static void on_response_trailers_received( - bidirectional_stream *stream, - const bidirectional_stream_header_array *trailers) { + bidirectional_stream* stream, + const bidirectional_stream_header_array* trailers) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; CRONET_LOG(GPR_DEBUG, "R: on_response_trailers_received(%p,%p)", stream, trailers); - stream_obj *s = (stream_obj *)stream->annotation; - grpc_cronet_transport *t = (grpc_cronet_transport *)s->curr_ct; + stream_obj* s = (stream_obj*)stream->annotation; + grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; gpr_mu_lock(&s->mu); memset(&s->state.rs.trailing_metadata, 0, sizeof(s->state.rs.trailing_metadata)); @@ -636,15 +636,15 @@ static void on_response_trailers_received( for (size_t i = 0; i < trailers->count; i++) { CRONET_LOG(GPR_DEBUG, "trailer key=%s, value=%s", trailers->headers[i].key, trailers->headers[i].value); - GRPC_LOG_IF_ERROR( - "on_response_trailers_received", - grpc_chttp2_incoming_metadata_buffer_add( - &exec_ctx, &s->state.rs.trailing_metadata, - grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string( - trailers->headers[i].key)), - grpc_slice_intern(grpc_slice_from_static_string( - trailers->headers[i].value))))); + GRPC_LOG_IF_ERROR("on_response_trailers_received", + grpc_chttp2_incoming_metadata_buffer_add( + &exec_ctx, &s->state.rs.trailing_metadata, + grpc_mdelem_from_slices( + &exec_ctx, + grpc_slice_intern(grpc_slice_from_static_string( + trailers->headers[i].key)), + grpc_slice_intern(grpc_slice_from_static_string( + trailers->headers[i].value))))); s->state.rs.trailing_metadata_valid = true; if (0 == strcmp(trailers->headers[i].key, "grpc-status") && 0 != strcmp(trailers->headers[i].value, "0")) { @@ -679,17 +679,17 @@ static void on_response_trailers_received( Utility function that takes the data from s->write_slice_buffer and assembles into a contiguous byte stream with 5 byte gRPC header prepended. */ -static void create_grpc_frame(grpc_exec_ctx *exec_ctx, - grpc_slice_buffer *write_slice_buffer, - char **pp_write_buffer, - size_t *p_write_buffer_size, uint32_t flags) { +static void create_grpc_frame(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* write_slice_buffer, + char** pp_write_buffer, + size_t* p_write_buffer_size, uint32_t flags) { grpc_slice slice = grpc_slice_buffer_take_first(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 = (char *)gpr_malloc(length + GRPC_HEADER_SIZE_IN_BYTES); + char* write_buffer = (char*)gpr_malloc(length + GRPC_HEADER_SIZE_IN_BYTES); *pp_write_buffer = write_buffer; - uint8_t *p = (uint8_t *)write_buffer; + uint8_t* p = (uint8_t*)write_buffer; /* Append 5 byte header */ /* Compressed flag */ *p++ = (uint8_t)((flags & GRPC_WRITE_INTERNAL_COMPRESS) ? 1 : 0); @@ -707,10 +707,10 @@ static void create_grpc_frame(grpc_exec_ctx *exec_ctx, Convert metadata in a format that Cronet can consume */ static void convert_metadata_to_cronet_headers( - grpc_linked_mdelem *head, const char *host, char **pp_url, - bidirectional_stream_header **pp_headers, size_t *p_num_headers, - const char **method) { - grpc_linked_mdelem *curr = head; + grpc_linked_mdelem* head, const char* host, char** pp_url, + bidirectional_stream_header** pp_headers, size_t* p_num_headers, + const char** method) { + grpc_linked_mdelem* curr = head; /* Walk the linked list and get number of header fields */ size_t num_headers_available = 0; while (curr != NULL) { @@ -719,8 +719,8 @@ static void convert_metadata_to_cronet_headers( } /* Allocate enough memory. It is freed in the on_stream_ready callback */ - bidirectional_stream_header *headers = - (bidirectional_stream_header *)gpr_malloc( + bidirectional_stream_header* headers = + (bidirectional_stream_header*)gpr_malloc( sizeof(bidirectional_stream_header) * num_headers_available); *pp_headers = headers; @@ -734,8 +734,8 @@ static void convert_metadata_to_cronet_headers( while (num_headers < num_headers_available) { grpc_mdelem mdelem = curr->md; curr = curr->next; - char *key = grpc_slice_to_c_string(GRPC_MDKEY(mdelem)); - char *value = grpc_slice_to_c_string(GRPC_MDVALUE(mdelem)); + char* key = grpc_slice_to_c_string(GRPC_MDKEY(mdelem)); + char* value = grpc_slice_to_c_string(GRPC_MDVALUE(mdelem)); if (grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_SCHEME) || grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_AUTHORITY)) { /* Cronet populates these fields on its own */ @@ -772,10 +772,10 @@ static void convert_metadata_to_cronet_headers( *p_num_headers = (size_t)num_headers; } -static void parse_grpc_header(const uint8_t *data, int *length, - bool *compressed) { +static void parse_grpc_header(const uint8_t* data, int* length, + bool* compressed) { const uint8_t c = *data; - const uint8_t *p = data + 1; + const uint8_t* p = data + 1; *compressed = ((c & 0x01) == 0x01); *length = 0; *length |= ((uint8_t)*p++) << 24; @@ -784,7 +784,7 @@ static void parse_grpc_header(const uint8_t *data, int *length, *length |= ((uint8_t)*p++); } -static bool header_has_authority(grpc_linked_mdelem *head) { +static bool header_has_authority(grpc_linked_mdelem* head) { while (head != NULL) { if (grpc_slice_eq(GRPC_MDKEY(head->md), GRPC_MDSTR_AUTHORITY)) { return true; @@ -798,11 +798,11 @@ static bool header_has_authority(grpc_linked_mdelem *head) { Op Execution: Decide if one of the actions contained in the stream op can be executed. This is the heart of the state machine. */ -static bool op_can_be_run(grpc_transport_stream_op_batch *curr_op, - struct stream_obj *s, struct op_state *op_state, +static bool op_can_be_run(grpc_transport_stream_op_batch* curr_op, + struct stream_obj* s, struct op_state* op_state, enum e_op_id op_id) { - struct op_state *stream_state = &s->state; - grpc_cronet_transport *t = s->curr_ct; + struct op_state* stream_state = &s->state; + grpc_cronet_transport* t = s->curr_ct; bool result = true; /* When call is canceled, every op can be run, except under following conditions @@ -981,12 +981,12 @@ static bool op_can_be_run(grpc_transport_stream_op_batch *curr_op, /* TODO (makdharma): Break down this function in smaller chunks for readability. */ -static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, - struct op_and_state *oas) { - grpc_transport_stream_op_batch *stream_op = &oas->op; - struct stream_obj *s = oas->s; - grpc_cronet_transport *t = (grpc_cronet_transport *)s->curr_ct; - struct op_state *stream_state = &s->state; +static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, + struct op_and_state* oas) { + grpc_transport_stream_op_batch* stream_op = &oas->op; + struct stream_obj* s = oas->s; + grpc_cronet_transport* t = (grpc_cronet_transport*)s->curr_ct; + struct op_state* stream_state = &s->state; enum e_op_result result = NO_ACTION_POSSIBLE; if (stream_op->send_initial_metadata && op_can_be_run(stream_op, s, &oas->state, OP_SEND_INITIAL_METADATA)) { @@ -1002,8 +1002,8 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, bidirectional_stream_disable_auto_flush(s->cbs, true); bidirectional_stream_delay_request_headers_until_flush(s->cbs, true); } - char *url = NULL; - const char *method = "POST"; + char* url = NULL; + const char* method = "POST"; s->header_array.headers = NULL; convert_metadata_to_cronet_headers(stream_op->payload->send_initial_metadata .send_initial_metadata->list.head, @@ -1018,8 +1018,8 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, unsigned int header_index; for (header_index = 0; header_index < s->header_array.count; header_index++) { - gpr_free((void *)s->header_array.headers[header_index].key); - gpr_free((void *)s->header_array.headers[header_index].value); + gpr_free((void*)s->header_array.headers[header_index].key); + gpr_free((void*)s->header_array.headers[header_index].value); } stream_state->state_op_done[OP_SEND_INITIAL_METADATA] = true; if (t->use_packet_coalescing) { @@ -1177,14 +1177,14 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, stream_state->rs.remaining_bytes == 0) { /* Start a read operation for data */ stream_state->rs.length_field_received = true; - parse_grpc_header((const uint8_t *)stream_state->rs.read_buffer, + parse_grpc_header((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 = - (char *)gpr_malloc((size_t)stream_state->rs.length_field); + (char*)gpr_malloc((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; @@ -1207,9 +1207,8 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, if (stream_state->rs.compressed) { stream_state->rs.sbs.base.flags |= GRPC_WRITE_INTERNAL_COMPRESS; } - *((grpc_byte_buffer **) - stream_op->payload->recv_message.recv_message) = - (grpc_byte_buffer *)&stream_state->rs.sbs; + *((grpc_byte_buffer**)stream_op->payload->recv_message.recv_message) = + (grpc_byte_buffer*)&stream_state->rs.sbs; GRPC_CLOSURE_SCHED( exec_ctx, stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); @@ -1250,7 +1249,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, CRONET_LOG(GPR_DEBUG, "read operation complete"); grpc_slice read_data_slice = GRPC_SLICE_MALLOC((uint32_t)stream_state->rs.length_field); - uint8_t *dst_p = GRPC_SLICE_START_PTR(read_data_slice); + uint8_t* dst_p = GRPC_SLICE_START_PTR(read_data_slice); memcpy(dst_p, stream_state->rs.read_buffer, (size_t)stream_state->rs.length_field); null_and_maybe_free_read_buffer(s); @@ -1265,8 +1264,8 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, if (stream_state->rs.compressed) { stream_state->rs.sbs.base.flags = GRPC_WRITE_INTERNAL_COMPRESS; } - *((grpc_byte_buffer **)stream_op->payload->recv_message.recv_message) = - (grpc_byte_buffer *)&stream_state->rs.sbs; + *((grpc_byte_buffer**)stream_op->payload->recv_message.recv_message) = + (grpc_byte_buffer*)&stream_state->rs.sbs; GRPC_CLOSURE_SCHED(exec_ctx, stream_op->payload->recv_message.recv_message_ready, GRPC_ERROR_NONE); @@ -1351,10 +1350,10 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, Functions used by upper layers to access transport functionality. */ -static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, grpc_stream_refcount *refcount, - const void *server_data, gpr_arena *arena) { - stream_obj *s = (stream_obj *)gs; +static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_stream_refcount* refcount, + const void* server_data, gpr_arena* arena) { + stream_obj* s = (stream_obj*)gs; s->refcount = refcount; GRPC_CRONET_STREAM_REF(s, "cronet transport"); @@ -1377,23 +1376,23 @@ static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, s->state.pending_read_from_cronet = false; s->curr_gs = gs; - s->curr_ct = (grpc_cronet_transport *)gt; + s->curr_ct = (grpc_cronet_transport*)gt; s->arena = arena; gpr_mu_init(&s->mu); return 0; } -static void set_pollset_do_nothing(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, grpc_pollset *pollset) {} +static void set_pollset_do_nothing(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_pollset* pollset) {} -static void set_pollset_set_do_nothing(grpc_exec_ctx *exec_ctx, - grpc_transport *gt, grpc_stream *gs, - grpc_pollset_set *pollset_set) {} +static void set_pollset_set_do_nothing(grpc_exec_ctx* exec_ctx, + grpc_transport* gt, grpc_stream* gs, + grpc_pollset_set* pollset_set) {} -static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, - grpc_transport_stream_op_batch *op) { +static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, + grpc_transport_stream_op_batch* op) { CRONET_LOG(GPR_DEBUG, "perform_stream_op"); if (op->send_initial_metadata && header_has_authority(op->payload->send_initial_metadata @@ -1413,15 +1412,15 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, GRPC_CLOSURE_SCHED(exec_ctx, op->on_complete, GRPC_ERROR_CANCELLED); return; } - stream_obj *s = (stream_obj *)gs; + stream_obj* s = (stream_obj*)gs; add_to_storage(s, op); execute_from_storage(exec_ctx, s); } -static void destroy_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, - grpc_closure *then_schedule_closure) { - stream_obj *s = (stream_obj *)gs; +static void destroy_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, + grpc_closure* then_schedule_closure) { + stream_obj* s = (stream_obj*)gs; null_and_maybe_free_read_buffer(s); /* Clean up read_slice_buffer in case there is unread data. */ grpc_slice_buffer_destroy_internal(exec_ctx, &s->state.rs.read_slice_buffer); @@ -1429,15 +1428,15 @@ static void destroy_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, GRPC_CLOSURE_SCHED(exec_ctx, then_schedule_closure, GRPC_ERROR_NONE); } -static void destroy_transport(grpc_exec_ctx *exec_ctx, grpc_transport *gt) {} +static void destroy_transport(grpc_exec_ctx* exec_ctx, grpc_transport* gt) {} -static grpc_endpoint *get_endpoint(grpc_exec_ctx *exec_ctx, - grpc_transport *gt) { +static grpc_endpoint* get_endpoint(grpc_exec_ctx* exec_ctx, + grpc_transport* gt) { return NULL; } -static void perform_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_transport_op *op) {} +static void perform_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_transport_op* op) {} static const grpc_transport_vtable grpc_cronet_vtable = { sizeof(stream_obj), @@ -1451,17 +1450,17 @@ static const grpc_transport_vtable grpc_cronet_vtable = { destroy_transport, get_endpoint}; -grpc_transport *grpc_create_cronet_transport(void *engine, const char *target, - const grpc_channel_args *args, - void *reserved) { - grpc_cronet_transport *ct = - (grpc_cronet_transport *)gpr_malloc(sizeof(grpc_cronet_transport)); +grpc_transport* grpc_create_cronet_transport(void* engine, const char* target, + const grpc_channel_args* args, + void* reserved) { + grpc_cronet_transport* ct = + (grpc_cronet_transport*)gpr_malloc(sizeof(grpc_cronet_transport)); if (!ct) { goto error; } ct->base.vtable = &grpc_cronet_vtable; - ct->engine = (stream_engine *)engine; - ct->host = (char *)gpr_malloc(strlen(target) + 1); + ct->engine = (stream_engine*)engine; + ct->host = (char*)gpr_malloc(strlen(target) + 1); if (!ct->host) { goto error; } diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.h b/src/core/ext/transport/cronet/transport/cronet_transport.h index 43ff391f79..7643fdb585 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.h +++ b/src/core/ext/transport/cronet/transport/cronet_transport.h @@ -25,9 +25,9 @@ extern "C" { #endif -grpc_transport *grpc_create_cronet_transport(void *engine, const char *target, - const grpc_channel_args *args, - void *reserved); +grpc_transport* grpc_create_cronet_transport(void* engine, const char* target, + const grpc_channel_args* args, + void* reserved); #ifdef __cplusplus } diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index 1551f5e988..a7a6db8bc2 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -50,20 +50,20 @@ typedef struct { typedef struct inproc_transport { grpc_transport base; - shared_mu *mu; + shared_mu* mu; gpr_refcount refs; bool is_client; grpc_connectivity_state_tracker connectivity; - void (*accept_stream_cb)(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_transport *transport, const void *server_data); - void *accept_stream_data; + void (*accept_stream_cb)(grpc_exec_ctx* exec_ctx, void* user_data, + grpc_transport* transport, const void* server_data); + void* accept_stream_data; bool is_closed; - struct inproc_transport *other_side; - struct inproc_stream *stream_list; + struct inproc_transport* other_side; + struct inproc_stream* stream_list; } inproc_transport; typedef struct inproc_stream { - inproc_transport *t; + inproc_transport* t; grpc_metadata_batch to_read_initial_md; uint32_t to_read_initial_md_flags; bool to_read_initial_md_filled; @@ -80,21 +80,21 @@ typedef struct inproc_stream { grpc_millis write_buffer_deadline; grpc_metadata_batch write_buffer_trailing_md; bool write_buffer_trailing_md_filled; - grpc_error *write_buffer_cancel_error; + grpc_error* write_buffer_cancel_error; - struct inproc_stream *other_side; + struct inproc_stream* other_side; bool other_side_closed; // won't talk anymore bool write_buffer_other_side_closed; // on hold - grpc_stream_refcount *refs; - grpc_closure *closure_at_destroy; + grpc_stream_refcount* refs; + grpc_closure* closure_at_destroy; - gpr_arena *arena; + gpr_arena* arena; - grpc_transport_stream_op_batch *send_message_op; - grpc_transport_stream_op_batch *send_trailing_md_op; - grpc_transport_stream_op_batch *recv_initial_md_op; - grpc_transport_stream_op_batch *recv_message_op; - grpc_transport_stream_op_batch *recv_trailing_md_op; + grpc_transport_stream_op_batch* send_message_op; + grpc_transport_stream_op_batch* send_trailing_md_op; + grpc_transport_stream_op_batch* recv_initial_md_op; + grpc_transport_stream_op_batch* recv_message_op; + grpc_transport_stream_op_batch* recv_trailing_md_op; grpc_slice_buffer recv_message; grpc_slice_buffer_stream recv_stream; @@ -107,29 +107,29 @@ typedef struct inproc_stream { bool closed; - grpc_error *cancel_self_error; - grpc_error *cancel_other_error; + grpc_error* cancel_self_error; + grpc_error* cancel_other_error; grpc_millis deadline; bool listed; - struct inproc_stream *stream_list_prev; - struct inproc_stream *stream_list_next; + struct inproc_stream* stream_list_prev; + struct inproc_stream* stream_list_next; } inproc_stream; static grpc_closure do_nothing_closure; -static bool cancel_stream_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s, - grpc_error *error); -static void op_state_machine(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error); +static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, + grpc_error* error); +static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error); -static void ref_transport(inproc_transport *t) { +static void ref_transport(inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "ref_transport %p", t); gpr_ref(&t->refs); } -static void really_destroy_transport(grpc_exec_ctx *exec_ctx, - inproc_transport *t) { +static void really_destroy_transport(grpc_exec_ctx* exec_ctx, + inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "really_destroy_transport %p", t); grpc_connectivity_state_destroy(exec_ctx, &t->connectivity); if (gpr_unref(&t->mu->refs)) { @@ -138,7 +138,7 @@ static void really_destroy_transport(grpc_exec_ctx *exec_ctx, gpr_free(t); } -static void unref_transport(grpc_exec_ctx *exec_ctx, inproc_transport *t) { +static void unref_transport(grpc_exec_ctx* exec_ctx, inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "unref_transport %p", t); if (gpr_unref(&t->refs)) { really_destroy_transport(exec_ctx, t); @@ -153,18 +153,18 @@ static void unref_transport(grpc_exec_ctx *exec_ctx, inproc_transport *t) { #define STREAM_UNREF(e, refs, reason) grpc_stream_unref(e, refs) #endif -static void ref_stream(inproc_stream *s, const char *reason) { +static void ref_stream(inproc_stream* s, const char* reason) { INPROC_LOG(GPR_DEBUG, "ref_stream %p %s", s, reason); STREAM_REF(s->refs, reason); } -static void unref_stream(grpc_exec_ctx *exec_ctx, inproc_stream *s, - const char *reason) { +static void unref_stream(grpc_exec_ctx* exec_ctx, inproc_stream* s, + const char* reason) { INPROC_LOG(GPR_DEBUG, "unref_stream %p %s", s, reason); STREAM_UNREF(exec_ctx, s->refs, reason); } -static void really_destroy_stream(grpc_exec_ctx *exec_ctx, inproc_stream *s) { +static void really_destroy_stream(grpc_exec_ctx* exec_ctx, inproc_stream* s) { INPROC_LOG(GPR_DEBUG, "really_destroy_stream %p", s); GRPC_ERROR_UNREF(s->write_buffer_cancel_error); @@ -182,12 +182,12 @@ static void really_destroy_stream(grpc_exec_ctx *exec_ctx, inproc_stream *s) { } } -static void log_metadata(const grpc_metadata_batch *md_batch, bool is_client, +static void log_metadata(const grpc_metadata_batch* md_batch, bool is_client, bool is_initial) { - for (grpc_linked_mdelem *md = md_batch->list.head; md != NULL; + for (grpc_linked_mdelem* md = md_batch->list.head; md != NULL; md = md->next) { - char *key = grpc_slice_to_c_string(GRPC_MDKEY(md->md)); - char *value = grpc_slice_to_c_string(GRPC_MDVALUE(md->md)); + char* key = grpc_slice_to_c_string(GRPC_MDKEY(md->md)); + char* value = grpc_slice_to_c_string(GRPC_MDVALUE(md->md)); gpr_log(GPR_INFO, "INPROC:%s:%s: %s: %s", is_initial ? "HDR" : "TRL", is_client ? "CLI" : "SVR", key, value); gpr_free(key); @@ -195,10 +195,10 @@ static void log_metadata(const grpc_metadata_batch *md_batch, bool is_client, } } -static grpc_error *fill_in_metadata(grpc_exec_ctx *exec_ctx, inproc_stream *s, - const grpc_metadata_batch *metadata, - uint32_t flags, grpc_metadata_batch *out_md, - uint32_t *outflags, bool *markfilled) { +static grpc_error* fill_in_metadata(grpc_exec_ctx* exec_ctx, inproc_stream* s, + const grpc_metadata_batch* metadata, + uint32_t flags, grpc_metadata_batch* out_md, + uint32_t* outflags, bool* markfilled) { if (GRPC_TRACER_ON(grpc_inproc_trace)) { log_metadata(metadata, s->t->is_client, outflags != NULL); } @@ -209,11 +209,11 @@ static grpc_error *fill_in_metadata(grpc_exec_ctx *exec_ctx, inproc_stream *s, if (markfilled != NULL) { *markfilled = true; } - grpc_error *error = GRPC_ERROR_NONE; - for (grpc_linked_mdelem *elem = metadata->list.head; + grpc_error* error = GRPC_ERROR_NONE; + for (grpc_linked_mdelem* elem = metadata->list.head; (elem != NULL) && (error == GRPC_ERROR_NONE); elem = elem->next) { - grpc_linked_mdelem *nelem = - (grpc_linked_mdelem *)gpr_arena_alloc(s->arena, sizeof(*nelem)); + grpc_linked_mdelem* nelem = + (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*nelem)); nelem->md = grpc_mdelem_from_slices( exec_ctx, grpc_slice_intern(GRPC_MDKEY(elem->md)), grpc_slice_intern(GRPC_MDVALUE(elem->md))); @@ -223,12 +223,12 @@ static grpc_error *fill_in_metadata(grpc_exec_ctx *exec_ctx, inproc_stream *s, return error; } -static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, grpc_stream_refcount *refcount, - const void *server_data, gpr_arena *arena) { +static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_stream_refcount* refcount, + const void* server_data, gpr_arena* arena) { INPROC_LOG(GPR_DEBUG, "init_stream %p %p %p", gt, gs, server_data); - inproc_transport *t = (inproc_transport *)gt; - inproc_stream *s = (inproc_stream *)gs; + inproc_transport* t = (inproc_transport*)gt; + inproc_stream* s = (inproc_stream*)gs; s->arena = arena; s->refs = refcount; @@ -277,7 +277,7 @@ static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, if (!server_data) { ref_transport(t); - inproc_transport *st = t->other_side; + inproc_transport* st = t->other_side; ref_transport(st); s->other_side = NULL; // will get filled in soon // Pass the client-side stream address to the server-side for a ref @@ -286,10 +286,10 @@ static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, INPROC_LOG(GPR_DEBUG, "calling accept stream cb %p %p", st->accept_stream_cb, st->accept_stream_data); (*st->accept_stream_cb)(exec_ctx, st->accept_stream_data, &st->base, - (void *)s); + (void*)s); } else { // This is the server-side and is being called through accept_stream_cb - inproc_stream *cs = (inproc_stream *)server_data; + inproc_stream* cs = (inproc_stream*)server_data; s->other_side = cs; // Ref the server-side stream on behalf of the client now ref_stream(s, "inproc_init_stream:srv"); @@ -326,15 +326,15 @@ static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, return 0; // return value is not important } -static void close_stream_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s) { +static void close_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s) { if (!s->closed) { // Release the metadata that we would have written out grpc_metadata_batch_destroy(exec_ctx, &s->write_buffer_initial_md); grpc_metadata_batch_destroy(exec_ctx, &s->write_buffer_trailing_md); if (s->listed) { - inproc_stream *p = s->stream_list_prev; - inproc_stream *n = s->stream_list_next; + inproc_stream* p = s->stream_list_prev; + inproc_stream* n = s->stream_list_next; if (p != NULL) { p->stream_list_next = n; } else { @@ -352,8 +352,8 @@ static void close_stream_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s) { } // This function means that we are done talking/listening to the other side -static void close_other_side_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s, - const char *reason) { +static void close_other_side_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, + const char* reason) { if (s->other_side != NULL) { // First release the metadata that came from the other side's arena grpc_metadata_batch_destroy(exec_ctx, &s->to_read_initial_md); @@ -371,10 +371,10 @@ static void close_other_side_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s, // this stream_op_batch is only one of the pending operations for this // stream. This is called when one of the pending operations for the stream // is done and about to be NULLed out -static void complete_if_batch_end_locked(grpc_exec_ctx *exec_ctx, - inproc_stream *s, grpc_error *error, - grpc_transport_stream_op_batch *op, - const char *msg) { +static void complete_if_batch_end_locked(grpc_exec_ctx* exec_ctx, + inproc_stream* s, grpc_error* error, + grpc_transport_stream_op_batch* op, + const char* msg) { int is_sm = (int)(op == s->send_message_op); int is_stm = (int)(op == s->send_trailing_md_op); int is_rim = (int)(op == s->recv_initial_md_op); @@ -387,9 +387,9 @@ static void complete_if_batch_end_locked(grpc_exec_ctx *exec_ctx, } } -static void maybe_schedule_op_closure_locked(grpc_exec_ctx *exec_ctx, - inproc_stream *s, - grpc_error *error) { +static void maybe_schedule_op_closure_locked(grpc_exec_ctx* exec_ctx, + inproc_stream* s, + grpc_error* error) { if (s && s->ops_needed && !s->op_closure_scheduled) { GRPC_CLOSURE_SCHED(exec_ctx, &s->op_closure, GRPC_ERROR_REF(error)); s->op_closure_scheduled = true; @@ -397,8 +397,8 @@ static void maybe_schedule_op_closure_locked(grpc_exec_ctx *exec_ctx, } } -static void fail_helper_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s, - grpc_error *error) { +static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, + grpc_error* error) { INPROC_LOG(GPR_DEBUG, "op_state_machine %p fail_helper", s); // If we're failing this side, we need to make sure that // we also send or have already sent trailing metadata @@ -409,10 +409,10 @@ static void fail_helper_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s, grpc_metadata_batch fake_md; grpc_metadata_batch_init(&fake_md); - inproc_stream *other = s->other_side; - grpc_metadata_batch *dest = (other == NULL) ? &s->write_buffer_trailing_md + inproc_stream* other = s->other_side; + grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_trailing_md : &other->to_read_trailing_md; - bool *destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled + bool* destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; fill_in_metadata(exec_ctx, s, &fake_md, 0, dest, NULL, destfilled); grpc_metadata_batch_destroy(exec_ctx, &fake_md); @@ -427,20 +427,20 @@ static void fail_helper_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s, } } if (s->recv_initial_md_op) { - grpc_error *err; + grpc_error* err; if (!s->t->is_client) { // If this is a server, provide initial metadata with a path and authority // 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 = - (grpc_linked_mdelem *)gpr_arena_alloc(s->arena, sizeof(*path_md)); + grpc_linked_mdelem* path_md = + (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*path_md)); path_md->md = grpc_mdelem_from_slices(exec_ctx, g_fake_path_key, g_fake_path_value); GPR_ASSERT(grpc_metadata_batch_link_tail(exec_ctx, &fake_md, path_md) == GRPC_ERROR_NONE); - grpc_linked_mdelem *auth_md = - (grpc_linked_mdelem *)gpr_arena_alloc(s->arena, sizeof(*auth_md)); + grpc_linked_mdelem* auth_md = + (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*auth_md)); auth_md->md = grpc_mdelem_from_slices(exec_ctx, g_fake_auth_key, g_fake_auth_value); GPR_ASSERT(grpc_metadata_batch_link_tail(exec_ctx, &fake_md, auth_md) == @@ -509,9 +509,9 @@ static void fail_helper_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s, GRPC_ERROR_UNREF(error); } -static void message_transfer_locked(grpc_exec_ctx *exec_ctx, - inproc_stream *sender, - inproc_stream *receiver) { +static void message_transfer_locked(grpc_exec_ctx* exec_ctx, + inproc_stream* sender, + inproc_stream* receiver) { size_t remaining = sender->send_message_op->payload->send_message.send_message->length; if (receiver->recv_inited) { @@ -525,7 +525,7 @@ static void message_transfer_locked(grpc_exec_ctx *exec_ctx, GPR_ASSERT(grpc_byte_stream_next( exec_ctx, sender->send_message_op->payload->send_message.send_message, SIZE_MAX, &unused)); - grpc_error *error = grpc_byte_stream_pull( + grpc_error* error = grpc_byte_stream_pull( exec_ctx, sender->send_message_op->payload->send_message.send_message, &message_slice); if (error != GRPC_ERROR_NONE) { @@ -558,8 +558,8 @@ static void message_transfer_locked(grpc_exec_ctx *exec_ctx, sender->send_message_op = NULL; } -static void op_state_machine(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { +static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { // This function gets called when we have contents in the unprocessed reads // Get what we want based on our ops wanted // Schedule our appropriate closures @@ -567,17 +567,17 @@ static void op_state_machine(grpc_exec_ctx *exec_ctx, void *arg, // Since this is a closure directly invoked by the combiner, it should not // unref the error parameter explicitly; the combiner will do that implicitly - grpc_error *new_err = GRPC_ERROR_NONE; + grpc_error* new_err = GRPC_ERROR_NONE; bool needs_close = false; INPROC_LOG(GPR_DEBUG, "op_state_machine %p", arg); - inproc_stream *s = (inproc_stream *)arg; - gpr_mu *mu = &s->t->mu->mu; // keep aside in case s gets closed + inproc_stream* s = (inproc_stream*)arg; + gpr_mu* mu = &s->t->mu->mu; // keep aside in case s gets closed gpr_mu_lock(mu); s->op_closure_scheduled = false; // cancellation takes precedence - inproc_stream *other = s->other_side; + inproc_stream* other = s->other_side; if (s->cancel_self_error != GRPC_ERROR_NONE) { fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(s->cancel_self_error)); @@ -612,9 +612,9 @@ static void op_state_machine(grpc_exec_ctx *exec_ctx, void *arg, (!s->send_message_op || (s->t->is_client && (s->trailing_md_recvd || s->to_read_trailing_md_filled)))) { - grpc_metadata_batch *dest = (other == NULL) ? &s->write_buffer_trailing_md + grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_trailing_md : &other->to_read_trailing_md; - bool *destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled + bool* destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; if (*destfilled || s->trailing_md_sent) { // The buffer is already in use; that's an error! @@ -810,8 +810,8 @@ done: GRPC_ERROR_UNREF(new_err); } -static bool cancel_stream_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s, - grpc_error *error) { +static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, + grpc_error* error) { bool ret = false; // was the cancel accepted INPROC_LOG(GPR_DEBUG, "cancel_stream %p with %s", s, grpc_error_string(error)); @@ -826,10 +826,10 @@ static bool cancel_stream_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s, grpc_metadata_batch cancel_md; grpc_metadata_batch_init(&cancel_md); - inproc_stream *other = s->other_side; - grpc_metadata_batch *dest = (other == NULL) ? &s->write_buffer_trailing_md + inproc_stream* other = s->other_side; + grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_trailing_md : &other->to_read_trailing_md; - bool *destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled + bool* destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; fill_in_metadata(exec_ctx, s, &cancel_md, 0, dest, NULL, destfilled); grpc_metadata_batch_destroy(exec_ctx, &cancel_md); @@ -862,12 +862,12 @@ static bool cancel_stream_locked(grpc_exec_ctx *exec_ctx, inproc_stream *s, return ret; } -static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, - grpc_transport_stream_op_batch *op) { +static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, + grpc_transport_stream_op_batch* op) { INPROC_LOG(GPR_DEBUG, "perform_stream_op %p %p %p", gt, gs, op); - inproc_stream *s = (inproc_stream *)gs; - gpr_mu *mu = &s->t->mu->mu; // save aside in case s gets closed + inproc_stream* s = (inproc_stream*)gs; + gpr_mu* mu = &s->t->mu->mu; // save aside in case s gets closed gpr_mu_lock(mu); if (GRPC_TRACER_ON(grpc_inproc_trace)) { @@ -880,8 +880,8 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, s->t->is_client, false); } } - grpc_error *error = GRPC_ERROR_NONE; - grpc_closure *on_complete = op->on_complete; + grpc_error* error = GRPC_ERROR_NONE; + grpc_closure* on_complete = op->on_complete; if (on_complete == NULL) { on_complete = &do_nothing_closure; } @@ -907,18 +907,18 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, bool needs_close = false; - inproc_stream *other = s->other_side; + inproc_stream* other = s->other_side; if (error == GRPC_ERROR_NONE && (op->send_initial_metadata || op->send_trailing_metadata)) { if (s->t->is_closed) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Endpoint already shutdown"); } if (error == GRPC_ERROR_NONE && op->send_initial_metadata) { - grpc_metadata_batch *dest = (other == NULL) ? &s->write_buffer_initial_md + grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_initial_md : &other->to_read_initial_md; - uint32_t *destflags = (other == NULL) ? &s->write_buffer_initial_md_flags + uint32_t* destflags = (other == NULL) ? &s->write_buffer_initial_md_flags : &other->to_read_initial_md_flags; - bool *destfilled = (other == NULL) ? &s->write_buffer_initial_md_filled + bool* destfilled = (other == NULL) ? &s->write_buffer_initial_md_filled : &other->to_read_initial_md_filled; if (*destfilled || s->initial_md_sent) { // The buffer is already in use; that's an error! @@ -933,7 +933,7 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, dest, destflags, destfilled); } if (s->t->is_client) { - grpc_millis *dl = + grpc_millis* dl = (other == NULL) ? &s->write_buffer_deadline : &other->deadline; *dl = GPR_MIN(*dl, op->payload->send_initial_metadata .send_initial_metadata->deadline); @@ -972,8 +972,9 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, // 4. We want to receive a message and there is a message ready // 5. There is trailing metadata, even if nothing specifically wants // that because that can shut down the receive message as well - if ((op->send_message && other && ((other->recv_message_op != NULL) || - (other->recv_trailing_md_op != NULL))) || + if ((op->send_message && other && + ((other->recv_message_op != NULL) || + (other->recv_trailing_md_op != NULL))) || (op->send_trailing_metadata && !op->send_message) || (op->recv_initial_metadata && s->to_read_initial_md_filled) || (op->recv_message && other && (other->send_message_op != NULL)) || @@ -1020,8 +1021,8 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, GRPC_ERROR_UNREF(error); } -static void close_transport_locked(grpc_exec_ctx *exec_ctx, - inproc_transport *t) { +static void close_transport_locked(grpc_exec_ctx* exec_ctx, + inproc_transport* t) { INPROC_LOG(GPR_DEBUG, "close_transport %p %d", t, t->is_closed); grpc_connectivity_state_set( exec_ctx, &t->connectivity, GRPC_CHANNEL_SHUTDOWN, @@ -1041,9 +1042,9 @@ static void close_transport_locked(grpc_exec_ctx *exec_ctx, } } -static void perform_transport_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_transport_op *op) { - inproc_transport *t = (inproc_transport *)gt; +static void perform_transport_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_transport_op* op) { + inproc_transport* t = (inproc_transport*)gt; INPROC_LOG(GPR_DEBUG, "perform_transport_op %p %p", t, op); gpr_mu_lock(&t->mu->mu); if (op->on_connectivity_state_change) { @@ -1075,17 +1076,17 @@ static void perform_transport_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, gpr_mu_unlock(&t->mu->mu); } -static void destroy_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, - grpc_closure *then_schedule_closure) { +static void destroy_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, + grpc_closure* then_schedule_closure) { INPROC_LOG(GPR_DEBUG, "destroy_stream %p %p", gs, then_schedule_closure); - inproc_stream *s = (inproc_stream *)gs; + inproc_stream* s = (inproc_stream*)gs; s->closure_at_destroy = then_schedule_closure; really_destroy_stream(exec_ctx, s); } -static void destroy_transport(grpc_exec_ctx *exec_ctx, grpc_transport *gt) { - inproc_transport *t = (inproc_transport *)gt; +static void destroy_transport(grpc_exec_ctx* exec_ctx, grpc_transport* gt) { + inproc_transport* t = (inproc_transport*)gt; INPROC_LOG(GPR_DEBUG, "destroy_transport %p", t); gpr_mu_lock(&t->mu->mu); close_transport_locked(exec_ctx, t); @@ -1098,24 +1099,24 @@ static void destroy_transport(grpc_exec_ctx *exec_ctx, grpc_transport *gt) { * INTEGRATION GLUE */ -static void set_pollset(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, grpc_pollset *pollset) { +static void set_pollset(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_pollset* pollset) { // Nothing to do here } -static void set_pollset_set(grpc_exec_ctx *exec_ctx, grpc_transport *gt, - grpc_stream *gs, grpc_pollset_set *pollset_set) { +static void set_pollset_set(grpc_exec_ctx* exec_ctx, grpc_transport* gt, + grpc_stream* gs, grpc_pollset_set* pollset_set) { // Nothing to do here } -static grpc_endpoint *get_endpoint(grpc_exec_ctx *exec_ctx, grpc_transport *t) { +static grpc_endpoint* get_endpoint(grpc_exec_ctx* exec_ctx, grpc_transport* t) { return NULL; } /******************************************************************************* * GLOBAL INIT AND DESTROY */ -static void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {} +static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} void grpc_inproc_transport_init(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; @@ -1146,16 +1147,16 @@ static const grpc_transport_vtable inproc_vtable = { /******************************************************************************* * Main inproc transport functions */ -static void inproc_transports_create(grpc_exec_ctx *exec_ctx, - grpc_transport **server_transport, - const grpc_channel_args *server_args, - grpc_transport **client_transport, - const grpc_channel_args *client_args) { +static void inproc_transports_create(grpc_exec_ctx* exec_ctx, + grpc_transport** server_transport, + const grpc_channel_args* server_args, + grpc_transport** client_transport, + const grpc_channel_args* client_args) { INPROC_LOG(GPR_DEBUG, "inproc_transports_create"); - inproc_transport *st = (inproc_transport *)gpr_zalloc(sizeof(*st)); - inproc_transport *ct = (inproc_transport *)gpr_zalloc(sizeof(*ct)); + inproc_transport* st = (inproc_transport*)gpr_zalloc(sizeof(*st)); + inproc_transport* ct = (inproc_transport*)gpr_zalloc(sizeof(*ct)); // Share one lock between both sides since both sides get affected - st->mu = ct->mu = (shared_mu *)gpr_malloc(sizeof(*st->mu)); + st->mu = ct->mu = (shared_mu*)gpr_malloc(sizeof(*st->mu)); gpr_mu_init(&st->mu->mu); gpr_ref_init(&st->mu->refs, 2); st->base.vtable = &inproc_vtable; @@ -1174,37 +1175,37 @@ static void inproc_transports_create(grpc_exec_ctx *exec_ctx, ct->other_side = st; st->stream_list = NULL; ct->stream_list = NULL; - *server_transport = (grpc_transport *)st; - *client_transport = (grpc_transport *)ct; + *server_transport = (grpc_transport*)st; + *client_transport = (grpc_transport*)ct; } -grpc_channel *grpc_inproc_channel_create(grpc_server *server, - grpc_channel_args *args, - void *reserved) { +grpc_channel* grpc_inproc_channel_create(grpc_server* server, + grpc_channel_args* args, + void* reserved) { GRPC_API_TRACE("grpc_inproc_channel_create(server=%p, args=%p)", 2, (server, args)); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - const grpc_channel_args *server_args = grpc_server_get_channel_args(server); + const grpc_channel_args* server_args = grpc_server_get_channel_args(server); // Add a default authority channel argument for the client grpc_arg default_authority_arg; default_authority_arg.type = GRPC_ARG_STRING; - default_authority_arg.key = (char *)GRPC_ARG_DEFAULT_AUTHORITY; - default_authority_arg.value.string = (char *)"inproc.authority"; - grpc_channel_args *client_args = + default_authority_arg.key = (char*)GRPC_ARG_DEFAULT_AUTHORITY; + default_authority_arg.value.string = (char*)"inproc.authority"; + grpc_channel_args* client_args = grpc_channel_args_copy_and_add(args, &default_authority_arg, 1); - grpc_transport *server_transport; - grpc_transport *client_transport; + grpc_transport* server_transport; + grpc_transport* client_transport; inproc_transports_create(&exec_ctx, &server_transport, server_args, &client_transport, client_args); grpc_server_setup_transport(&exec_ctx, server, server_transport, NULL, server_args); - grpc_channel *channel = + grpc_channel* channel = grpc_channel_create(&exec_ctx, "inproc", client_args, GRPC_CLIENT_DIRECT_CHANNEL, client_transport); diff --git a/src/core/ext/transport/inproc/inproc_transport.h b/src/core/ext/transport/inproc/inproc_transport.h index 37e6d99e99..6e83af3b4c 100644 --- a/src/core/ext/transport/inproc/inproc_transport.h +++ b/src/core/ext/transport/inproc/inproc_transport.h @@ -25,9 +25,9 @@ extern "C" { #endif -grpc_channel *grpc_inproc_channel_create(grpc_server *server, - grpc_channel_args *args, - void *reserved); +grpc_channel* grpc_inproc_channel_create(grpc_server* server, + grpc_channel_args* args, + void* reserved); extern grpc_tracer_flag grpc_inproc_trace; |