/* * Curl_resolver_wait_resolv() * * waits for a resolve to finish. This function should be avoided since using * this risk getting the multi interface to "hang". * * If 'entry' is non-NULL, make it point to the resolved dns entry * * This is the version for resolves-in-a-thread. */ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn, struct Curl_dns_entry **entry) { struct thread_data *td = (struct thread_data*) conn->async.os_specific; CURLcode result = CURLE_OK; DEBUGASSERT(conn && td); /* wait for the thread to resolve the name */ if(Curl_thread_join(&td->thread_hnd)) result = getaddrinfo_complete(conn); else DEBUGASSERT(0); conn->async.done = TRUE; if(entry) *entry = conn->async.dns; if(!conn->async.dns) /* a name was not resolved, report error */ result = resolver_error(conn); destroy_async_data(&conn->async); if(!conn->async.dns) connclose(conn, "asynch resolve failed"); return result; }
/* * Curl_resolver_is_resolved() is called repeatedly to check if a previous * name resolve request has completed. It should also make sure to time-out if * the operation seems to take too long. */ CURLcode Curl_resolver_is_resolved(struct connectdata *conn, struct Curl_dns_entry **entry) { struct Curl_easy *data = conn->data; struct thread_data *td = (struct thread_data*) conn->async.os_specific; int done = 0; *entry = NULL; if(!td) { DEBUGASSERT(td); return CURLE_COULDNT_RESOLVE_HOST; } Curl_mutex_acquire(td->tsd.mtx); done = td->tsd.done; Curl_mutex_release(td->tsd.mtx); if(done) { getaddrinfo_complete(conn); if(!conn->async.dns) { CURLcode result = resolver_error(conn); destroy_async_data(&conn->async); return result; } destroy_async_data(&conn->async); *entry = conn->async.dns; } else { /* poll for name lookup done with exponential backoff up to 250ms */ timediff_t elapsed = Curl_timediff(Curl_now(), data->progress.t_startsingle); if(elapsed < 0) elapsed = 0; if(td->poll_interval == 0) /* Start at 1ms poll interval */ td->poll_interval = 1; else if(elapsed >= td->interval_end) /* Back-off exponentially if last interval expired */ td->poll_interval *= 2; if(td->poll_interval > 250) td->poll_interval = 250; td->interval_end = elapsed + td->poll_interval; Curl_expire(conn->data, td->poll_interval, EXPIRE_ASYNC_NAME); } return CURLE_OK; }
/* * Curl_resolver_wait_resolv() * * waits for a resolve to finish. This function should be avoided since using * this risk getting the multi interface to "hang". * * If 'entry' is non-NULL, make it point to the resolved dns entry * * This is the version for resolves-in-a-thread. */ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn, struct Curl_dns_entry **entry) { struct thread_data *td = (struct thread_data*) conn->async.os_specific; CURLcode rc = CURLE_OK; DEBUGASSERT(conn && td); /* wait for the thread to resolve the name */ if(Curl_thread_join(&td->thread_hnd)) rc = getaddrinfo_complete(conn); else DEBUGASSERT(0); conn->async.done = TRUE; if(entry) *entry = conn->async.dns; if(!conn->async.dns) { /* a name was not resolved */ if(conn->bits.httpproxy) { resolver_error(conn, "proxy"); rc = CURLE_COULDNT_RESOLVE_PROXY; } else { resolver_error(conn, "host"); rc = CURLE_COULDNT_RESOLVE_HOST; } } destroy_async_data(&conn->async); if(!conn->async.dns) conn->bits.close = TRUE; return (rc); }
static void resolve_cb(struct sockaddr *addr, void *data) { struct remote_context *remote = data; if (addr == NULL) { logger_log(LOG_ERR, "resolve %s failed: %s", remote->client->target_addr, resolver_error(remote->host_query)); remote->stage = XSTAGE_TERMINATE; close_client(remote->client); close_remote(remote); } else { if (verbose) { logger_log(LOG_INFO, "connect to %s", remote->client->target_addr); } remote->addr = *addr; connect_to_remote(remote); } }