asyn-thread.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "curl_setup.h"
  25. #include "socketpair.h"
  26. /***********************************************************************
  27. * Only for threaded name resolves builds
  28. **********************************************************************/
  29. #ifdef CURLRES_THREADED
  30. #ifdef HAVE_NETINET_IN_H
  31. #include <netinet/in.h>
  32. #endif
  33. #ifdef HAVE_NETDB_H
  34. #include <netdb.h>
  35. #endif
  36. #ifdef HAVE_ARPA_INET_H
  37. #include <arpa/inet.h>
  38. #endif
  39. #ifdef __VMS
  40. #include <in.h>
  41. #include <inet.h>
  42. #endif
  43. #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
  44. # include <pthread.h>
  45. #endif
  46. #ifdef HAVE_GETADDRINFO
  47. # define RESOLVER_ENOMEM EAI_MEMORY
  48. #else
  49. # define RESOLVER_ENOMEM ENOMEM
  50. #endif
  51. #include "urldata.h"
  52. #include "sendf.h"
  53. #include "hostip.h"
  54. #include "hash.h"
  55. #include "share.h"
  56. #include "url.h"
  57. #include "multiif.h"
  58. #include "inet_ntop.h"
  59. #include "curl_threads.h"
  60. #include "connect.h"
  61. /* The last 3 #include files should be in this order */
  62. #include "curl_printf.h"
  63. #include "curl_memory.h"
  64. #include "memdebug.h"
  65. struct resdata {
  66. struct curltime start;
  67. };
  68. /*
  69. * Curl_resolver_global_init()
  70. * Called from curl_global_init() to initialize global resolver environment.
  71. * Does nothing here.
  72. */
  73. int Curl_resolver_global_init(void)
  74. {
  75. return CURLE_OK;
  76. }
  77. /*
  78. * Curl_resolver_global_cleanup()
  79. * Called from curl_global_cleanup() to destroy global resolver environment.
  80. * Does nothing here.
  81. */
  82. void Curl_resolver_global_cleanup(void)
  83. {
  84. }
  85. /*
  86. * Curl_resolver_init()
  87. * Called from curl_easy_init() -> Curl_open() to initialize resolver
  88. * URL-state specific environment ('resolver' member of the UrlState
  89. * structure).
  90. */
  91. CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver)
  92. {
  93. (void)easy;
  94. *resolver = calloc(1, sizeof(struct resdata));
  95. if(!*resolver)
  96. return CURLE_OUT_OF_MEMORY;
  97. return CURLE_OK;
  98. }
  99. /*
  100. * Curl_resolver_cleanup()
  101. * Called from curl_easy_cleanup() -> Curl_close() to cleanup resolver
  102. * URL-state specific environment ('resolver' member of the UrlState
  103. * structure).
  104. */
  105. void Curl_resolver_cleanup(void *resolver)
  106. {
  107. free(resolver);
  108. }
  109. /*
  110. * Curl_resolver_duphandle()
  111. * Called from curl_easy_duphandle() to duplicate resolver URL state-specific
  112. * environment ('resolver' member of the UrlState structure).
  113. */
  114. CURLcode Curl_resolver_duphandle(struct Curl_easy *easy, void **to, void *from)
  115. {
  116. (void)from;
  117. return Curl_resolver_init(easy, to);
  118. }
  119. static void destroy_async_data(struct Curl_async *);
  120. /*
  121. * Cancel all possibly still on-going resolves for this connection.
  122. */
  123. void Curl_resolver_cancel(struct Curl_easy *data)
  124. {
  125. destroy_async_data(&data->state.async);
  126. }
  127. /* This function is used to init a threaded resolve */
  128. static bool init_resolve_thread(struct Curl_easy *data,
  129. const char *hostname, int port,
  130. const struct addrinfo *hints);
  131. /* Data for synchronization between resolver thread and its parent */
  132. struct thread_sync_data {
  133. curl_mutex_t *mtx;
  134. int done;
  135. int port;
  136. char *hostname; /* hostname to resolve, Curl_async.hostname
  137. duplicate */
  138. #ifndef CURL_DISABLE_SOCKETPAIR
  139. struct Curl_easy *data;
  140. curl_socket_t sock_pair[2]; /* socket pair */
  141. #endif
  142. int sock_error;
  143. struct Curl_addrinfo *res;
  144. #ifdef HAVE_GETADDRINFO
  145. struct addrinfo hints;
  146. #endif
  147. struct thread_data *td; /* for thread-self cleanup */
  148. };
  149. struct thread_data {
  150. curl_thread_t thread_hnd;
  151. unsigned int poll_interval;
  152. timediff_t interval_end;
  153. struct thread_sync_data tsd;
  154. };
  155. static struct thread_sync_data *conn_thread_sync_data(struct Curl_easy *data)
  156. {
  157. return &(data->state.async.tdata->tsd);
  158. }
  159. /* Destroy resolver thread synchronization data */
  160. static
  161. void destroy_thread_sync_data(struct thread_sync_data *tsd)
  162. {
  163. if(tsd->mtx) {
  164. Curl_mutex_destroy(tsd->mtx);
  165. free(tsd->mtx);
  166. }
  167. free(tsd->hostname);
  168. if(tsd->res)
  169. Curl_freeaddrinfo(tsd->res);
  170. #ifndef CURL_DISABLE_SOCKETPAIR
  171. /*
  172. * close one end of the socket pair (may be done in resolver thread);
  173. * the other end (for reading) is always closed in the parent thread.
  174. */
  175. if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
  176. sclose(tsd->sock_pair[1]);
  177. }
  178. #endif
  179. memset(tsd, 0, sizeof(*tsd));
  180. }
  181. /* Initialize resolver thread synchronization data */
  182. static
  183. int init_thread_sync_data(struct thread_data *td,
  184. const char *hostname,
  185. int port,
  186. const struct addrinfo *hints)
  187. {
  188. struct thread_sync_data *tsd = &td->tsd;
  189. memset(tsd, 0, sizeof(*tsd));
  190. tsd->td = td;
  191. tsd->port = port;
  192. /* Treat the request as done until the thread actually starts so any early
  193. * cleanup gets done properly.
  194. */
  195. tsd->done = 1;
  196. #ifdef HAVE_GETADDRINFO
  197. DEBUGASSERT(hints);
  198. tsd->hints = *hints;
  199. #else
  200. (void) hints;
  201. #endif
  202. tsd->mtx = malloc(sizeof(curl_mutex_t));
  203. if(!tsd->mtx)
  204. goto err_exit;
  205. Curl_mutex_init(tsd->mtx);
  206. #ifndef CURL_DISABLE_SOCKETPAIR
  207. /* create socket pair, avoid AF_LOCAL since it doesn't build on Solaris */
  208. if(Curl_socketpair(AF_UNIX, SOCK_STREAM, 0, &tsd->sock_pair[0]) < 0) {
  209. tsd->sock_pair[0] = CURL_SOCKET_BAD;
  210. tsd->sock_pair[1] = CURL_SOCKET_BAD;
  211. goto err_exit;
  212. }
  213. #endif
  214. tsd->sock_error = CURL_ASYNC_SUCCESS;
  215. /* Copying hostname string because original can be destroyed by parent
  216. * thread during gethostbyname execution.
  217. */
  218. tsd->hostname = strdup(hostname);
  219. if(!tsd->hostname)
  220. goto err_exit;
  221. return 1;
  222. err_exit:
  223. #ifndef CURL_DISABLE_SOCKETPAIR
  224. if(tsd->sock_pair[0] != CURL_SOCKET_BAD) {
  225. sclose(tsd->sock_pair[0]);
  226. tsd->sock_pair[0] = CURL_SOCKET_BAD;
  227. }
  228. #endif
  229. destroy_thread_sync_data(tsd);
  230. return 0;
  231. }
  232. static CURLcode getaddrinfo_complete(struct Curl_easy *data)
  233. {
  234. struct thread_sync_data *tsd = conn_thread_sync_data(data);
  235. CURLcode result;
  236. result = Curl_addrinfo_callback(data, tsd->sock_error, tsd->res);
  237. /* The tsd->res structure has been copied to async.dns and perhaps the DNS
  238. cache. Set our copy to NULL so destroy_thread_sync_data doesn't free it.
  239. */
  240. tsd->res = NULL;
  241. return result;
  242. }
  243. #ifdef HAVE_GETADDRINFO
  244. /*
  245. * getaddrinfo_thread() resolves a name and then exits.
  246. *
  247. * For builds without ARES, but with ENABLE_IPV6, create a resolver thread
  248. * and wait on it.
  249. */
  250. static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg)
  251. {
  252. struct thread_sync_data *tsd = (struct thread_sync_data *)arg;
  253. struct thread_data *td = tsd->td;
  254. char service[12];
  255. int rc;
  256. #ifndef CURL_DISABLE_SOCKETPAIR
  257. char buf[1];
  258. #endif
  259. msnprintf(service, sizeof(service), "%d", tsd->port);
  260. rc = Curl_getaddrinfo_ex(tsd->hostname, service, &tsd->hints, &tsd->res);
  261. if(rc) {
  262. tsd->sock_error = SOCKERRNO?SOCKERRNO:rc;
  263. if(tsd->sock_error == 0)
  264. tsd->sock_error = RESOLVER_ENOMEM;
  265. }
  266. else {
  267. Curl_addrinfo_set_port(tsd->res, tsd->port);
  268. }
  269. Curl_mutex_acquire(tsd->mtx);
  270. if(tsd->done) {
  271. /* too late, gotta clean up the mess */
  272. Curl_mutex_release(tsd->mtx);
  273. destroy_thread_sync_data(tsd);
  274. free(td);
  275. }
  276. else {
  277. #ifndef CURL_DISABLE_SOCKETPAIR
  278. if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
  279. /* DNS has been resolved, signal client task */
  280. buf[0] = 1;
  281. if(swrite(tsd->sock_pair[1], buf, sizeof(buf)) < 0) {
  282. /* update sock_erro to errno */
  283. tsd->sock_error = SOCKERRNO;
  284. }
  285. }
  286. #endif
  287. tsd->done = 1;
  288. Curl_mutex_release(tsd->mtx);
  289. }
  290. return 0;
  291. }
  292. #else /* HAVE_GETADDRINFO */
  293. /*
  294. * gethostbyname_thread() resolves a name and then exits.
  295. */
  296. static unsigned int CURL_STDCALL gethostbyname_thread(void *arg)
  297. {
  298. struct thread_sync_data *tsd = (struct thread_sync_data *)arg;
  299. struct thread_data *td = tsd->td;
  300. tsd->res = Curl_ipv4_resolve_r(tsd->hostname, tsd->port);
  301. if(!tsd->res) {
  302. tsd->sock_error = SOCKERRNO;
  303. if(tsd->sock_error == 0)
  304. tsd->sock_error = RESOLVER_ENOMEM;
  305. }
  306. Curl_mutex_acquire(tsd->mtx);
  307. if(tsd->done) {
  308. /* too late, gotta clean up the mess */
  309. Curl_mutex_release(tsd->mtx);
  310. destroy_thread_sync_data(tsd);
  311. free(td);
  312. }
  313. else {
  314. tsd->done = 1;
  315. Curl_mutex_release(tsd->mtx);
  316. }
  317. return 0;
  318. }
  319. #endif /* HAVE_GETADDRINFO */
  320. /*
  321. * destroy_async_data() cleans up async resolver data and thread handle.
  322. */
  323. static void destroy_async_data(struct Curl_async *async)
  324. {
  325. if(async->tdata) {
  326. struct thread_data *td = async->tdata;
  327. int done;
  328. #ifndef CURL_DISABLE_SOCKETPAIR
  329. curl_socket_t sock_rd = td->tsd.sock_pair[0];
  330. struct Curl_easy *data = td->tsd.data;
  331. #endif
  332. /*
  333. * if the thread is still blocking in the resolve syscall, detach it and
  334. * let the thread do the cleanup...
  335. */
  336. Curl_mutex_acquire(td->tsd.mtx);
  337. done = td->tsd.done;
  338. td->tsd.done = 1;
  339. Curl_mutex_release(td->tsd.mtx);
  340. if(!done) {
  341. Curl_thread_destroy(td->thread_hnd);
  342. }
  343. else {
  344. if(td->thread_hnd != curl_thread_t_null)
  345. Curl_thread_join(&td->thread_hnd);
  346. destroy_thread_sync_data(&td->tsd);
  347. free(async->tdata);
  348. }
  349. #ifndef CURL_DISABLE_SOCKETPAIR
  350. /*
  351. * ensure CURLMOPT_SOCKETFUNCTION fires CURL_POLL_REMOVE
  352. * before the FD is invalidated to avoid EBADF on EPOLL_CTL_DEL
  353. */
  354. Curl_multi_closed(data, sock_rd);
  355. sclose(sock_rd);
  356. #endif
  357. }
  358. async->tdata = NULL;
  359. free(async->hostname);
  360. async->hostname = NULL;
  361. }
  362. /*
  363. * init_resolve_thread() starts a new thread that performs the actual
  364. * resolve. This function returns before the resolve is done.
  365. *
  366. * Returns FALSE in case of failure, otherwise TRUE.
  367. */
  368. static bool init_resolve_thread(struct Curl_easy *data,
  369. const char *hostname, int port,
  370. const struct addrinfo *hints)
  371. {
  372. struct thread_data *td = calloc(1, sizeof(struct thread_data));
  373. int err = ENOMEM;
  374. struct Curl_async *asp = &data->state.async;
  375. data->state.async.tdata = td;
  376. if(!td)
  377. goto errno_exit;
  378. asp->port = port;
  379. asp->done = FALSE;
  380. asp->status = 0;
  381. asp->dns = NULL;
  382. td->thread_hnd = curl_thread_t_null;
  383. if(!init_thread_sync_data(td, hostname, port, hints)) {
  384. asp->tdata = NULL;
  385. free(td);
  386. goto errno_exit;
  387. }
  388. free(asp->hostname);
  389. asp->hostname = strdup(hostname);
  390. if(!asp->hostname)
  391. goto err_exit;
  392. /* The thread will set this to 1 when complete. */
  393. td->tsd.done = 0;
  394. #ifdef HAVE_GETADDRINFO
  395. td->thread_hnd = Curl_thread_create(getaddrinfo_thread, &td->tsd);
  396. #else
  397. td->thread_hnd = Curl_thread_create(gethostbyname_thread, &td->tsd);
  398. #endif
  399. if(!td->thread_hnd) {
  400. /* The thread never started, so mark it as done here for proper cleanup. */
  401. td->tsd.done = 1;
  402. err = errno;
  403. goto err_exit;
  404. }
  405. return TRUE;
  406. err_exit:
  407. destroy_async_data(asp);
  408. errno_exit:
  409. errno = err;
  410. return FALSE;
  411. }
  412. /*
  413. * 'entry' may be NULL and then no data is returned
  414. */
  415. static CURLcode thread_wait_resolv(struct Curl_easy *data,
  416. struct Curl_dns_entry **entry,
  417. bool report)
  418. {
  419. struct thread_data *td;
  420. CURLcode result = CURLE_OK;
  421. DEBUGASSERT(data);
  422. td = data->state.async.tdata;
  423. DEBUGASSERT(td);
  424. DEBUGASSERT(td->thread_hnd != curl_thread_t_null);
  425. /* wait for the thread to resolve the name */
  426. if(Curl_thread_join(&td->thread_hnd)) {
  427. if(entry)
  428. result = getaddrinfo_complete(data);
  429. }
  430. else
  431. DEBUGASSERT(0);
  432. data->state.async.done = TRUE;
  433. if(entry)
  434. *entry = data->state.async.dns;
  435. if(!data->state.async.dns && report)
  436. /* a name was not resolved, report error */
  437. result = Curl_resolver_error(data);
  438. destroy_async_data(&data->state.async);
  439. if(!data->state.async.dns && report)
  440. connclose(data->conn, "asynch resolve failed");
  441. return result;
  442. }
  443. /*
  444. * Until we gain a way to signal the resolver threads to stop early, we must
  445. * simply wait for them and ignore their results.
  446. */
  447. void Curl_resolver_kill(struct Curl_easy *data)
  448. {
  449. struct thread_data *td = data->state.async.tdata;
  450. /* If we're still resolving, we must wait for the threads to fully clean up,
  451. unfortunately. Otherwise, we can simply cancel to clean up any resolver
  452. data. */
  453. if(td && td->thread_hnd != curl_thread_t_null
  454. && (data->set.quick_exit != 1L))
  455. (void)thread_wait_resolv(data, NULL, FALSE);
  456. else
  457. Curl_resolver_cancel(data);
  458. }
  459. /*
  460. * Curl_resolver_wait_resolv()
  461. *
  462. * Waits for a resolve to finish. This function should be avoided since using
  463. * this risk getting the multi interface to "hang".
  464. *
  465. * If 'entry' is non-NULL, make it point to the resolved dns entry
  466. *
  467. * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved,
  468. * CURLE_OPERATION_TIMEDOUT if a time-out occurred, or other errors.
  469. *
  470. * This is the version for resolves-in-a-thread.
  471. */
  472. CURLcode Curl_resolver_wait_resolv(struct Curl_easy *data,
  473. struct Curl_dns_entry **entry)
  474. {
  475. return thread_wait_resolv(data, entry, TRUE);
  476. }
  477. /*
  478. * Curl_resolver_is_resolved() is called repeatedly to check if a previous
  479. * name resolve request has completed. It should also make sure to time-out if
  480. * the operation seems to take too long.
  481. */
  482. CURLcode Curl_resolver_is_resolved(struct Curl_easy *data,
  483. struct Curl_dns_entry **entry)
  484. {
  485. struct thread_data *td = data->state.async.tdata;
  486. int done = 0;
  487. DEBUGASSERT(entry);
  488. *entry = NULL;
  489. if(!td) {
  490. DEBUGASSERT(td);
  491. return CURLE_COULDNT_RESOLVE_HOST;
  492. }
  493. Curl_mutex_acquire(td->tsd.mtx);
  494. done = td->tsd.done;
  495. Curl_mutex_release(td->tsd.mtx);
  496. if(done) {
  497. getaddrinfo_complete(data);
  498. if(!data->state.async.dns) {
  499. CURLcode result = Curl_resolver_error(data);
  500. destroy_async_data(&data->state.async);
  501. return result;
  502. }
  503. destroy_async_data(&data->state.async);
  504. *entry = data->state.async.dns;
  505. }
  506. else {
  507. /* poll for name lookup done with exponential backoff up to 250ms */
  508. /* should be fine even if this converts to 32 bit */
  509. timediff_t elapsed = Curl_timediff(Curl_now(),
  510. data->progress.t_startsingle);
  511. if(elapsed < 0)
  512. elapsed = 0;
  513. if(td->poll_interval == 0)
  514. /* Start at 1ms poll interval */
  515. td->poll_interval = 1;
  516. else if(elapsed >= td->interval_end)
  517. /* Back-off exponentially if last interval expired */
  518. td->poll_interval *= 2;
  519. if(td->poll_interval > 250)
  520. td->poll_interval = 250;
  521. td->interval_end = elapsed + td->poll_interval;
  522. Curl_expire(data, td->poll_interval, EXPIRE_ASYNC_NAME);
  523. }
  524. return CURLE_OK;
  525. }
  526. int Curl_resolver_getsock(struct Curl_easy *data, curl_socket_t *socks)
  527. {
  528. int ret_val = 0;
  529. timediff_t milli;
  530. timediff_t ms;
  531. struct resdata *reslv = (struct resdata *)data->state.async.resolver;
  532. #ifndef CURL_DISABLE_SOCKETPAIR
  533. struct thread_data *td = data->state.async.tdata;
  534. #else
  535. (void)socks;
  536. #endif
  537. #ifndef CURL_DISABLE_SOCKETPAIR
  538. if(td) {
  539. /* return read fd to client for polling the DNS resolution status */
  540. socks[0] = td->tsd.sock_pair[0];
  541. td->tsd.data = data;
  542. ret_val = GETSOCK_READSOCK(0);
  543. }
  544. else {
  545. #endif
  546. ms = Curl_timediff(Curl_now(), reslv->start);
  547. if(ms < 3)
  548. milli = 0;
  549. else if(ms <= 50)
  550. milli = ms/3;
  551. else if(ms <= 250)
  552. milli = 50;
  553. else
  554. milli = 200;
  555. Curl_expire(data, milli, EXPIRE_ASYNC_NAME);
  556. #ifndef CURL_DISABLE_SOCKETPAIR
  557. }
  558. #endif
  559. return ret_val;
  560. }
  561. #ifndef HAVE_GETADDRINFO
  562. /*
  563. * Curl_getaddrinfo() - for platforms without getaddrinfo
  564. */
  565. struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data,
  566. const char *hostname,
  567. int port,
  568. int *waitp)
  569. {
  570. struct resdata *reslv = (struct resdata *)data->state.async.resolver;
  571. *waitp = 0; /* default to synchronous response */
  572. reslv->start = Curl_now();
  573. /* fire up a new resolver thread! */
  574. if(init_resolve_thread(data, hostname, port, NULL)) {
  575. *waitp = 1; /* expect asynchronous response */
  576. return NULL;
  577. }
  578. failf(data, "getaddrinfo() thread failed");
  579. return NULL;
  580. }
  581. #else /* !HAVE_GETADDRINFO */
  582. /*
  583. * Curl_resolver_getaddrinfo() - for getaddrinfo
  584. */
  585. struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data,
  586. const char *hostname,
  587. int port,
  588. int *waitp)
  589. {
  590. struct addrinfo hints;
  591. int pf = PF_INET;
  592. struct resdata *reslv = (struct resdata *)data->state.async.resolver;
  593. *waitp = 0; /* default to synchronous response */
  594. #ifdef CURLRES_IPV6
  595. if((data->conn->ip_version != CURL_IPRESOLVE_V4) && Curl_ipv6works(data))
  596. /* The stack seems to be IPv6-enabled */
  597. pf = PF_UNSPEC;
  598. #endif /* CURLRES_IPV6 */
  599. memset(&hints, 0, sizeof(hints));
  600. hints.ai_family = pf;
  601. hints.ai_socktype = (data->conn->transport == TRNSPRT_TCP)?
  602. SOCK_STREAM : SOCK_DGRAM;
  603. reslv->start = Curl_now();
  604. /* fire up a new resolver thread! */
  605. if(init_resolve_thread(data, hostname, port, &hints)) {
  606. *waitp = 1; /* expect asynchronous response */
  607. return NULL;
  608. }
  609. failf(data, "getaddrinfo() thread failed to start");
  610. return NULL;
  611. }
  612. #endif /* !HAVE_GETADDRINFO */
  613. CURLcode Curl_set_dns_servers(struct Curl_easy *data,
  614. char *servers)
  615. {
  616. (void)data;
  617. (void)servers;
  618. return CURLE_NOT_BUILT_IN;
  619. }
  620. CURLcode Curl_set_dns_interface(struct Curl_easy *data,
  621. const char *interf)
  622. {
  623. (void)data;
  624. (void)interf;
  625. return CURLE_NOT_BUILT_IN;
  626. }
  627. CURLcode Curl_set_dns_local_ip4(struct Curl_easy *data,
  628. const char *local_ip4)
  629. {
  630. (void)data;
  631. (void)local_ip4;
  632. return CURLE_NOT_BUILT_IN;
  633. }
  634. CURLcode Curl_set_dns_local_ip6(struct Curl_easy *data,
  635. const char *local_ip6)
  636. {
  637. (void)data;
  638. (void)local_ip6;
  639. return CURLE_NOT_BUILT_IN;
  640. }
  641. #endif /* CURLRES_THREADED */