|
|
@ -114,8 +114,6 @@ struct grpc_ares_ev_driver { |
|
|
|
std::shared_ptr<grpc_core::WorkSerializer> work_serializer; |
|
|
|
std::shared_ptr<grpc_core::WorkSerializer> work_serializer; |
|
|
|
/** a list of grpc_fd that this event driver is currently using. */ |
|
|
|
/** a list of grpc_fd that this event driver is currently using. */ |
|
|
|
fd_node* fds; |
|
|
|
fd_node* fds; |
|
|
|
/** is this event driver currently working? */ |
|
|
|
|
|
|
|
bool working; |
|
|
|
|
|
|
|
/** is this event driver being shut down */ |
|
|
|
/** is this event driver being shut down */ |
|
|
|
bool shutting_down; |
|
|
|
bool shutting_down; |
|
|
|
/** request object that's using this ev driver */ |
|
|
|
/** request object that's using this ev driver */ |
|
|
@ -219,9 +217,9 @@ static void fd_node_shutdown_locked(fd_node* fdn, const char* reason) { |
|
|
|
|
|
|
|
|
|
|
|
void grpc_ares_ev_driver_on_queries_complete_locked( |
|
|
|
void grpc_ares_ev_driver_on_queries_complete_locked( |
|
|
|
grpc_ares_ev_driver* ev_driver) { |
|
|
|
grpc_ares_ev_driver* ev_driver) { |
|
|
|
// We mark the event driver as being shut down. If the event driver
|
|
|
|
// We mark the event driver as being shut down.
|
|
|
|
// is working, grpc_ares_notify_on_event_locked will shut down the
|
|
|
|
// grpc_ares_notify_on_event_locked will shut down any remaining
|
|
|
|
// fds; if it's not working, there are no fds to shut down.
|
|
|
|
// fds.
|
|
|
|
ev_driver->shutting_down = true; |
|
|
|
ev_driver->shutting_down = true; |
|
|
|
grpc_timer_cancel(&ev_driver->query_timeout); |
|
|
|
grpc_timer_cancel(&ev_driver->query_timeout); |
|
|
|
grpc_timer_cancel(&ev_driver->ares_backup_poll_alarm); |
|
|
|
grpc_timer_cancel(&ev_driver->ares_backup_poll_alarm); |
|
|
@ -483,43 +481,34 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ev_driver->fds = new_list; |
|
|
|
ev_driver->fds = new_list; |
|
|
|
// If the ev driver has no working fd, all the tasks are done.
|
|
|
|
|
|
|
|
if (new_list == nullptr) { |
|
|
|
|
|
|
|
ev_driver->working = false; |
|
|
|
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p ev driver stop working", |
|
|
|
|
|
|
|
ev_driver->request); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_ares_ev_driver_start_locked(grpc_ares_ev_driver* ev_driver) { |
|
|
|
void grpc_ares_ev_driver_start_locked(grpc_ares_ev_driver* ev_driver) { |
|
|
|
if (!ev_driver->working) { |
|
|
|
grpc_ares_notify_on_event_locked(ev_driver); |
|
|
|
ev_driver->working = true; |
|
|
|
// Initialize overall DNS resolution timeout alarm
|
|
|
|
grpc_ares_notify_on_event_locked(ev_driver); |
|
|
|
grpc_millis timeout = |
|
|
|
// Initialize overall DNS resolution timeout alarm
|
|
|
|
ev_driver->query_timeout_ms == 0 |
|
|
|
grpc_millis timeout = |
|
|
|
? GRPC_MILLIS_INF_FUTURE |
|
|
|
ev_driver->query_timeout_ms == 0 |
|
|
|
: ev_driver->query_timeout_ms + grpc_core::ExecCtx::Get()->Now(); |
|
|
|
? GRPC_MILLIS_INF_FUTURE |
|
|
|
GRPC_CARES_TRACE_LOG( |
|
|
|
: ev_driver->query_timeout_ms + grpc_core::ExecCtx::Get()->Now(); |
|
|
|
"request:%p ev_driver=%p grpc_ares_ev_driver_start_locked. timeout in " |
|
|
|
GRPC_CARES_TRACE_LOG( |
|
|
|
"%" PRId64 " ms", |
|
|
|
"request:%p ev_driver=%p grpc_ares_ev_driver_start_locked. timeout in " |
|
|
|
ev_driver->request, ev_driver, timeout); |
|
|
|
"%" PRId64 " ms", |
|
|
|
grpc_ares_ev_driver_ref(ev_driver); |
|
|
|
ev_driver->request, ev_driver, timeout); |
|
|
|
GRPC_CLOSURE_INIT(&ev_driver->on_timeout_locked, on_timeout, ev_driver, |
|
|
|
grpc_ares_ev_driver_ref(ev_driver); |
|
|
|
grpc_schedule_on_exec_ctx); |
|
|
|
GRPC_CLOSURE_INIT(&ev_driver->on_timeout_locked, on_timeout, ev_driver, |
|
|
|
grpc_timer_init(&ev_driver->query_timeout, timeout, |
|
|
|
grpc_schedule_on_exec_ctx); |
|
|
|
&ev_driver->on_timeout_locked); |
|
|
|
grpc_timer_init(&ev_driver->query_timeout, timeout, |
|
|
|
// Initialize the backup poll alarm
|
|
|
|
&ev_driver->on_timeout_locked); |
|
|
|
grpc_millis next_ares_backup_poll_alarm = |
|
|
|
// Initialize the backup poll alarm
|
|
|
|
calculate_next_ares_backup_poll_alarm_ms(ev_driver); |
|
|
|
grpc_millis next_ares_backup_poll_alarm = |
|
|
|
grpc_ares_ev_driver_ref(ev_driver); |
|
|
|
calculate_next_ares_backup_poll_alarm_ms(ev_driver); |
|
|
|
GRPC_CLOSURE_INIT(&ev_driver->on_ares_backup_poll_alarm_locked, |
|
|
|
grpc_ares_ev_driver_ref(ev_driver); |
|
|
|
on_ares_backup_poll_alarm, ev_driver, |
|
|
|
GRPC_CLOSURE_INIT(&ev_driver->on_ares_backup_poll_alarm_locked, |
|
|
|
grpc_schedule_on_exec_ctx); |
|
|
|
on_ares_backup_poll_alarm, ev_driver, |
|
|
|
grpc_timer_init(&ev_driver->ares_backup_poll_alarm, |
|
|
|
grpc_schedule_on_exec_ctx); |
|
|
|
next_ares_backup_poll_alarm, |
|
|
|
grpc_timer_init(&ev_driver->ares_backup_poll_alarm, |
|
|
|
&ev_driver->on_ares_backup_poll_alarm_locked); |
|
|
|
next_ares_backup_poll_alarm, |
|
|
|
|
|
|
|
&ev_driver->on_ares_backup_poll_alarm_locked); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void noop_inject_channel_config(ares_channel /*channel*/) {} |
|
|
|
static void noop_inject_channel_config(ares_channel /*channel*/) {} |
|
|
@ -551,7 +540,6 @@ grpc_error* grpc_ares_ev_driver_create_locked( |
|
|
|
gpr_ref_init(&(*ev_driver)->refs, 1); |
|
|
|
gpr_ref_init(&(*ev_driver)->refs, 1); |
|
|
|
(*ev_driver)->pollset_set = pollset_set; |
|
|
|
(*ev_driver)->pollset_set = pollset_set; |
|
|
|
(*ev_driver)->fds = nullptr; |
|
|
|
(*ev_driver)->fds = nullptr; |
|
|
|
(*ev_driver)->working = false; |
|
|
|
|
|
|
|
(*ev_driver)->shutting_down = false; |
|
|
|
(*ev_driver)->shutting_down = false; |
|
|
|
(*ev_driver)->request = request; |
|
|
|
(*ev_driver)->request = request; |
|
|
|
(*ev_driver)->polled_fd_factory = |
|
|
|
(*ev_driver)->polled_fd_factory = |
|
|
@ -757,7 +745,7 @@ static void on_srv_query_done_locked(void* arg, int status, int /*timeouts*/, |
|
|
|
r, srv_it->host, htons(srv_it->port), true /* is_balancer */, "A"); |
|
|
|
r, srv_it->host, htons(srv_it->port), true /* is_balancer */, "A"); |
|
|
|
ares_gethostbyname(r->ev_driver->channel, hr->host, AF_INET, |
|
|
|
ares_gethostbyname(r->ev_driver->channel, hr->host, AF_INET, |
|
|
|
on_hostbyname_done_locked, hr); |
|
|
|
on_hostbyname_done_locked, hr); |
|
|
|
grpc_ares_ev_driver_start_locked(r->ev_driver); |
|
|
|
grpc_ares_notify_on_event_locked(r->ev_driver); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (reply != nullptr) { |
|
|
|
if (reply != nullptr) { |
|
|
|