| 427 | } |
| 428 | |
| 429 | struct dns_lookup *async_dns_resolve(const tal_t *ctx, |
| 430 | struct timers *timers, |
| 431 | const char *hostname, |
| 432 | u16 port, |
| 433 | dns_result_cb cb, |
| 434 | void *cb_arg) |
| 435 | { |
| 436 | struct dns_lookup *lookup = tal(ctx, struct dns_lookup); |
| 437 | |
| 438 | lookup->timers = timers; |
| 439 | lookup->cb = cb; |
| 440 | lookup->cb_arg = cb_arg; |
| 441 | lookup->hostname = tal_strdup(lookup, hostname); |
| 442 | lookup->port = port; |
| 443 | lookup->addrs = tal_arr(lookup, struct wireaddr, 0); |
| 444 | lookup->err = NULL; |
| 445 | lookup->finished = false; |
| 446 | lookup->queued = false; |
| 447 | lookup->started = false; |
| 448 | list_node_init(&lookup->list); |
| 449 | lookup->child = 0; |
| 450 | lookup->conn = NULL; |
| 451 | lookup->call_timer = NULL; |
| 452 | lookup->in = tal_arr(lookup, u8, 0); |
| 453 | lookup->inode = 0; |
| 454 | lookup->readlen = 0; |
| 455 | /* If ctx dies while we're queued, we must leave the queue. We |
| 456 | * deliberately don't kill a running child here: it may already have |
| 457 | * exited and its pid been recycled (SIGCHLD is ignored), and it |
| 458 | * will die on EPIPE or its own alarm regardless. */ |
| 459 | tal_add_destructor(lookup, destroy_dns_lookup); |
| 460 | |
| 461 | /* The cap spans queueing too: a lookup never takes longer than |
| 462 | * DNS_TOTAL_TIMEOUT_SECS from ask to callback. */ |
| 463 | lookup->total_timer = new_reltimer(timers, lookup, |
| 464 | time_from_sec(DNS_TOTAL_TIMEOUT_SECS), |
| 465 | dns_total_timeout, lookup); |
| 466 | |
| 467 | if (dns_num_active < DNS_MAX_CONCURRENT_LOOKUPS) { |
| 468 | dns_start(lookup); |
| 469 | } else { |
| 470 | status_debug("dns: lookup of %s queued, %u running", |
| 471 | hostname, dns_num_active); |
| 472 | list_add_tail(&dns_queue, &lookup->list); |
| 473 | lookup->queued = true; |
| 474 | } |
| 475 | return lookup; |
| 476 | } |
no test coverage detected