diff options
Diffstat (limited to 'src/core/ext/filters/client_channel/resolver/dns')
5 files changed, 99 insertions, 97 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 76f08281f7..07737b19d2 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 @@ -121,15 +121,15 @@ static void dns_ares_shutdown_locked(grpc_exec_ctx* exec_ctx, if (r->have_retry_timer) { grpc_timer_cancel(exec_ctx, &r->retry_timer); } - if (r->pending_request != NULL) { + if (r->pending_request != nullptr) { grpc_cancel_ares_request(exec_ctx, r->pending_request); } - if (r->next_completion != NULL) { - *r->target_result = NULL; + 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")); - r->next_completion = NULL; + r->next_completion = nullptr; } } @@ -155,7 +155,7 @@ static void dns_ares_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, } static bool value_in_json_array(grpc_json* array, const char* value) { - for (grpc_json* entry = array->child; entry != NULL; entry = entry->next) { + for (grpc_json* entry = array->child; entry != nullptr; entry = entry->next) { if (entry->type == GRPC_JSON_STRING && strcmp(entry->value, value) == 0) { return true; } @@ -165,47 +165,48 @@ static bool value_in_json_array(grpc_json* array, const char* value) { 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) { + if (choices_json == nullptr || choices_json->type != GRPC_JSON_ARRAY) { gpr_log(GPR_ERROR, "cannot parse service config JSON string"); - return NULL; + return nullptr; } - char* service_config = NULL; - for (grpc_json* choice = choices_json->child; choice != NULL; + char* service_config = nullptr; + for (grpc_json* choice = choices_json->child; choice != nullptr; 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 = nullptr; + for (grpc_json* field = choice->child; field != nullptr; + field = field->next) { // Check client language, if specified. if (strcmp(field->key, "clientLanguage") == 0) { if (field->type != GRPC_JSON_ARRAY || !value_in_json_array(field, "c++")) { - service_config_json = NULL; + service_config_json = nullptr; break; } } // Check client hostname, if specified. if (strcmp(field->key, "clientHostname") == 0) { char* hostname = grpc_gethostname(); - if (hostname == NULL || field->type != GRPC_JSON_ARRAY || + if (hostname == nullptr || field->type != GRPC_JSON_ARRAY || !value_in_json_array(field, hostname)) { - service_config_json = NULL; + service_config_json = nullptr; break; } } // Check percentage, if specified. if (strcmp(field->key, "percentage") == 0) { if (field->type != GRPC_JSON_NUMBER) { - service_config_json = NULL; + service_config_json = nullptr; break; } int random_pct = rand() % 100; int percentage; if (sscanf(field->value, "%d", &percentage) != 1 || random_pct > percentage || percentage == 0) { - service_config_json = NULL; + service_config_json = nullptr; break; } } @@ -216,7 +217,7 @@ static char* choose_service_config(char* service_config_choice_json) { } } } - if (service_config_json != NULL) { + if (service_config_json != nullptr) { service_config = grpc_json_dump_to_string(service_config_json, 0); break; } @@ -228,33 +229,33 @@ static char* choose_service_config(char* service_config_choice_json) { 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; + grpc_channel_args* result = nullptr; GPR_ASSERT(r->resolving); r->resolving = false; - r->pending_request = NULL; - if (r->lb_addresses != NULL) { + r->pending_request = nullptr; + if (r->lb_addresses != nullptr) { 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; - if (r->service_config_json != NULL) { + grpc_service_config* service_config = nullptr; + char* service_config_string = nullptr; + if (r->service_config_json != nullptr) { service_config_string = choose_service_config(r->service_config_json); gpr_free(r->service_config_json); - if (service_config_string != NULL) { + if (service_config_string != nullptr) { gpr_log(GPR_INFO, "selected service config choice: %s", 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); service_config = grpc_service_config_create(service_config_string); - if (service_config != NULL) { + if (service_config != nullptr) { const char* lb_policy_name = grpc_service_config_get_lb_policy_name(service_config); - if (lb_policy_name != NULL) { + if (lb_policy_name != nullptr) { 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); @@ -265,7 +266,7 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, result = grpc_channel_args_copy_and_add_and_remove( r->channel_args, args_to_remove, num_args_to_remove, new_args, num_args_to_add); - if (service_config != NULL) grpc_service_config_destroy(service_config); + if (service_config != nullptr) grpc_service_config_destroy(service_config); gpr_free(service_config_string); grpc_lb_addresses_destroy(exec_ctx, r->lb_addresses); } else { @@ -287,7 +288,7 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_timer_init(exec_ctx, &r->retry_timer, next_try, &r->dns_ares_on_retry_timer_locked); } - if (r->resolved_result != NULL) { + if (r->resolved_result != nullptr) { grpc_channel_args_destroy(exec_ctx, r->resolved_result); } r->resolved_result = result; @@ -318,25 +319,25 @@ static void dns_ares_start_resolving_locked(grpc_exec_ctx* exec_ctx, GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GPR_ASSERT(!r->resolving); r->resolving = true; - r->lb_addresses = NULL; - r->service_config_json = NULL; + 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, true /* check_grpclb */, - r->request_service_config ? &r->service_config_json : NULL); + 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) { - if (r->next_completion != NULL && + if (r->next_completion != nullptr && r->resolved_version != r->published_version) { - *r->target_result = r->resolved_result == NULL - ? NULL + *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); - r->next_completion = NULL; + r->next_completion = nullptr; r->published_version = r->resolved_version; } } @@ -344,7 +345,7 @@ 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) { gpr_log(GPR_DEBUG, "dns_ares_destroy"); ares_dns_resolver* r = (ares_dns_resolver*)gr; - if (r->resolved_result != NULL) { + if (r->resolved_result != nullptr) { grpc_channel_args_destroy(exec_ctx, r->resolved_result); } grpc_pollset_set_destroy(exec_ctx, r->interested_parties); @@ -376,7 +377,7 @@ static grpc_resolver* dns_ares_create(grpc_exec_ctx* exec_ctx, r->request_service_config = !grpc_channel_arg_get_integer( arg, (grpc_integer_options){false, false, true}); r->interested_parties = grpc_pollset_set_create(); - if (args->pollset_set != NULL) { + if (args->pollset_set != nullptr) { grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, args->pollset_set); } @@ -428,7 +429,7 @@ extern "C" void grpc_resolver_dns_ares_init(void) { 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) { + if (resolver != nullptr && gpr_stricmp(resolver, "ares") == 0) { grpc_error* error = grpc_ares_init(); if (error != GRPC_ERROR_NONE) { GRPC_LOG_IF_ERROR("ares_library_init() failed", error); @@ -442,7 +443,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"); - if (resolver != NULL && gpr_stricmp(resolver, "ares") == 0) { + if (resolver != nullptr && gpr_stricmp(resolver, "ares") == 0) { grpc_ares_cleanup(); } gpr_free(resolver); 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 a5fb1f10e1..0062aa561a 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 @@ -19,6 +19,7 @@ #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H +#include <ares.h> #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/pollset_set.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 2bb98c1a3f..4cb068a41d 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 @@ -91,7 +91,7 @@ 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); - GPR_ASSERT(ev_driver->fds == NULL); + GPR_ASSERT(ev_driver->fds == nullptr); gpr_mu_destroy(&ev_driver->mu); ares_destroy(ev_driver->channel); gpr_free(ev_driver); @@ -106,7 +106,7 @@ static void fd_node_destroy(grpc_exec_ctx* exec_ctx, fd_node* fdn) { /* c-ares library has closed the fd inside grpc_fd. This fd may be picked up immediately by another thread, and should not be closed by the following grpc_fd_orphan. */ - grpc_fd_orphan(exec_ctx, fdn->fd, NULL, NULL, true /* already_closed */, + grpc_fd_orphan(exec_ctx, fdn->fd, nullptr, nullptr, true /* already_closed */, "c-ares query finished"); gpr_free(fdn); } @@ -142,7 +142,7 @@ grpc_error* grpc_ares_ev_driver_create(grpc_ares_ev_driver** ev_driver, gpr_mu_init(&(*ev_driver)->mu); gpr_ref_init(&(*ev_driver)->refs, 1); (*ev_driver)->pollset_set = pollset_set; - (*ev_driver)->fds = NULL; + (*ev_driver)->fds = nullptr; (*ev_driver)->working = false; (*ev_driver)->shutting_down = false; return GRPC_ERROR_NONE; @@ -165,7 +165,7 @@ void grpc_ares_ev_driver_shutdown(grpc_exec_ctx* exec_ctx, gpr_mu_lock(&ev_driver->mu); ev_driver->shutting_down = true; fd_node* fn = ev_driver->fds; - while (fn != NULL) { + while (fn != nullptr) { grpc_fd_shutdown( exec_ctx, fn->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("grpc_ares_ev_driver_shutdown")); @@ -180,7 +180,7 @@ static fd_node* pop_fd_node(fd_node** head, int fd) { fd_node dummy_head; dummy_head.next = *head; fd_node* node = &dummy_head; - while (node->next != NULL) { + while (node->next != nullptr) { if (grpc_fd_wrapped_fd(node->next->fd) == fd) { fd_node* ret = node->next; node->next = node->next->next; @@ -189,7 +189,7 @@ static fd_node* pop_fd_node(fd_node** head, int fd) { } node = node->next; } - return NULL; + return nullptr; } /* Check if \a fd is still readable */ @@ -275,7 +275,7 @@ ares_channel* grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver* ev_driver) { // 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; + fd_node* new_list = nullptr; if (!ev_driver->shutting_down) { ares_socket_t socks[ARES_GETSOCK_MAXNUM]; int socks_bitmask = @@ -285,7 +285,7 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, ARES_GETSOCK_WRITABLE(socks_bitmask, 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) { + if (fdn == nullptr) { char* fd_name; gpr_asprintf(&fd_name, "ares_ev_driver-%" PRIuPTR, i); fdn = (fd_node*)gpr_malloc(sizeof(fd_node)); @@ -332,14 +332,14 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, // Any remaining fds in ev_driver->fds were not returned by ares_getsock() and // are therefore no longer in use, so they can be shut down and removed from // the list. - while (ev_driver->fds != NULL) { + while (ev_driver->fds != nullptr) { fd_node* cur = ev_driver->fds; ev_driver->fds = ev_driver->fds->next; fd_node_shutdown(exec_ctx, cur); } ev_driver->fds = new_list; // If the ev driver has no working fd, all the tasks are done. - if (new_list == NULL) { + if (new_list == nullptr) { ev_driver->working = false; gpr_log(GPR_DEBUG, "ev driver stop working"); } 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 9408b9d81d..7271559432 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 @@ -102,7 +102,7 @@ static void grpc_ares_request_unref(grpc_exec_ctx* exec_ctx, request */ if (gpr_unref(&r->pending_queries)) { /* TODO(zyc): Sort results with RFC6724 before invoking on_done. */ - if (exec_ctx == NULL) { + if (exec_ctx == nullptr) { /* A new exec_ctx is created here, as the c-ares interface does not provide one in ares_host_callback. It's safe to schedule on_done with the newly created exec_ctx, since the caller has been warned not to @@ -150,12 +150,12 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, r->error = GRPC_ERROR_NONE; r->success = true; grpc_lb_addresses** lb_addresses = r->lb_addrs_out; - if (*lb_addresses == NULL) { - *lb_addresses = grpc_lb_addresses_create(0, NULL); + if (*lb_addresses == nullptr) { + *lb_addresses = grpc_lb_addresses_create(0, nullptr); } size_t prev_naddr = (*lb_addresses)->num_addresses; size_t i; - for (i = 0; hostent->h_addr_list[i] != NULL; i++) { + for (i = 0; hostent->h_addr_list[i] != nullptr; i++) { } (*lb_addresses)->num_addresses += i; (*lb_addresses)->addresses = (grpc_lb_address*)gpr_realloc( @@ -174,8 +174,8 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, grpc_lb_addresses_set_address( *lb_addresses, i, &addr, addr_len, hr->is_balancer /* is_balancer */, - hr->is_balancer ? hr->host : NULL /* balancer_name */, - NULL /* user_data */); + hr->is_balancer ? hr->host : nullptr /* balancer_name */, + nullptr /* user_data */); char output[INET6_ADDRSTRLEN]; ares_inet_ntop(AF_INET6, &addr.sin6_addr, output, INET6_ADDRSTRLEN); gpr_log(GPR_DEBUG, @@ -195,8 +195,8 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, grpc_lb_addresses_set_address( *lb_addresses, i, &addr, addr_len, hr->is_balancer /* is_balancer */, - hr->is_balancer ? hr->host : NULL /* balancer_name */, - NULL /* user_data */); + hr->is_balancer ? hr->host : nullptr /* balancer_name */, + nullptr /* user_data */); char output[INET_ADDRSTRLEN]; ares_inet_ntop(AF_INET, &addr.sin_addr, output, INET_ADDRSTRLEN); gpr_log(GPR_DEBUG, @@ -220,7 +220,7 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, } } gpr_mu_unlock(&r->mu); - destroy_hostbyname_request(NULL, hr); + destroy_hostbyname_request(nullptr, hr); } static void on_srv_query_done_cb(void* arg, int status, int timeouts, @@ -234,7 +234,7 @@ static void on_srv_query_done_cb(void* arg, int status, int timeouts, 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; + for (struct ares_srv_reply* srv_it = reply; srv_it != nullptr; srv_it = srv_it->next) { if (grpc_ipv6_loopback_available()) { grpc_ares_hostbyname_request* hr = create_hostbyname_request( @@ -249,7 +249,7 @@ static void on_srv_query_done_cb(void* arg, int status, int timeouts, grpc_ares_ev_driver_start(&exec_ctx, r->ev_driver); } } - if (reply != NULL) { + if (reply != nullptr) { ares_free_data(reply); } } else if (!r->success) { @@ -276,15 +276,15 @@ static void on_txt_done_cb(void* arg, int status, int timeouts, 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; + struct ares_txt_ext* result = nullptr; + struct ares_txt_ext* reply = nullptr; 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); if (status != ARES_SUCCESS) goto fail; // Find service config in TXT record. - for (result = reply; result != NULL; result = result->next) { + for (result = reply; result != nullptr; result = result->next) { if (result->record_start && memcmp(result->txt, g_service_config_attribute_prefix, prefix_len) == 0) { @@ -292,12 +292,12 @@ static void on_txt_done_cb(void* arg, int status, int timeouts, } } // Found a service config record. - if (result != NULL) { + if (result != nullptr) { size_t service_config_len = result->length - prefix_len; *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; + for (result = result->next; result != nullptr && !result->record_start; result = result->next) { *r->service_config_json_out = (char*)gpr_realloc( *r->service_config_json_out, service_config_len + result->length + 1); @@ -323,7 +323,7 @@ fail: } done: gpr_mu_unlock(&r->mu); - grpc_ares_request_unref(NULL, r); + grpc_ares_request_unref(nullptr, r); } static grpc_ares_request* grpc_dns_lookup_ares_impl( @@ -332,9 +332,9 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( 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; + grpc_ares_hostbyname_request* hr = nullptr; + grpc_ares_request* r = nullptr; + ares_channel* channel = nullptr; /* 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", @@ -345,13 +345,13 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( char* host; char* port; gpr_split_host_port(name, &host, &port); - if (host == NULL) { + if (host == nullptr) { error = grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"), GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name)); goto error_cleanup; - } else if (port == NULL) { - if (default_port == NULL) { + } else if (port == nullptr) { + if (default_port == nullptr) { error = grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING("no port in name"), GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name)); @@ -375,7 +375,7 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( channel = grpc_ares_ev_driver_get_channel(r->ev_driver); // If dns_server is specified, use it. - if (dns_server != NULL) { + if (dns_server != nullptr) { gpr_log(GPR_INFO, "Using DNS server %s", dns_server); grpc_resolved_address addr; if (grpc_parse_ipv4_hostport(dns_server, &addr, false /* log_errors */)) { @@ -429,7 +429,7 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( r); gpr_free(service_name); } - if (service_config_json != NULL) { + if (service_config_json != nullptr) { grpc_ares_request_ref(r); ares_search(*channel, hr->host, ns_c_in, ns_t_txt, on_txt_done_cb, r); } @@ -444,7 +444,7 @@ error_cleanup: GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); gpr_free(host); gpr_free(port); - return NULL; + return nullptr; } grpc_ares_request* (*grpc_dns_lookup_ares)( @@ -503,8 +503,8 @@ static void on_dns_lookup_done_cb(grpc_exec_ctx* exec_ctx, void* arg, 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; + if (r->lb_addrs == nullptr || r->lb_addrs->num_addresses == 0) { + *resolved_addresses = nullptr; } else { *resolved_addresses = (grpc_resolved_addresses*)gpr_zalloc(sizeof(grpc_resolved_addresses)); @@ -536,10 +536,10 @@ static void grpc_resolve_address_ares_impl(grpc_exec_ctx* exec_ctx, r->on_resolve_address_done = on_done; GRPC_CLOSURE_INIT(&r->on_dns_lookup_done, on_dns_lookup_done_cb, r, grpc_schedule_on_exec_ctx); - grpc_dns_lookup_ares(exec_ctx, NULL /* dns_server */, name, default_port, + grpc_dns_lookup_ares(exec_ctx, nullptr /* dns_server */, name, default_port, interested_parties, &r->on_dns_lookup_done, &r->lb_addrs, false /* check_grpclb */, - NULL /* service_config_json */); + nullptr /* service_config_json */); } void (*grpc_resolve_address_ares)( 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 a57ab66118..589c74807f 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 @@ -100,12 +100,12 @@ static void dns_shutdown_locked(grpc_exec_ctx* exec_ctx, if (r->have_retry_timer) { grpc_timer_cancel(exec_ctx, &r->retry_timer); } - if (r->next_completion != NULL) { - *r->target_result = NULL; + 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")); - r->next_completion = NULL; + r->next_completion = nullptr; } } @@ -150,20 +150,20 @@ static void dns_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, 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; + grpc_channel_args* result = nullptr; 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) { + if (r->addresses != nullptr) { grpc_lb_addresses* addresses = grpc_lb_addresses_create( - r->addresses->naddrs, NULL /* user_data_vtable */); + r->addresses->naddrs, nullptr /* user_data_vtable */); for (size_t i = 0; i < r->addresses->naddrs; ++i) { grpc_lb_addresses_set_address( addresses, i, &r->addresses->addrs[i].addr, r->addresses->addrs[i].len, false /* is_balancer */, - NULL /* balancer_name */, NULL /* user_data */); + nullptr /* balancer_name */, nullptr /* user_data */); } grpc_arg new_arg = grpc_lb_addresses_create_channel_arg(addresses); result = grpc_channel_args_copy_and_add(r->channel_args, &new_arg, 1); @@ -187,7 +187,7 @@ static void dns_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_combiner_scheduler(r->base.combiner)); grpc_timer_init(exec_ctx, &r->retry_timer, next_try, &r->on_retry); } - if (r->resolved_result != NULL) { + if (r->resolved_result != nullptr) { grpc_channel_args_destroy(exec_ctx, r->resolved_result); } r->resolved_result = result; @@ -203,7 +203,7 @@ static void dns_start_resolving_locked(grpc_exec_ctx* exec_ctx, GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GPR_ASSERT(!r->resolving); r->resolving = true; - r->addresses = NULL; + r->addresses = nullptr; grpc_resolve_address( exec_ctx, r->name_to_resolve, r->default_port, r->interested_parties, GRPC_CLOSURE_CREATE(dns_on_resolved_locked, r, @@ -213,20 +213,20 @@ static void dns_start_resolving_locked(grpc_exec_ctx* exec_ctx, static void dns_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, dns_resolver* r) { - if (r->next_completion != NULL && + if (r->next_completion != nullptr && r->resolved_version != r->published_version) { - *r->target_result = r->resolved_result == NULL - ? NULL + *r->target_result = r->resolved_result == nullptr + ? nullptr : grpc_channel_args_copy(r->resolved_result); GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); - r->next_completion = NULL; + r->next_completion = nullptr; r->published_version = r->resolved_version; } } static void dns_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { dns_resolver* r = (dns_resolver*)gr; - if (r->resolved_result != NULL) { + if (r->resolved_result != nullptr) { grpc_channel_args_destroy(exec_ctx, r->resolved_result); } grpc_pollset_set_destroy(exec_ctx, r->interested_parties); @@ -241,7 +241,7 @@ static grpc_resolver* dns_create(grpc_exec_ctx* exec_ctx, const char* default_port) { if (0 != strcmp(args->uri->authority, "")) { gpr_log(GPR_ERROR, "authority based dns uri's not supported"); - return NULL; + return nullptr; } // Get name from args. char* path = args->uri->path; @@ -253,7 +253,7 @@ static grpc_resolver* dns_create(grpc_exec_ctx* exec_ctx, r->default_port = gpr_strdup(default_port); r->channel_args = grpc_channel_args_copy(args->args); r->interested_parties = grpc_pollset_set_create(); - if (args->pollset_set != NULL) { + if (args->pollset_set != nullptr) { grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, args->pollset_set); } @@ -297,13 +297,13 @@ static grpc_resolver_factory* dns_resolver_factory_create() { extern "C" void grpc_resolver_dns_native_init(void) { char* resolver = gpr_getenv("GRPC_DNS_RESOLVER"); - if (resolver != NULL && gpr_stricmp(resolver, "native") == 0) { + if (resolver != nullptr && 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_lookup("dns"); - if (existing_factory == NULL) { + if (existing_factory == nullptr) { gpr_log(GPR_DEBUG, "Using native dns resolver"); grpc_register_resolver_type(dns_resolver_factory_create()); } else { |