asyn-thread.c 19 KB

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