|
|
|
@ -90,15 +90,18 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver); |
|
|
|
|
|
|
|
|
|
static grpc_ares_ev_driver* grpc_ares_ev_driver_ref( |
|
|
|
|
grpc_ares_ev_driver* ev_driver) { |
|
|
|
|
gpr_log(GPR_DEBUG, "Ref ev_driver %" PRIuPTR, (uintptr_t)ev_driver); |
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p Ref ev_driver %p", ev_driver->request, |
|
|
|
|
ev_driver); |
|
|
|
|
gpr_ref(&ev_driver->refs); |
|
|
|
|
return ev_driver; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver* ev_driver) { |
|
|
|
|
gpr_log(GPR_DEBUG, "Unref ev_driver %" PRIuPTR, (uintptr_t)ev_driver); |
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p Unref ev_driver %p", ev_driver->request, |
|
|
|
|
ev_driver); |
|
|
|
|
if (gpr_unref(&ev_driver->refs)) { |
|
|
|
|
gpr_log(GPR_DEBUG, "destroy ev_driver %" PRIuPTR, (uintptr_t)ev_driver); |
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p destroy ev_driver %p", ev_driver->request, |
|
|
|
|
ev_driver); |
|
|
|
|
GPR_ASSERT(ev_driver->fds == nullptr); |
|
|
|
|
GRPC_COMBINER_UNREF(ev_driver->combiner, "free ares event driver"); |
|
|
|
|
ares_destroy(ev_driver->channel); |
|
|
|
@ -108,7 +111,8 @@ static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver* ev_driver) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void fd_node_destroy_locked(fd_node* fdn) { |
|
|
|
|
gpr_log(GPR_DEBUG, "delete fd: %s", fdn->grpc_polled_fd->GetName()); |
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p delete fd: %s", fdn->ev_driver->request, |
|
|
|
|
fdn->grpc_polled_fd->GetName()); |
|
|
|
|
GPR_ASSERT(!fdn->readable_registered); |
|
|
|
|
GPR_ASSERT(!fdn->writable_registered); |
|
|
|
|
GPR_ASSERT(fdn->already_shutdown); |
|
|
|
@ -136,7 +140,7 @@ grpc_error* grpc_ares_ev_driver_create_locked(grpc_ares_ev_driver** ev_driver, |
|
|
|
|
memset(&opts, 0, sizeof(opts)); |
|
|
|
|
opts.flags |= ARES_FLAG_STAYOPEN; |
|
|
|
|
int status = ares_init_options(&(*ev_driver)->channel, &opts, ARES_OPT_FLAGS); |
|
|
|
|
gpr_log(GPR_DEBUG, "grpc_ares_ev_driver_create_locked"); |
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p grpc_ares_ev_driver_create_locked", request); |
|
|
|
|
if (status != ARES_SUCCESS) { |
|
|
|
|
char* err_msg; |
|
|
|
|
gpr_asprintf(&err_msg, "Failed to init ares channel. C-ares error: %s", |
|
|
|
@ -203,8 +207,9 @@ static fd_node* pop_fd_node_locked(fd_node** head, ares_socket_t as) { |
|
|
|
|
static void on_timeout_locked(void* arg, grpc_error* error) { |
|
|
|
|
grpc_ares_ev_driver* driver = static_cast<grpc_ares_ev_driver*>(arg); |
|
|
|
|
GRPC_CARES_TRACE_LOG( |
|
|
|
|
"ev_driver=%p on_timeout_locked. driver->shutting_down=%d. err=%s", |
|
|
|
|
driver, driver->shutting_down, grpc_error_string(error)); |
|
|
|
|
"request:%p ev_driver=%p on_timeout_locked. driver->shutting_down=%d. " |
|
|
|
|
"err=%s", |
|
|
|
|
driver->request, driver, driver->shutting_down, grpc_error_string(error)); |
|
|
|
|
if (!driver->shutting_down && error == GRPC_ERROR_NONE) { |
|
|
|
|
grpc_ares_ev_driver_shutdown_locked(driver); |
|
|
|
|
} |
|
|
|
@ -216,7 +221,8 @@ static void on_readable_locked(void* arg, grpc_error* error) { |
|
|
|
|
grpc_ares_ev_driver* ev_driver = fdn->ev_driver; |
|
|
|
|
const ares_socket_t as = fdn->grpc_polled_fd->GetWrappedAresSocketLocked(); |
|
|
|
|
fdn->readable_registered = false; |
|
|
|
|
gpr_log(GPR_DEBUG, "readable on %s", fdn->grpc_polled_fd->GetName()); |
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p readable on %s", fdn->ev_driver->request, |
|
|
|
|
fdn->grpc_polled_fd->GetName()); |
|
|
|
|
if (error == GRPC_ERROR_NONE) { |
|
|
|
|
do { |
|
|
|
|
ares_process_fd(ev_driver->channel, as, ARES_SOCKET_BAD); |
|
|
|
@ -239,7 +245,8 @@ static void on_writable_locked(void* arg, grpc_error* error) { |
|
|
|
|
grpc_ares_ev_driver* ev_driver = fdn->ev_driver; |
|
|
|
|
const ares_socket_t as = fdn->grpc_polled_fd->GetWrappedAresSocketLocked(); |
|
|
|
|
fdn->writable_registered = false; |
|
|
|
|
gpr_log(GPR_DEBUG, "writable on %s", fdn->grpc_polled_fd->GetName()); |
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p writable on %s", ev_driver->request, |
|
|
|
|
fdn->grpc_polled_fd->GetName()); |
|
|
|
|
if (error == GRPC_ERROR_NONE) { |
|
|
|
|
ares_process_fd(ev_driver->channel, ARES_SOCKET_BAD, as); |
|
|
|
|
} else { |
|
|
|
@ -278,7 +285,8 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { |
|
|
|
|
fdn->grpc_polled_fd = |
|
|
|
|
ev_driver->polled_fd_factory->NewGrpcPolledFdLocked( |
|
|
|
|
socks[i], ev_driver->pollset_set, ev_driver->combiner); |
|
|
|
|
gpr_log(GPR_DEBUG, "new fd: %s", fdn->grpc_polled_fd->GetName()); |
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p new fd: %s", ev_driver->request, |
|
|
|
|
fdn->grpc_polled_fd->GetName()); |
|
|
|
|
fdn->ev_driver = ev_driver; |
|
|
|
|
fdn->readable_registered = false; |
|
|
|
|
fdn->writable_registered = false; |
|
|
|
@ -295,8 +303,9 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { |
|
|
|
|
if (ARES_GETSOCK_READABLE(socks_bitmask, i) && |
|
|
|
|
!fdn->readable_registered) { |
|
|
|
|
grpc_ares_ev_driver_ref(ev_driver); |
|
|
|
|
gpr_log(GPR_DEBUG, "notify read on: %s", |
|
|
|
|
fdn->grpc_polled_fd->GetName()); |
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p notify read on: %s", |
|
|
|
|
ev_driver->request, |
|
|
|
|
fdn->grpc_polled_fd->GetName()); |
|
|
|
|
fdn->grpc_polled_fd->RegisterForOnReadableLocked(&fdn->read_closure); |
|
|
|
|
fdn->readable_registered = true; |
|
|
|
|
} |
|
|
|
@ -304,8 +313,9 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { |
|
|
|
|
// has not been registered with this socket.
|
|
|
|
|
if (ARES_GETSOCK_WRITABLE(socks_bitmask, i) && |
|
|
|
|
!fdn->writable_registered) { |
|
|
|
|
gpr_log(GPR_DEBUG, "notify write on: %s", |
|
|
|
|
fdn->grpc_polled_fd->GetName()); |
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p notify write on: %s", |
|
|
|
|
ev_driver->request, |
|
|
|
|
fdn->grpc_polled_fd->GetName()); |
|
|
|
|
grpc_ares_ev_driver_ref(ev_driver); |
|
|
|
|
fdn->grpc_polled_fd->RegisterForOnWriteableLocked( |
|
|
|
|
&fdn->write_closure); |
|
|
|
@ -332,7 +342,8 @@ static void grpc_ares_notify_on_event_locked(grpc_ares_ev_driver* ev_driver) { |
|
|
|
|
// If the ev driver has no working fd, all the tasks are done.
|
|
|
|
|
if (new_list == nullptr) { |
|
|
|
|
ev_driver->working = false; |
|
|
|
|
gpr_log(GPR_DEBUG, "ev driver stop working"); |
|
|
|
|
GRPC_CARES_TRACE_LOG("request:%p ev driver stop working", |
|
|
|
|
ev_driver->request); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -345,9 +356,9 @@ void grpc_ares_ev_driver_start_locked(grpc_ares_ev_driver* ev_driver) { |
|
|
|
|
? GRPC_MILLIS_INF_FUTURE |
|
|
|
|
: ev_driver->query_timeout_ms + grpc_core::ExecCtx::Get()->Now(); |
|
|
|
|
GRPC_CARES_TRACE_LOG( |
|
|
|
|
"ev_driver=%p grpc_ares_ev_driver_start_locked. timeout in %" PRId64 |
|
|
|
|
" ms", |
|
|
|
|
ev_driver, timeout); |
|
|
|
|
"request:%p ev_driver=%p grpc_ares_ev_driver_start_locked. timeout in " |
|
|
|
|
"%" PRId64 " ms", |
|
|
|
|
ev_driver->request, ev_driver, timeout); |
|
|
|
|
grpc_ares_ev_driver_ref(ev_driver); |
|
|
|
|
grpc_timer_init(&ev_driver->query_timeout, timeout, |
|
|
|
|
&ev_driver->on_timeout_locked); |
|
|
|
|