diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 3908547893b..fa33ffd7bd5 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -53,8 +53,6 @@ typedef struct { /** base class: must be first */ grpc_resolver base; - /** refcount */ - gpr_refcount refs; /** target name */ char *target_name; /** name to resolve (usually the same as target_name) */ @@ -260,7 +258,6 @@ static grpc_resolver *dns_create(grpc_resolver_args *args, // Create resolver. dns_resolver *r = gpr_malloc(sizeof(dns_resolver)); memset(r, 0, sizeof(*r)); - gpr_ref_init(&r->refs, 1); gpr_mu_init(&r->mu); grpc_resolver_init(&r->base, &dns_resolver_vtable); r->target_name = gpr_strdup(path); diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index dff0079aad9..5e7dd5e653b 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -51,8 +51,6 @@ typedef struct { /** base class: must be first */ grpc_resolver base; - /** refcount */ - gpr_refcount refs; /** the path component of the uri passed in */ char *target_name; /** the addresses that we've 'resolved' */ @@ -170,25 +168,21 @@ static grpc_resolver *sockaddr_create( args->uri->scheme); return NULL; } - - sockaddr_resolver *r = gpr_malloc(sizeof(sockaddr_resolver)); - memset(r, 0, sizeof(*r)); - r->target_name = gpr_strdup(args->uri->path); - + /* Construct addresses. */ gpr_slice path_slice = gpr_slice_new(args->uri->path, strlen(args->uri->path), do_nothing); gpr_slice_buffer path_parts; gpr_slice_buffer_init(&path_parts); gpr_slice_split(path_slice, ",", &path_parts); - r->addresses = grpc_lb_addresses_create(path_parts.count); + grpc_lb_addresses *addresses = grpc_lb_addresses_create(path_parts.count); bool errors_found = false; - for (size_t i = 0; i < r->addresses->num_addresses; i++) { + for (size_t i = 0; i < 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->addresses[i] + if (!parse(&ith_uri, (struct sockaddr_storage *)(&addresses->addresses[i] .address.addr), - &r->addresses->addresses[i].address.len)) { + &addresses->addresses[i].address.len)) { errors_found = true; } gpr_free(part_str); @@ -197,16 +191,16 @@ static grpc_resolver *sockaddr_create( gpr_slice_buffer_destroy(&path_parts); gpr_slice_unref(path_slice); if (errors_found) { - gpr_free(r->target_name); - grpc_lb_addresses_destroy(r->addresses, NULL /* user_data_destroy */); - gpr_free(r); + grpc_lb_addresses_destroy(addresses, NULL /* user_data_destroy */); return NULL; } - - gpr_ref_init(&r->refs, 1); + /* Instantiate resolver. */ + sockaddr_resolver *r = gpr_malloc(sizeof(sockaddr_resolver)); + memset(r, 0, sizeof(*r)); + r->target_name = gpr_strdup(args->uri->path); + r->addresses = addresses; gpr_mu_init(&r->mu); grpc_resolver_init(&r->base, &sockaddr_resolver_vtable); - return &r->base; } diff --git a/test/core/end2end/fake_resolver.c b/test/core/end2end/fake_resolver.c index 3878952f211..6f7ddfc4493 100644 --- a/test/core/end2end/fake_resolver.c +++ b/test/core/end2end/fake_resolver.c @@ -58,8 +58,6 @@ typedef struct { // base class -- must be first grpc_resolver base; - gpr_refcount refs; - // passed-in parameters char* target_name; // the path component of the uri passed in grpc_lb_addresses* addresses; @@ -159,62 +157,42 @@ static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory, args->uri->scheme); return NULL; } - fake_resolver* r = gpr_malloc(sizeof(fake_resolver)); - memset(r, 0, sizeof(*r)); - r->target_name = gpr_strdup(args->uri->path); - // Initialize LB policy name. - r->lb_policy_name = - gpr_strdup(grpc_uri_get_query_arg(args->uri, "lb_policy")); - if (r->lb_policy_name == NULL) { - r->lb_policy_name = gpr_strdup("pick_first"); - } - // Get lb_enabled arg. + // Get lb_enabled arg. Anything other than "0" is interpreted as true. const char* lb_enabled_qpart = grpc_uri_get_query_arg(args->uri, "lb_enabled"); - // Anything other than "0" is interpreted as true. const bool lb_enabled = lb_enabled_qpart != NULL && strcmp("0", lb_enabled_qpart) != 0; - if (strcmp("grpclb", r->lb_policy_name) == 0 && !lb_enabled) { - // we want grpclb but the "resolved" addresses aren't LB enabled. Bail - // out, as this is meant mostly for tests. - gpr_log(GPR_ERROR, - "Requested 'grpclb' LB policy but resolved addresses don't " - "support load balancing."); - abort(); - } // Construct addresses. gpr_slice path_slice = gpr_slice_new(args->uri->path, strlen(args->uri->path), do_nothing); gpr_slice_buffer path_parts; gpr_slice_buffer_init(&path_parts); gpr_slice_split(path_slice, ",", &path_parts); - r->addresses = grpc_lb_addresses_create(path_parts.count); + grpc_lb_addresses* addresses = grpc_lb_addresses_create(path_parts.count); bool errors_found = false; - for (size_t i = 0; i < r->addresses->num_addresses; i++) { + for (size_t i = 0; i < 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_ipv4(&ith_uri, - (struct sockaddr_storage*)(&r->addresses->addresses[i] + (struct sockaddr_storage*)(&addresses->addresses[i] .address.addr), - &r->addresses->addresses[i].address.len)) { + &addresses->addresses[i].address.len)) { errors_found = true; } gpr_free(part_str); - r->addresses->addresses[i].is_balancer = lb_enabled; + addresses->addresses[i].is_balancer = lb_enabled; if (errors_found) break; } gpr_slice_buffer_destroy(&path_parts); gpr_slice_unref(path_slice); if (errors_found) { - gpr_free(r->lb_policy_name); - gpr_free(r->target_name); - grpc_lb_addresses_destroy(r->addresses, NULL /* user_data_destroy */); - gpr_free(r); + grpc_lb_addresses_destroy(addresses, NULL /* user_data_destroy */); return NULL; } // Construct method config table. // We only support parameters for a single method. + grpc_method_config_table* method_config_table = NULL; const char* method_name = grpc_uri_get_query_arg(args->uri, "method_name"); if (method_name != NULL) { const char* wait_for_ready_str = @@ -247,11 +225,18 @@ static grpc_resolver* fake_resolver_create(grpc_resolver_factory* factory, : &max_response_message_bytes); grpc_method_config_table_entry entry = {grpc_mdstr_from_string(method_name), method_config}; - r->method_config_table = grpc_method_config_table_create(1, &entry); + method_config_table = grpc_method_config_table_create(1, &entry); GRPC_MDSTR_UNREF(entry.method_name); grpc_method_config_unref(method_config); } - gpr_ref_init(&r->refs, 1); + // Instantiate resolver. + fake_resolver* r = gpr_malloc(sizeof(fake_resolver)); + memset(r, 0, sizeof(*r)); + r->target_name = gpr_strdup(args->uri->path); + r->addresses = addresses; + r->lb_policy_name = + gpr_strdup(grpc_uri_get_query_arg(args->uri, "lb_policy")); + r->method_config_table = method_config_table; gpr_mu_init(&r->mu); grpc_resolver_init(&r->base, &fake_resolver_vtable); return &r->base;