diff options
Diffstat (limited to 'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc')
-rw-r--r-- | src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc | 94 |
1 files changed, 40 insertions, 54 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 3a16b3492d..4ec4477c82 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 @@ -97,17 +97,14 @@ typedef struct { 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_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(ares_dns_resolver* r); +static void dns_ares_maybe_finish_next_locked(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, +static void dns_ares_shutdown_locked(grpc_resolver* r); +static void dns_ares_channel_saw_error_locked(grpc_resolver* r); +static void dns_ares_next_locked(grpc_resolver* r, grpc_channel_args** target_result, grpc_closure* on_complete); @@ -115,43 +112,39 @@ 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) { +static void dns_ares_shutdown_locked(grpc_resolver* resolver) { ares_dns_resolver* r = (ares_dns_resolver*)resolver; if (r->have_retry_timer) { - grpc_timer_cancel(exec_ctx, &r->retry_timer); + grpc_timer_cancel(&r->retry_timer); } if (r->pending_request != nullptr) { - grpc_cancel_ares_request(exec_ctx, r->pending_request); + grpc_cancel_ares_request(r->pending_request); } if (r->next_completion != nullptr) { *r->target_result = nullptr; - GRPC_CLOSURE_SCHED( - exec_ctx, r->next_completion, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); + GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Resolver Shutdown")); r->next_completion = nullptr; } } -static void dns_ares_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver) { +static void dns_ares_channel_saw_error_locked(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); + dns_ares_start_resolving_locked(r); } } -static void dns_ares_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, - grpc_error* error) { +static void dns_ares_on_retry_timer_locked(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) { - dns_ares_start_resolving_locked(exec_ctx, r); + dns_ares_start_resolving_locked(r); } } - GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "retry-timer"); + GRPC_RESOLVER_UNREF(&r->base, "retry-timer"); } static bool value_in_json_array(grpc_json* array, const char* value) { @@ -226,8 +219,7 @@ 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) { +static void dns_ares_on_resolved_locked(void* arg, grpc_error* error) { ares_dns_resolver* r = (ares_dns_resolver*)arg; grpc_channel_args* result = nullptr; GPR_ASSERT(r->resolving); @@ -268,13 +260,13 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, num_args_to_add); if (service_config != nullptr) grpc_service_config_destroy(service_config); gpr_free(service_config_string); - grpc_lb_addresses_destroy(exec_ctx, r->lb_addresses); + grpc_lb_addresses_destroy(r->lb_addresses); } else { 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; - grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); + grpc_backoff_step(&r->backoff_state).next_attempt_start_time; + grpc_millis timeout = next_try - grpc_core::ExecCtx::Get()->Now(); gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", grpc_error_string(error)); GPR_ASSERT(!r->have_retry_timer); @@ -285,20 +277,19 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, } else { gpr_log(GPR_DEBUG, "retrying immediately"); } - grpc_timer_init(exec_ctx, &r->retry_timer, next_try, + grpc_timer_init(&r->retry_timer, next_try, &r->dns_ares_on_retry_timer_locked); } if (r->resolved_result != nullptr) { - grpc_channel_args_destroy(exec_ctx, r->resolved_result); + grpc_channel_args_destroy(r->resolved_result); } r->resolved_result = result; r->resolved_version++; - dns_ares_maybe_finish_next_locked(exec_ctx, r); - GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "dns-resolving"); + dns_ares_maybe_finish_next_locked(r); + GRPC_RESOLVER_UNREF(&r->base, "dns-resolving"); } -static void dns_ares_next_locked(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver, +static void dns_ares_next_locked(grpc_resolver* resolver, grpc_channel_args** target_result, grpc_closure* on_complete) { gpr_log(GPR_DEBUG, "dns_ares_next is called."); @@ -308,56 +299,53 @@ static void dns_ares_next_locked(grpc_exec_ctx* exec_ctx, r->target_result = target_result; if (r->resolved_version == 0 && !r->resolving) { grpc_backoff_reset(&r->backoff_state); - dns_ares_start_resolving_locked(exec_ctx, r); + dns_ares_start_resolving_locked(r); } else { - dns_ares_maybe_finish_next_locked(exec_ctx, r); + dns_ares_maybe_finish_next_locked(r); } } -static void dns_ares_start_resolving_locked(grpc_exec_ctx* exec_ctx, - ares_dns_resolver* r) { +static void dns_ares_start_resolving_locked(ares_dns_resolver* r) { GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GPR_ASSERT(!r->resolving); r->resolving = true; r->lb_addresses = nullptr; r->service_config_json = nullptr; r->pending_request = grpc_dns_lookup_ares( - exec_ctx, r->dns_server, r->name_to_resolve, r->default_port, - r->interested_parties, &r->dns_ares_on_resolved_locked, &r->lb_addresses, + r->dns_server, r->name_to_resolve, r->default_port, r->interested_parties, + &r->dns_ares_on_resolved_locked, &r->lb_addresses, true /* check_grpclb */, r->request_service_config ? &r->service_config_json : nullptr); } -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(ares_dns_resolver* r) { if (r->next_completion != nullptr && r->resolved_version != r->published_version) { *r->target_result = r->resolved_result == nullptr ? nullptr : grpc_channel_args_copy(r->resolved_result); gpr_log(GPR_DEBUG, "dns_ares_maybe_finish_next_locked"); - GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(r->next_completion, GRPC_ERROR_NONE); r->next_completion = nullptr; r->published_version = r->resolved_version; } } -static void dns_ares_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { +static void dns_ares_destroy(grpc_resolver* gr) { gpr_log(GPR_DEBUG, "dns_ares_destroy"); ares_dns_resolver* r = (ares_dns_resolver*)gr; if (r->resolved_result != nullptr) { - grpc_channel_args_destroy(exec_ctx, r->resolved_result); + grpc_channel_args_destroy(r->resolved_result); } - grpc_pollset_set_destroy(exec_ctx, r->interested_parties); + grpc_pollset_set_destroy(r->interested_parties); gpr_free(r->dns_server); gpr_free(r->name_to_resolve); gpr_free(r->default_port); - grpc_channel_args_destroy(exec_ctx, r->channel_args); + grpc_channel_args_destroy(r->channel_args); gpr_free(r); } -static grpc_resolver* dns_ares_create(grpc_exec_ctx* exec_ctx, - grpc_resolver_args* args, +static grpc_resolver* dns_ares_create(grpc_resolver_args* args, const char* default_port) { /* Get name from args. */ const char* path = args->uri->path; @@ -378,8 +366,7 @@ static grpc_resolver* dns_ares_create(grpc_exec_ctx* exec_ctx, arg, (grpc_integer_options){false, false, true}); r->interested_parties = grpc_pollset_set_create(); if (args->pollset_set != nullptr) { - grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, - args->pollset_set); + grpc_pollset_set_add_pollset_set(r->interested_parties, args->pollset_set); } grpc_backoff_init( &r->backoff_state, GRPC_DNS_INITIAL_CONNECT_BACKOFF_SECONDS * 1000, @@ -404,9 +391,8 @@ static void dns_ares_factory_ref(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) { - return dns_ares_create(exec_ctx, args, "https"); + grpc_resolver_factory* factory, grpc_resolver_args* args) { + return dns_ares_create(args, "https"); } static char* dns_ares_factory_get_default_host_name( |