diff options
author | Mark D. Roth <roth@google.com> | 2016-10-21 14:19:50 -0700 |
---|---|---|
committer | Mark D. Roth <roth@google.com> | 2016-10-21 14:19:50 -0700 |
commit | 5bd7be0c55d4149cc6e2d5ee90f33fe5f7f6a7de (patch) | |
tree | 957598f8579c5b1dcd6eb43e580921776368a42e /src/core/ext/lb_policy/pick_first | |
parent | 3686996786faa2671e487707c78b32c0e4a63d80 (diff) |
Change LB policies to get their input from channel args.
Diffstat (limited to 'src/core/ext/lb_policy/pick_first')
-rw-r--r-- | src/core/ext/lb_policy/pick_first/pick_first.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/core/ext/lb_policy/pick_first/pick_first.c b/src/core/ext/lb_policy/pick_first/pick_first.c index 3683079cf4..d95f0310b6 100644 --- a/src/core/ext/lb_policy/pick_first/pick_first.c +++ b/src/core/ext/lb_policy/pick_first/pick_first.c @@ -34,7 +34,9 @@ #include <string.h> #include <grpc/support/alloc.h> + #include "src/core/ext/client_config/lb_policy_registry.h" +#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/transport/connectivity_state.h" typedef struct pending_pick { @@ -432,14 +434,23 @@ static void pick_first_factory_unref(grpc_lb_policy_factory *factory) {} static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, grpc_lb_policy_factory *factory, grpc_lb_policy_args *args) { - GPR_ASSERT(args->addresses != NULL); GPR_ASSERT(args->client_channel_factory != NULL); + /* Get server name. */ + const grpc_arg* arg = + grpc_channel_args_find(args->args, GRPC_ARG_SERVER_NAME); + const char* server_name = + arg != NULL && arg->type == GRPC_ARG_STRING + ? arg->value.string : NULL; + /* Find the number of backend addresses. We ignore balancer * addresses, since we don't know how to handle them. */ + arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); + GPR_ASSERT(arg != NULL && arg->type == GRPC_ARG_POINTER); + grpc_lb_addresses* addresses = arg->value.pointer.p; size_t num_addrs = 0; - for (size_t i = 0; i < args->addresses->num_addresses; i++) { - if (!args->addresses->addresses[i].is_balancer) ++num_addrs; + for (size_t i = 0; i < addresses->num_addresses; i++) { + if (!addresses->addresses[i].is_balancer) ++num_addrs; } if (num_addrs == 0) return NULL; @@ -450,22 +461,22 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, memset(p->subchannels, 0, sizeof(*p->subchannels) * num_addrs); grpc_subchannel_args sc_args; size_t subchannel_idx = 0; - for (size_t i = 0; i < args->addresses->num_addresses; i++) { + for (size_t i = 0; i < addresses->num_addresses; i++) { /* Skip balancer addresses, since we only know how to handle backends. */ - if (args->addresses->addresses[i].is_balancer) continue; + if (addresses->addresses[i].is_balancer) continue; - if (args->addresses->addresses[i].user_data != NULL) { + if (addresses->addresses[i].user_data != NULL) { gpr_log(GPR_ERROR, "This LB policy doesn't support user data. It will be ignored"); } memset(&sc_args, 0, sizeof(grpc_subchannel_args)); /* server_name will be copied as part of the subchannel creation. This makes - * the copying of args->server_name (a borrowed pointer) OK. */ - sc_args.server_name = args->server_name; + * the copying of server_name (a borrowed pointer) OK. */ + sc_args.server_name = server_name; sc_args.addr = - (struct sockaddr *)(&args->addresses->addresses[i].address.addr); - sc_args.addr_len = args->addresses->addresses[i].address.len; + (struct sockaddr *)(&addresses->addresses[i].address.addr); + sc_args.addr_len = addresses->addresses[i].address.len; sc_args.args = args->args; grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( |