diff options
author | Mark D. Roth <roth@google.com> | 2016-09-19 07:49:29 -0700 |
---|---|---|
committer | Mark D. Roth <roth@google.com> | 2016-09-19 07:49:29 -0700 |
commit | 89675154020e5bdabe654b5b65087fe3935b696a (patch) | |
tree | 9a7b17c7410ef1321e1f675d18a756d6e3c35190 /src/core/ext/resolver | |
parent | 8ce02afd0bb4c7147f8526c14424cb99e3271a65 (diff) | |
parent | f9652f2b84364eb4f8c8272b269e44adbc80733a (diff) |
Merge remote-tracking branch 'upstream/master' into http_connect
Diffstat (limited to 'src/core/ext/resolver')
-rw-r--r-- | src/core/ext/resolver/dns/native/dns_resolver.c | 21 | ||||
-rw-r--r-- | src/core/ext/resolver/sockaddr/sockaddr_resolver.c | 41 |
2 files changed, 25 insertions, 37 deletions
diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 759bd4a699..cc028c3a55 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -173,29 +173,28 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, gpr_mu_lock(&r->mu); GPR_ASSERT(r->resolving); r->resolving = false; - grpc_resolved_addresses *addresses = r->addresses; - if (addresses != NULL) { + if (r->addresses != NULL) { grpc_lb_policy_args lb_policy_args; memset(&lb_policy_args, 0, sizeof(lb_policy_args)); lb_policy_args.server_name = r->target_name; - lb_policy_args.num_addresses = addresses->naddrs; - lb_policy_args.addresses = - gpr_malloc(sizeof(grpc_lb_address) * lb_policy_args.num_addresses); - memset(lb_policy_args.addresses, 0, - sizeof(grpc_lb_address) * lb_policy_args.num_addresses); - for (size_t i = 0; i < addresses->naddrs; ++i) { - lb_policy_args.addresses[i].resolved_address = &r->addresses->addrs[i]; + lb_policy_args.addresses = grpc_lb_addresses_create(r->addresses->naddrs); + for (size_t i = 0; i < r->addresses->naddrs; ++i) { + grpc_lb_addresses_set_address( + lb_policy_args.addresses, i, &r->addresses->addrs[i].addr, + r->addresses->addrs[i].len, false /* is_balancer */, + NULL /* balancer_name */, NULL /* user_data */); } + grpc_resolved_addresses_destroy(r->addresses); lb_policy_args.client_channel_factory = r->client_channel_factory; lb_policy = grpc_lb_policy_create(exec_ctx, r->lb_policy_name, &lb_policy_args); - gpr_free(lb_policy_args.addresses); + grpc_lb_addresses_destroy(lb_policy_args.addresses, + NULL /* user_data_destroy */); result = grpc_resolver_result_create(); if (lb_policy != NULL) { grpc_resolver_result_set_lb_policy(result, lb_policy); GRPC_LB_POLICY_UNREF(exec_ctx, lb_policy, "construction"); } - grpc_resolved_addresses_destroy(addresses); } else { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now); diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index fe2e9bf8bf..34916e10be 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -58,12 +58,12 @@ typedef struct { char *lb_policy_name; /** the addresses that we've 'resolved' */ - grpc_resolved_addresses *addresses; + grpc_lb_addresses *addresses; /** mutex guarding the rest of the state */ gpr_mu mu; /** have we published? */ - int published; + bool published; /** pending next completion, or NULL */ grpc_closure *next_completion; /** target result address for next completion */ @@ -102,7 +102,7 @@ static void sockaddr_channel_saw_error(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver) { sockaddr_resolver *r = (sockaddr_resolver *)resolver; gpr_mu_lock(&r->mu); - r->published = 0; + r->published = false; sockaddr_maybe_finish_next_locked(exec_ctx, r); gpr_mu_unlock(&r->mu); } @@ -126,21 +126,13 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy_args lb_policy_args; memset(&lb_policy_args, 0, sizeof(lb_policy_args)); lb_policy_args.server_name = ""; - lb_policy_args.num_addresses = r->addresses->naddrs; - lb_policy_args.addresses = - gpr_malloc(sizeof(grpc_lb_address) * lb_policy_args.num_addresses); - memset(lb_policy_args.addresses, 0, - sizeof(grpc_lb_address) * lb_policy_args.num_addresses); - for (size_t i = 0; i < lb_policy_args.num_addresses; ++i) { - lb_policy_args.addresses[i].resolved_address = &r->addresses->addrs[i]; - } + lb_policy_args.addresses = r->addresses; lb_policy_args.client_channel_factory = r->client_channel_factory; grpc_lb_policy *lb_policy = grpc_lb_policy_create(exec_ctx, r->lb_policy_name, &lb_policy_args); - gpr_free(lb_policy_args.addresses); grpc_resolver_result_set_lb_policy(result, lb_policy); GRPC_LB_POLICY_UNREF(exec_ctx, lb_policy, "sockaddr"); - r->published = 1; + r->published = true; *r->target_result = result; grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; @@ -151,7 +143,7 @@ static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { sockaddr_resolver *r = (sockaddr_resolver *)gr; gpr_mu_destroy(&r->mu); grpc_client_channel_factory_unref(exec_ctx, r->client_channel_factory); - grpc_resolved_addresses_destroy(r->addresses); + grpc_lb_addresses_destroy(r->addresses, NULL /* user_data_destroy */); gpr_free(r->lb_policy_name); gpr_free(r); } @@ -184,7 +176,7 @@ static void do_nothing(void *ignored) {} static grpc_resolver *sockaddr_create( grpc_resolver_args *args, const char *default_lb_policy_name, int parse(grpc_uri *uri, struct sockaddr_storage *dst, size_t *len)) { - int errors_found = 0; /* GPR_FALSE */ + bool errors_found = false; sockaddr_resolver *r; gpr_slice path_slice; gpr_slice_buffer path_parts; @@ -225,21 +217,18 @@ static grpc_resolver *sockaddr_create( gpr_slice_buffer_init(&path_parts); gpr_slice_split(path_slice, ",", &path_parts); - r->addresses = gpr_malloc(sizeof(grpc_resolved_addresses)); - r->addresses->naddrs = path_parts.count; - r->addresses->addrs = - gpr_malloc(sizeof(grpc_resolved_address) * r->addresses->naddrs); - - for (size_t i = 0; i < r->addresses->naddrs; i++) { + r->addresses = grpc_lb_addresses_create(path_parts.count); + for (size_t i = 0; i < r->addresses->num_addresses; i++) { grpc_uri ith_uri = *args->uri; char *part_str = gpr_dump_slice(path_parts.slices[i], GPR_DUMP_ASCII); ith_uri.path = part_str; - if (!parse(&ith_uri, - (struct sockaddr_storage *)(&r->addresses->addrs[i].addr), - &r->addresses->addrs[i].len)) { - errors_found = 1; /* GPR_TRUE */ + if (!parse(&ith_uri, (struct sockaddr_storage *)(&r->addresses->addresses[i] + .address.addr), + &r->addresses->addresses[i].address.len)) { + errors_found = true; } gpr_free(part_str); + r->addresses->addresses[i].is_balancer = lb_enabled; if (errors_found) break; } @@ -247,7 +236,7 @@ static grpc_resolver *sockaddr_create( gpr_slice_unref(path_slice); if (errors_found) { gpr_free(r->lb_policy_name); - grpc_resolved_addresses_destroy(r->addresses); + grpc_lb_addresses_destroy(r->addresses, NULL /* user_data_destroy */); gpr_free(r); return NULL; } |