|
|
|
@ -41,9 +41,12 @@ |
|
|
|
|
|
|
|
|
|
#include "src/core/ext/client_channel/client_channel.h" |
|
|
|
|
#include "src/core/ext/client_channel/initial_connect_string.h" |
|
|
|
|
#include "src/core/ext/client_channel/parse_address.h" |
|
|
|
|
#include "src/core/ext/client_channel/subchannel_index.h" |
|
|
|
|
#include "src/core/ext/client_channel/uri_parser.h" |
|
|
|
|
#include "src/core/lib/channel/channel_args.h" |
|
|
|
|
#include "src/core/lib/channel/connected_channel.h" |
|
|
|
|
#include "src/core/lib/iomgr/sockaddr_utils.h" |
|
|
|
|
#include "src/core/lib/iomgr/timer.h" |
|
|
|
|
#include "src/core/lib/profiling/timers.h" |
|
|
|
|
#include "src/core/lib/slice/slice_internal.h" |
|
|
|
@ -95,8 +98,6 @@ struct grpc_subchannel { |
|
|
|
|
size_t num_filters; |
|
|
|
|
/** channel arguments */ |
|
|
|
|
grpc_channel_args *args; |
|
|
|
|
/** address to connect to */ |
|
|
|
|
grpc_resolved_address *addr; |
|
|
|
|
|
|
|
|
|
grpc_subchannel_key *key; |
|
|
|
|
|
|
|
|
@ -211,7 +212,6 @@ static void subchannel_destroy(grpc_exec_ctx *exec_ctx, void *arg, |
|
|
|
|
grpc_subchannel *c = arg; |
|
|
|
|
gpr_free((void *)c->filters); |
|
|
|
|
grpc_channel_args_destroy(exec_ctx, c->args); |
|
|
|
|
gpr_free(c->addr); |
|
|
|
|
grpc_slice_unref_internal(exec_ctx, c->initial_connect_string); |
|
|
|
|
grpc_connectivity_state_destroy(exec_ctx, &c->state_tracker); |
|
|
|
|
grpc_connector_unref(exec_ctx, c->connector); |
|
|
|
@ -327,12 +327,22 @@ grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, |
|
|
|
|
} else { |
|
|
|
|
c->filters = NULL; |
|
|
|
|
} |
|
|
|
|
c->addr = gpr_malloc(sizeof(grpc_resolved_address)); |
|
|
|
|
if (args->addr->len) |
|
|
|
|
memcpy(c->addr, args->addr, sizeof(grpc_resolved_address)); |
|
|
|
|
c->pollset_set = grpc_pollset_set_create(); |
|
|
|
|
grpc_set_initial_connect_string(&c->addr, &c->initial_connect_string); |
|
|
|
|
c->args = grpc_channel_args_copy(args->args); |
|
|
|
|
const grpc_arg *addr_arg = |
|
|
|
|
grpc_channel_args_find(args->args, GRPC_ARG_SUBCHANNEL_ADDRESS); |
|
|
|
|
GPR_ASSERT(addr_arg != NULL); // Should have been set by LB policy.
|
|
|
|
|
grpc_resolved_address *addr = gpr_malloc(sizeof(*addr)); |
|
|
|
|
grpc_uri_to_sockaddr(addr_arg->value.string, addr); |
|
|
|
|
grpc_set_initial_connect_string(&addr, &c->initial_connect_string); |
|
|
|
|
static const char *keys_to_remove[] = {GRPC_ARG_SUBCHANNEL_ADDRESS}; |
|
|
|
|
grpc_arg new_arg; |
|
|
|
|
new_arg.key = GRPC_ARG_SUBCHANNEL_ADDRESS; |
|
|
|
|
new_arg.type = GRPC_ARG_STRING; |
|
|
|
|
new_arg.value.string = grpc_sockaddr_to_uri(addr); |
|
|
|
|
gpr_free(addr); |
|
|
|
|
c->args = grpc_channel_args_copy_and_add_and_remove( |
|
|
|
|
args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &new_arg, 1); |
|
|
|
|
gpr_free(new_arg.value.string); |
|
|
|
|
c->root_external_state_watcher.next = c->root_external_state_watcher.prev = |
|
|
|
|
&c->root_external_state_watcher; |
|
|
|
|
grpc_closure_init(&c->connected, subchannel_connected, c, |
|
|
|
@ -385,7 +395,6 @@ static void continue_connect_locked(grpc_exec_ctx *exec_ctx, |
|
|
|
|
grpc_connect_in_args args; |
|
|
|
|
|
|
|
|
|
args.interested_parties = c->pollset_set; |
|
|
|
|
args.addr = c->addr; |
|
|
|
|
args.deadline = c->next_attempt; |
|
|
|
|
args.channel_args = c->args; |
|
|
|
|
args.initial_connect_string = c->initial_connect_string; |
|
|
|
@ -771,3 +780,16 @@ grpc_call_stack *grpc_subchannel_call_get_call_stack( |
|
|
|
|
grpc_subchannel_call *subchannel_call) { |
|
|
|
|
return SUBCHANNEL_CALL_TO_CALL_STACK(subchannel_call); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void grpc_uri_to_sockaddr(char *uri_str, grpc_resolved_address *addr) { |
|
|
|
|
grpc_uri *uri = grpc_uri_parse(uri_str, 0 /* suppress_errors */); |
|
|
|
|
GPR_ASSERT(uri != NULL); |
|
|
|
|
if (strcmp(uri->scheme, "ipv4") == 0) { |
|
|
|
|
GPR_ASSERT(parse_ipv4(uri, addr)); |
|
|
|
|
} else if (strcmp(uri->scheme, "ipv6") == 0) { |
|
|
|
|
GPR_ASSERT(parse_ipv6(uri, addr)); |
|
|
|
|
} else { |
|
|
|
|
GPR_ASSERT(parse_unix(uri, addr)); |
|
|
|
|
} |
|
|
|
|
grpc_uri_destroy(uri); |
|
|
|
|
} |
|
|
|
|