Address review comments

reviewable/pr7771/r2
Yuchen Zeng 8 years ago
parent 0b4c4fc537
commit 43aa9a12b9
  1. 26
      src/core/ext/resolver/dns/c_ares/dns_resolver_ares.c
  2. 5
      src/core/ext/resolver/dns/c_ares/grpc_ares_ev_driver.h
  3. 22
      src/core/ext/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c

@ -84,14 +84,14 @@ typedef struct {
/** currently resolving addresses */
grpc_resolved_addresses *addresses;
} dns_resolver;
} ares_dns_resolver;
static void dns_ares_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *r);
static void dns_ares_start_resolving_locked(grpc_exec_ctx *exec_ctx,
dns_resolver *r);
ares_dns_resolver *r);
static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
dns_resolver *r);
ares_dns_resolver *r);
static void dns_ares_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *r);
static void dns_ares_channel_saw_error(grpc_exec_ctx *exec_ctx,
@ -106,7 +106,7 @@ static const grpc_resolver_vtable dns_ares_resolver_vtable = {
static void dns_ares_shutdown(grpc_exec_ctx *exec_ctx,
grpc_resolver *resolver) {
dns_resolver *r = (dns_resolver *)resolver;
ares_dns_resolver *r = (ares_dns_resolver *)resolver;
gpr_mu_lock(&r->mu);
if (r->have_retry_timer) {
grpc_timer_cancel(exec_ctx, &r->retry_timer);
@ -122,7 +122,7 @@ static void dns_ares_shutdown(grpc_exec_ctx *exec_ctx,
static void dns_ares_channel_saw_error(grpc_exec_ctx *exec_ctx,
grpc_resolver *resolver) {
dns_resolver *r = (dns_resolver *)resolver;
ares_dns_resolver *r = (ares_dns_resolver *)resolver;
gpr_mu_lock(&r->mu);
if (!r->resolving) {
gpr_backoff_reset(&r->backoff_state);
@ -133,7 +133,7 @@ static void dns_ares_channel_saw_error(grpc_exec_ctx *exec_ctx,
static void dns_ares_on_retry_timer(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) {
dns_resolver *r = arg;
ares_dns_resolver *r = arg;
gpr_mu_lock(&r->mu);
r->have_retry_timer = false;
if (error == GRPC_ERROR_NONE) {
@ -147,7 +147,7 @@ static void dns_ares_on_retry_timer(grpc_exec_ctx *exec_ctx, void *arg,
static void dns_ares_on_resolved(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) {
dns_resolver *r = arg;
ares_dns_resolver *r = arg;
grpc_resolver_result *result = NULL;
gpr_mu_lock(&r->mu);
GPR_ASSERT(r->resolving);
@ -196,7 +196,7 @@ static void dns_ares_on_resolved(grpc_exec_ctx *exec_ctx, void *arg,
static void dns_ares_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
grpc_resolver_result **target_result,
grpc_closure *on_complete) {
dns_resolver *r = (dns_resolver *)resolver;
ares_dns_resolver *r = (ares_dns_resolver *)resolver;
gpr_mu_lock(&r->mu);
GPR_ASSERT(!r->next_completion);
r->next_completion = on_complete;
@ -217,7 +217,7 @@ static void dns_ares_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
}
static void dns_ares_start_resolving_locked(grpc_exec_ctx *exec_ctx,
dns_resolver *r) {
ares_dns_resolver *r) {
GRPC_RESOLVER_REF(&r->base, "dns-resolving");
GPR_ASSERT(!r->resolving);
r->resolving = true;
@ -228,7 +228,7 @@ static void dns_ares_start_resolving_locked(grpc_exec_ctx *exec_ctx,
}
static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
dns_resolver *r) {
ares_dns_resolver *r) {
if (r->next_completion != NULL &&
r->resolved_version != r->published_version) {
*r->target_result = r->resolved_result;
@ -242,7 +242,7 @@ static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
}
static void dns_ares_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
dns_resolver *r = (dns_resolver *)gr;
ares_dns_resolver *r = (ares_dns_resolver *)gr;
gpr_mu_destroy(&r->mu);
grpc_ares_cleanup();
if (r->resolved_result) {
@ -256,7 +256,7 @@ static void dns_ares_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
static grpc_resolver *dns_ares_create(grpc_resolver_args *args,
const char *default_port) {
dns_resolver *r;
ares_dns_resolver *r;
grpc_error *error = GRPC_ERROR_NONE;
char *proxy_name;
// Get name from args.
@ -278,7 +278,7 @@ static grpc_resolver *dns_ares_create(grpc_resolver_args *args,
// Get proxy name, if any.
proxy_name = grpc_get_http_proxy_server();
// Create resolver.
r = gpr_malloc(sizeof(dns_resolver));
r = gpr_malloc(sizeof(ares_dns_resolver));
memset(r, 0, sizeof(*r));
gpr_mu_init(&r->mu);
grpc_resolver_init(&r->base, &dns_ares_resolver_vtable);

@ -60,8 +60,9 @@ ares_channel *grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver *ev_driver);
grpc_error *grpc_ares_ev_driver_create(grpc_ares_ev_driver **ev_driver,
grpc_pollset_set *pollset_set);
/* Destroys \a ev_driver asynchronously. The actual cleanup happens after
grpc_ares_ev_driver_start() is called, or \a ev_driver is already working. */
/* Destroys \a ev_driver asynchronously. If \a ev_driver is already working,
destroys it immediately; otherwise, destroys it once
grpc_ares_ev_driver_start() is called */
void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver *ev_driver);
#endif /* GRPC_NATIVE_ADDRESS_RESOLVE */

@ -75,7 +75,7 @@ struct grpc_ares_ev_driver {
/** a list of grpc_fd that this event driver is currently using. */
fd_node *fds;
/** mutex guarding the reset of the state */
/** mutex guarding the rest of the state */
gpr_mu mu;
/** is this event driver currently working? */
bool working;
@ -90,8 +90,13 @@ grpc_error *grpc_ares_ev_driver_create(grpc_ares_ev_driver **ev_driver,
*ev_driver = gpr_malloc(sizeof(grpc_ares_ev_driver));
status = ares_init(&(*ev_driver)->channel);
if (status != ARES_SUCCESS) {
char *err_msg;
gpr_asprintf(&err_msg, "Failed to init ares channel. C-ares error: %s",
ares_strerror(status));
grpc_error *err = GRPC_ERROR_CREATE(err_msg);
gpr_free(err_msg);
gpr_free(*ev_driver);
return GRPC_ERROR_CREATE("Failed to init ares channel");
return err;
}
gpr_mu_init(&(*ev_driver)->mu);
(*ev_driver)->pollset_set = pollset_set;
@ -133,12 +138,13 @@ static void driver_cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
if (error == GRPC_ERROR_NONE) {
for (i = 0; i < ARES_GETSOCK_MAXNUM; i++) {
ares_process_fd(d->channel, ARES_GETSOCK_READABLE(d->socks_bitmask, i)
? d->socks[i]
: ARES_SOCKET_BAD,
ARES_GETSOCK_WRITABLE(d->socks_bitmask, i)
? d->socks[i]
: ARES_SOCKET_BAD);
ares_socket_t read_fd = ARES_GETSOCK_READABLE(d->socks_bitmask, i)
? d->socks[i]
: ARES_SOCKET_BAD;
ares_socket_t write_fd = ARES_GETSOCK_WRITABLE(d->socks_bitmask, i)
? d->socks[i]
: ARES_SOCKET_BAD;
ares_process_fd(d->channel, read_fd, write_fd);
}
} else {
ares_cancel(d->channel);

Loading…
Cancel
Save