aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/client_config/resolvers/sockaddr_resolver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/client_config/resolvers/sockaddr_resolver.c')
-rw-r--r--src/core/client_config/resolvers/sockaddr_resolver.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/core/client_config/resolvers/sockaddr_resolver.c b/src/core/client_config/resolvers/sockaddr_resolver.c
index 85b1bf2849..ea2df07035 100644
--- a/src/core/client_config/resolvers/sockaddr_resolver.c
+++ b/src/core/client_config/resolvers/sockaddr_resolver.c
@@ -45,7 +45,7 @@
#include <grpc/support/host_port.h>
#include <grpc/support/string_util.h>
-#include "src/core/client_config/lb_policies/pick_first.h"
+#include "src/core/client_config/lb_policy_registry.h"
#include "src/core/iomgr/resolve_address.h"
#include "src/core/support/string.h"
@@ -56,9 +56,8 @@ typedef struct {
gpr_refcount refs;
/** subchannel factory */
grpc_subchannel_factory *subchannel_factory;
- /** load balancing policy factory */
- grpc_lb_policy *(*lb_policy_factory)(grpc_subchannel **subchannels,
- size_t num_subchannels);
+ /** load balancing policy name */
+ char *lb_policy_name;
/** the addresses that we've 'resolved' */
struct sockaddr_storage *addrs;
@@ -122,6 +121,7 @@ static void sockaddr_next(grpc_resolver *resolver,
static void sockaddr_maybe_finish_next_locked(sockaddr_resolver *r) {
grpc_client_config *cfg;
grpc_lb_policy *lb_policy;
+ grpc_lb_policy_args lb_policy_args;
grpc_subchannel **subchannels;
grpc_subchannel_args args;
@@ -136,7 +136,10 @@ static void sockaddr_maybe_finish_next_locked(sockaddr_resolver *r) {
subchannels[i] = grpc_subchannel_factory_create_subchannel(
r->subchannel_factory, &args);
}
- lb_policy = r->lb_policy_factory(subchannels, r->num_addrs);
+ lb_policy_args.subchannels = subchannels;
+ lb_policy_args.num_subchannels = r->num_addrs;
+ lb_policy =
+ grpc_lb_policy_create(r->lb_policy_name, &lb_policy_args);
gpr_free(subchannels);
grpc_client_config_set_lb_policy(cfg, lb_policy);
GRPC_LB_POLICY_UNREF(lb_policy, "unix");
@@ -153,6 +156,7 @@ static void sockaddr_destroy(grpc_resolver *gr) {
grpc_subchannel_factory_unref(r->subchannel_factory);
gpr_free(r->addrs);
gpr_free(r->addrs_len);
+ gpr_free(r->lb_policy_name);
gpr_free(r);
}
@@ -274,9 +278,7 @@ done:
static void do_nothing(void *ignored) {}
static grpc_resolver *sockaddr_create(
- grpc_uri *uri,
- grpc_lb_policy *(*lb_policy_factory)(grpc_subchannel **subchannels,
- size_t num_subchannels),
+ grpc_uri *uri, const char *default_lb_policy_name,
grpc_subchannel_factory *subchannel_factory,
int parse(grpc_uri *uri, struct sockaddr_storage *dst, size_t *len)) {
size_t i;
@@ -293,6 +295,25 @@ static grpc_resolver *sockaddr_create(
r = gpr_malloc(sizeof(sockaddr_resolver));
memset(r, 0, sizeof(*r));
+ r->lb_policy_name = NULL;
+ if (0 != strcmp(uri->query, "")) {
+ gpr_slice query_slice;
+ gpr_slice_buffer query_parts;
+
+ query_slice = gpr_slice_new(uri->query, strlen(uri->query), do_nothing);
+ gpr_slice_buffer_init(&query_parts);
+ gpr_slice_split(query_slice, "=", &query_parts);
+ GPR_ASSERT(query_parts.count == 2);
+ if (0 == gpr_slice_str_cmp(query_parts.slices[0], "lb_policy")) {
+ r->lb_policy_name = gpr_dump_slice(query_parts.slices[1], GPR_DUMP_ASCII);
+ }
+ gpr_slice_buffer_destroy(&query_parts);
+ gpr_slice_unref(query_slice);
+ }
+ if (r->lb_policy_name == NULL) {
+ r->lb_policy_name = gpr_strdup(default_lb_policy_name);
+ }
+
path_slice = gpr_slice_new(uri->path, strlen(uri->path), do_nothing);
gpr_slice_buffer_init(&path_parts);
@@ -323,7 +344,6 @@ static grpc_resolver *sockaddr_create(
gpr_mu_init(&r->mu);
grpc_resolver_init(&r->base, &sockaddr_resolver_vtable);
r->subchannel_factory = subchannel_factory;
- r->lb_policy_factory = lb_policy_factory;
grpc_subchannel_factory_ref(subchannel_factory);
return &r->base;
@@ -341,7 +361,7 @@ static void sockaddr_factory_unref(grpc_resolver_factory *factory) {}
static grpc_resolver *name##_factory_create_resolver( \
grpc_resolver_factory *factory, grpc_uri *uri, \
grpc_subchannel_factory *subchannel_factory) { \
- return sockaddr_create(uri, grpc_create_pick_first_lb_policy, \
+ return sockaddr_create(uri, "pick_first", \
subchannel_factory, parse_##name); \
} \
static const grpc_resolver_factory_vtable name##_factory_vtable = { \