Add grpc_customized_resolve_address

pull/7704/head
Yuchen Zeng 8 years ago
parent 85750b08f2
commit 10c1d5af31
  1. 7
      src/core/lib/iomgr/resolve_address.h
  2. 22
      src/core/lib/iomgr/resolve_address_posix.c
  3. 22
      src/core/lib/iomgr/resolve_address_windows.c
  4. 2
      test/core/client_config/resolvers/dns_resolver_connectivity_test.c
  5. 8
      test/core/end2end/goaway_server_test.c

@ -66,4 +66,11 @@ extern grpc_error *(*grpc_blocking_resolve_address)(
const char *name, const char *default_port,
grpc_resolved_addresses **addresses);
/* Returns GRPC_ERROR_CANCELLED by default. If it's overriden and returns
error other than GRPC_ERROR_CANCELLED, grpc_resolve_address will use its
result. Result must be freed with grpc_resolved_addresses_destroy. */
extern grpc_error *(*grpc_customized_resolve_address)(
const char *name, const char *default_port,
grpc_resolved_addresses **addresses);
#endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H */

@ -149,6 +149,17 @@ grpc_error *(*grpc_blocking_resolve_address)(
const char *name, const char *default_port,
grpc_resolved_addresses **addresses) = blocking_resolve_address_impl;
static grpc_error *default_customized_resolve_address_impl(
const char *name, const char *default_port,
grpc_resolved_addresses **addresses) {
return GRPC_ERROR_CANCELLED;
}
grpc_error *(*grpc_customized_resolve_address)(
const char *name, const char *default_port,
grpc_resolved_addresses **addresses) =
default_customized_resolve_address_impl;
typedef struct {
char *name;
char *default_port;
@ -183,7 +194,16 @@ static void resolve_address_impl(grpc_exec_ctx *exec_ctx, const char *name,
const char *default_port,
grpc_closure *on_done,
grpc_resolved_addresses **addrs) {
request *r = gpr_malloc(sizeof(request));
request *r;
grpc_error *err;
if ((err = grpc_customized_resolve_address(name, default_port, addrs)) !=
GRPC_ERROR_CANCELLED) {
grpc_exec_ctx_sched(exec_ctx, on_done, err, NULL);
return;
}
r = gpr_malloc(sizeof(request));
grpc_closure_init(&r->request_closure, do_request_thread, r);
r->name = gpr_strdup(name);
r->default_port = gpr_strdup(default_port);

@ -143,6 +143,17 @@ grpc_error *(*grpc_blocking_resolve_address)(
const char *name, const char *default_port,
grpc_resolved_addresses **addresses) = blocking_resolve_address_impl;
static grpc_error *default_customized_resolve_address_impl(
const char *name, const char *default_port,
grpc_resolved_addresses **addresses) {
return GRPC_ERROR_CANCELLED;
}
grpc_error *(*grpc_customized_resolve_address)(
const char *name, const char *default_port,
grpc_resolved_addresses **addresses) =
default_customized_resolve_address_impl;
/* Callback to be passed to grpc_executor to asynch-ify
* grpc_blocking_resolve_address */
static void do_request_thread(grpc_exec_ctx *exec_ctx, void *rp,
@ -171,7 +182,16 @@ static void resolve_address_impl(grpc_exec_ctx *exec_ctx, const char *name,
const char *default_port,
grpc_closure *on_done,
grpc_resolved_addresses **addresses) {
request *r = gpr_malloc(sizeof(request));
request *r;
grpc_error *err;
if ((err = grpc_customized_resolve_address(name, default_port, addrs)) !=
GRPC_ERROR_CANCELLED) {
grpc_exec_ctx_sched(exec_ctx, on_done, err, NULL);
return;
}
r = gpr_malloc(sizeof(request));
grpc_closure_init(&r->request_closure, do_request_thread, r);
r->name = gpr_strdup(name);
r->default_port = gpr_strdup(default_port);

@ -123,7 +123,7 @@ int main(int argc, char **argv) {
grpc_init();
gpr_mu_init(&g_mu);
grpc_blocking_resolve_address = my_resolve_address;
grpc_customized_resolve_address = my_resolve_address;
grpc_resolver *resolver = create_resolver("dns:test");

@ -46,9 +46,6 @@ static void *tag(intptr_t i) { return (void *)i; }
static gpr_mu g_mu;
static int g_resolve_port = -1;
static grpc_error *(*iomgr_resolve_address)(const char *name,
const char *default_port,
grpc_resolved_addresses **addrs);
static void set_resolve_port(int port) {
gpr_mu_lock(&g_mu);
@ -59,7 +56,7 @@ static void set_resolve_port(int port) {
static grpc_error *my_resolve_address(const char *name, const char *addr,
grpc_resolved_addresses **addrs) {
if (0 != strcmp(name, "test")) {
return iomgr_resolve_address(name, addr, addrs);
return GRPC_ERROR_CANCELLED;
}
gpr_mu_lock(&g_mu);
@ -90,8 +87,7 @@ int main(int argc, char **argv) {
grpc_test_init(argc, argv);
gpr_mu_init(&g_mu);
iomgr_resolve_address = grpc_blocking_resolve_address;
grpc_blocking_resolve_address = my_resolve_address;
grpc_customized_resolve_address = my_resolve_address;
grpc_init();
int was_cancelled1;

Loading…
Cancel
Save