diff options
author | David Garcia Quintas <dgq@google.com> | 2016-09-23 16:10:19 -0700 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2016-09-23 16:30:22 -0700 |
commit | fa0896bbd0323d18b4e41805510b23d0f42fc34c (patch) | |
tree | 61fd5421abbf280813d5da4efd05e9c357d56342 /src | |
parent | 942c264861dedd8020fc18d65933e8f4f57e3e46 (diff) |
Rewrote handling of default resolver prefix
Diffstat (limited to 'src')
-rw-r--r-- | src/core/ext/client_config/client_config_plugin.c | 6 | ||||
-rw-r--r-- | src/core/ext/client_config/resolver_registry.c | 22 | ||||
-rw-r--r-- | src/core/ext/client_config/resolver_registry.h | 5 |
3 files changed, 19 insertions, 14 deletions
diff --git a/src/core/ext/client_config/client_config_plugin.c b/src/core/ext/client_config/client_config_plugin.c index 5e31613420..dc3629d383 100644 --- a/src/core/ext/client_config/client_config_plugin.c +++ b/src/core/ext/client_config/client_config_plugin.c @@ -43,10 +43,6 @@ #include "src/core/ext/client_config/subchannel_index.h" #include "src/core/lib/surface/channel_init.h" -#ifndef GRPC_DEFAULT_NAME_PREFIX -#define GRPC_DEFAULT_NAME_PREFIX "dns:///" -#endif - static bool append_filter(grpc_channel_stack_builder *builder, void *arg) { return grpc_channel_stack_builder_append_filter( builder, (const grpc_channel_filter *)arg, NULL, NULL); @@ -79,7 +75,7 @@ static bool set_default_host_if_unset(grpc_channel_stack_builder *builder, void grpc_client_config_init(void) { grpc_lb_policy_registry_init(); - grpc_resolver_registry_init(GRPC_DEFAULT_NAME_PREFIX); + grpc_resolver_registry_init(); grpc_subchannel_index_init(); grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MIN, set_default_host_if_unset, NULL); diff --git a/src/core/ext/client_config/resolver_registry.c b/src/core/ext/client_config/resolver_registry.c index b5308a140c..8d8e2d9d8c 100644 --- a/src/core/ext/client_config/resolver_registry.c +++ b/src/core/ext/client_config/resolver_registry.c @@ -40,22 +40,20 @@ #include <grpc/support/string_util.h> #define MAX_RESOLVERS 10 +#define DEFAULT_RESOLVER_PREFIX_MAX_LENGTH 32 static grpc_resolver_factory *g_all_of_the_resolvers[MAX_RESOLVERS]; static int g_number_of_resolvers = 0; -static char *g_default_resolver_prefix; +static char g_default_resolver_prefix[DEFAULT_RESOLVER_PREFIX_MAX_LENGTH] = + "dns:///"; -void grpc_resolver_registry_init(const char *default_resolver_prefix) { - g_default_resolver_prefix = gpr_strdup(default_resolver_prefix); -} +void grpc_resolver_registry_init() {} void grpc_resolver_registry_shutdown(void) { - int i; - for (i = 0; i < g_number_of_resolvers; i++) { + for (int i = 0; i < g_number_of_resolvers; i++) { grpc_resolver_factory_unref(g_all_of_the_resolvers[i]); } - gpr_free(g_default_resolver_prefix); // FIXME(ctiller): this should live in grpc_resolver_registry_init, // however that would have the client_config plugin call this AFTER we start // registering resolvers from third party plugins, and so they'd never show @@ -65,6 +63,14 @@ void grpc_resolver_registry_shutdown(void) { g_number_of_resolvers = 0; } +void grpc_resolver_registry_set_default_prefix( + const char *default_resolver_prefix) { + GPR_ASSERT(strlen(default_resolver_prefix) < + DEFAULT_RESOLVER_PREFIX_MAX_LENGTH); + memcpy(g_default_resolver_prefix, default_resolver_prefix, + DEFAULT_RESOLVER_PREFIX_MAX_LENGTH); +} + void grpc_register_resolver_type(grpc_resolver_factory *factory) { int i; for (i = 0; i < g_number_of_resolvers; i++) { @@ -108,7 +114,7 @@ static grpc_resolver_factory *resolve_factory(const char *target, *uri = grpc_uri_parse(target, 1); factory = lookup_factory_by_uri(*uri); if (factory == NULL) { - if (g_default_resolver_prefix != NULL) { + if (g_default_resolver_prefix[0] != '\0') { grpc_uri_destroy(*uri); gpr_asprintf(&tmp, "%s%s", g_default_resolver_prefix, target); *uri = grpc_uri_parse(tmp, 1); diff --git a/src/core/ext/client_config/resolver_registry.h b/src/core/ext/client_config/resolver_registry.h index 92e248d548..4c6279b978 100644 --- a/src/core/ext/client_config/resolver_registry.h +++ b/src/core/ext/client_config/resolver_registry.h @@ -36,9 +36,12 @@ #include "src/core/ext/client_config/resolver_factory.h" -void grpc_resolver_registry_init(const char *default_prefix); +void grpc_resolver_registry_init(); void grpc_resolver_registry_shutdown(void); +/** Set the default URI prefix to \a default_prefix. */ +void grpc_resolver_registry_set_default_prefix(const char *default_prefix); + /** Register a resolver type. URI's of \a scheme will be resolved with the given resolver. If \a priority is greater than zero, then the resolver will be eligible |