asyn-thread.c 19 KB

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