diff options
Diffstat (limited to 'src/core/ext/filters/client_channel/resolver')
9 files changed, 390 insertions, 386 deletions
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 5f7ab987cb..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,9 +269,10 @@ 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); + grpc_millis next_try = + grpc_backoff_step(exec_ctx, &r->backoff_state).next_attempt_start_time; grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); @@ -295,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; @@ -312,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; @@ -326,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 @@ -340,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); } @@ -354,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); @@ -370,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}); @@ -379,11 +380,11 @@ static grpc_resolver *dns_ares_create(grpc_exec_ctx *exec_ctx, grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, args->pollset_set); } - grpc_backoff_init(&r->backoff_state, GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS, - GRPC_DNS_RECONNECT_BACKOFF_MULTIPLIER, - GRPC_DNS_RECONNECT_JITTER, - GRPC_DNS_MIN_CONNECT_TIMEOUT_SECONDS * 1000, - GRPC_DNS_RECONNECT_MAX_BACKOFF_SECONDS * 1000); + grpc_backoff_init( + &r->backoff_state, GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS * 1000, + GRPC_DNS_RECONNECT_BACKOFF_MULTIPLIER, GRPC_DNS_RECONNECT_JITTER, + GRPC_DNS_MIN_CONNECT_TIMEOUT_SECONDS * 1000, + GRPC_DNS_RECONNECT_MAX_BACKOFF_SECONDS * 1000); GRPC_CLOSURE_INIT(&r->dns_ares_on_retry_timer_locked, dns_ares_on_retry_timer_locked, r, grpc_combiner_scheduler(r->base.combiner)); @@ -397,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); } @@ -419,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; @@ -440,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 e669b6dfc7..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( @@ -170,7 +170,8 @@ static void dns_on_resolved_locked(grpc_exec_ctx *exec_ctx, void *arg, grpc_resolved_addresses_destroy(r->addresses); grpc_lb_addresses_destroy(exec_ctx, addresses); } else { - grpc_millis next_try = grpc_backoff_step(exec_ctx, &r->backoff_state); + grpc_millis next_try = + grpc_backoff_step(exec_ctx, &r->backoff_state).next_attempt_start_time; grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); @@ -197,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; @@ -210,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 @@ -223,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); } @@ -235,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); @@ -256,11 +257,11 @@ static grpc_resolver *dns_create(grpc_exec_ctx *exec_ctx, grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, args->pollset_set); } - grpc_backoff_init(&r->backoff_state, GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS, - GRPC_DNS_RECONNECT_BACKOFF_MULTIPLIER, - GRPC_DNS_RECONNECT_JITTER, - GRPC_DNS_MIN_CONNECT_TIMEOUT_SECONDS * 1000, - GRPC_DNS_RECONNECT_MAX_BACKOFF_SECONDS * 1000); + grpc_backoff_init( + &r->backoff_state, GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS * 1000, + GRPC_DNS_RECONNECT_BACKOFF_MULTIPLIER, GRPC_DNS_RECONNECT_JITTER, + GRPC_DNS_MIN_CONNECT_TIMEOUT_SECONDS * 1000, + GRPC_DNS_RECONNECT_MAX_BACKOFF_SECONDS * 1000); return &r->base; } @@ -268,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); } @@ -290,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 = { \ |