asyn-thread.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  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]; /* eventfd/pipes/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. #ifndef USE_EVENTFD
  176. if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
  177. wakeup_close(tsd->sock_pair[1]);
  178. }
  179. #endif
  180. #endif
  181. memset(tsd, 0, sizeof(*tsd));
  182. }
  183. /* Initialize resolver thread synchronization data */
  184. static
  185. int init_thread_sync_data(struct thread_data *td,
  186. const char *hostname,
  187. int port,
  188. const struct addrinfo *hints)
  189. {
  190. struct thread_sync_data *tsd = &td->tsd;
  191. memset(tsd, 0, sizeof(*tsd));
  192. tsd->td = td;
  193. tsd->port = port;
  194. /* Treat the request as done until the thread actually starts so any early
  195. * cleanup gets done properly.
  196. */
  197. tsd->done = 1;
  198. #ifdef HAVE_GETADDRINFO
  199. DEBUGASSERT(hints);
  200. tsd->hints = *hints;
  201. #else
  202. (void) hints;
  203. #endif
  204. tsd->mtx = malloc(sizeof(curl_mutex_t));
  205. if(!tsd->mtx)
  206. goto err_exit;
  207. Curl_mutex_init(tsd->mtx);
  208. #ifndef CURL_DISABLE_SOCKETPAIR
  209. /* create socket pair or pipe */
  210. if(wakeup_create(tsd->sock_pair, FALSE) < 0) {
  211. tsd->sock_pair[0] = CURL_SOCKET_BAD;
  212. tsd->sock_pair[1] = CURL_SOCKET_BAD;
  213. goto err_exit;
  214. }
  215. #endif
  216. tsd->sock_error = CURL_ASYNC_SUCCESS;
  217. /* Copying hostname string because original can be destroyed by parent
  218. * thread during gethostbyname execution.
  219. */
  220. tsd->hostname = strdup(hostname);
  221. if(!tsd->hostname)
  222. goto err_exit;
  223. return 1;
  224. err_exit:
  225. #ifndef CURL_DISABLE_SOCKETPAIR
  226. if(tsd->sock_pair[0] != CURL_SOCKET_BAD) {
  227. wakeup_close(tsd->sock_pair[0]);
  228. tsd->sock_pair[0] = CURL_SOCKET_BAD;
  229. }
  230. #endif
  231. destroy_thread_sync_data(tsd);
  232. return 0;
  233. }
  234. static CURLcode getaddrinfo_complete(struct Curl_easy *data)
  235. {
  236. struct thread_sync_data *tsd = conn_thread_sync_data(data);
  237. CURLcode result;
  238. result = Curl_addrinfo_callback(data, tsd->sock_error, tsd->res);
  239. /* The tsd->res structure has been copied to async.dns and perhaps the DNS
  240. cache. Set our copy to NULL so destroy_thread_sync_data does not free it.
  241. */
  242. tsd->res = NULL;
  243. return result;
  244. }
  245. #ifdef HAVE_GETADDRINFO
  246. /*
  247. * getaddrinfo_thread() resolves a name and then exits.
  248. *
  249. * For builds without ARES, but with USE_IPV6, create a resolver thread
  250. * and wait on it.
  251. */
  252. static
  253. #if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
  254. DWORD
  255. #else
  256. unsigned int
  257. #endif
  258. CURL_STDCALL getaddrinfo_thread(void *arg)
  259. {
  260. struct thread_sync_data *tsd = (struct thread_sync_data *)arg;
  261. struct thread_data *td = tsd->td;
  262. char service[12];
  263. int rc;
  264. #ifndef CURL_DISABLE_SOCKETPAIR
  265. #ifdef USE_EVENTFD
  266. const void *buf;
  267. const uint64_t val = 1;
  268. #else
  269. char buf[1];
  270. #endif
  271. #endif
  272. msnprintf(service, sizeof(service), "%d", tsd->port);
  273. rc = Curl_getaddrinfo_ex(tsd->hostname, service, &tsd->hints, &tsd->res);
  274. if(rc) {
  275. tsd->sock_error = SOCKERRNO ? SOCKERRNO : rc;
  276. if(tsd->sock_error == 0)
  277. tsd->sock_error = RESOLVER_ENOMEM;
  278. }
  279. else {
  280. Curl_addrinfo_set_port(tsd->res, tsd->port);
  281. }
  282. Curl_mutex_acquire(tsd->mtx);
  283. if(tsd->done) {
  284. /* too late, gotta clean up the mess */
  285. Curl_mutex_release(tsd->mtx);
  286. destroy_thread_sync_data(tsd);
  287. free(td);
  288. }
  289. else {
  290. #ifndef CURL_DISABLE_SOCKETPAIR
  291. if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
  292. #ifdef USE_EVENTFD
  293. buf = &val;
  294. #else
  295. buf[0] = 1;
  296. #endif
  297. /* DNS has been resolved, signal client task */
  298. if(wakeup_write(tsd->sock_pair[1], buf, sizeof(buf)) < 0) {
  299. /* update sock_erro to errno */
  300. tsd->sock_error = SOCKERRNO;
  301. }
  302. }
  303. #endif
  304. tsd->done = 1;
  305. Curl_mutex_release(tsd->mtx);
  306. }
  307. return 0;
  308. }
  309. #else /* HAVE_GETADDRINFO */
  310. /*
  311. * gethostbyname_thread() resolves a name and then exits.
  312. */
  313. static
  314. #if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
  315. DWORD
  316. #else
  317. unsigned int
  318. #endif
  319. CURL_STDCALL gethostbyname_thread(void *arg)
  320. {
  321. struct thread_sync_data *tsd = (struct thread_sync_data *)arg;
  322. struct thread_data *td = tsd->td;
  323. tsd->res = Curl_ipv4_resolve_r(tsd->hostname, tsd->port);
  324. if(!tsd->res) {
  325. tsd->sock_error = SOCKERRNO;
  326. if(tsd->sock_error == 0)
  327. tsd->sock_error = RESOLVER_ENOMEM;
  328. }
  329. Curl_mutex_acquire(tsd->mtx);
  330. if(tsd->done) {
  331. /* too late, gotta clean up the mess */
  332. Curl_mutex_release(tsd->mtx);
  333. destroy_thread_sync_data(tsd);
  334. free(td);
  335. }
  336. else {
  337. tsd->done = 1;
  338. Curl_mutex_release(tsd->mtx);
  339. }
  340. return 0;
  341. }
  342. #endif /* HAVE_GETADDRINFO */
  343. /*
  344. * destroy_async_data() cleans up async resolver data and thread handle.
  345. */
  346. static void destroy_async_data(struct Curl_async *async)
  347. {
  348. if(async->tdata) {
  349. struct thread_data *td = async->tdata;
  350. int done;
  351. #ifndef CURL_DISABLE_SOCKETPAIR
  352. curl_socket_t sock_rd = td->tsd.sock_pair[0];
  353. struct Curl_easy *data = td->tsd.data;
  354. #endif
  355. /*
  356. * if the thread is still blocking in the resolve syscall, detach it and
  357. * let the thread do the cleanup...
  358. */
  359. Curl_mutex_acquire(td->tsd.mtx);
  360. done = td->tsd.done;
  361. td->tsd.done = 1;
  362. Curl_mutex_release(td->tsd.mtx);
  363. if(!done) {
  364. Curl_thread_destroy(td->thread_hnd);
  365. }
  366. else {
  367. if(td->thread_hnd != curl_thread_t_null)
  368. Curl_thread_join(&td->thread_hnd);
  369. destroy_thread_sync_data(&td->tsd);
  370. free(async->tdata);
  371. }
  372. #ifndef CURL_DISABLE_SOCKETPAIR
  373. /*
  374. * ensure CURLMOPT_SOCKETFUNCTION fires CURL_POLL_REMOVE
  375. * before the FD is invalidated to avoid EBADF on EPOLL_CTL_DEL
  376. */
  377. Curl_multi_closed(data, sock_rd);
  378. wakeup_close(sock_rd);
  379. #endif
  380. }
  381. async->tdata = NULL;
  382. free(async->hostname);
  383. async->hostname = NULL;
  384. }
  385. /*
  386. * init_resolve_thread() starts a new thread that performs the actual
  387. * resolve. This function returns before the resolve is done.
  388. *
  389. * Returns FALSE in case of failure, otherwise TRUE.
  390. */
  391. static bool init_resolve_thread(struct Curl_easy *data,
  392. const char *hostname, int port,
  393. const struct addrinfo *hints)
  394. {
  395. struct thread_data *td = calloc(1, sizeof(struct thread_data));
  396. int err = ENOMEM;
  397. struct Curl_async *asp = &data->state.async;
  398. data->state.async.tdata = td;
  399. if(!td)
  400. goto errno_exit;
  401. asp->port = port;
  402. asp->done = FALSE;
  403. asp->status = 0;
  404. asp->dns = NULL;
  405. td->thread_hnd = curl_thread_t_null;
  406. if(!init_thread_sync_data(td, hostname, port, hints)) {
  407. asp->tdata = NULL;
  408. free(td);
  409. goto errno_exit;
  410. }
  411. free(asp->hostname);
  412. asp->hostname = strdup(hostname);
  413. if(!asp->hostname)
  414. goto err_exit;
  415. /* The thread will set this to 1 when complete. */
  416. td->tsd.done = 0;
  417. #ifdef HAVE_GETADDRINFO
  418. td->thread_hnd = Curl_thread_create(getaddrinfo_thread, &td->tsd);
  419. #else
  420. td->thread_hnd = Curl_thread_create(gethostbyname_thread, &td->tsd);
  421. #endif
  422. if(td->thread_hnd == curl_thread_t_null) {
  423. /* The thread never started, so mark it as done here for proper cleanup. */
  424. td->tsd.done = 1;
  425. err = errno;
  426. goto err_exit;
  427. }
  428. return TRUE;
  429. err_exit:
  430. destroy_async_data(asp);
  431. errno_exit:
  432. errno = err;
  433. return FALSE;
  434. }
  435. /*
  436. * 'entry' may be NULL and then no data is returned
  437. */
  438. static CURLcode thread_wait_resolv(struct Curl_easy *data,
  439. struct Curl_dns_entry **entry,
  440. bool report)
  441. {
  442. struct thread_data *td;
  443. CURLcode result = CURLE_OK;
  444. DEBUGASSERT(data);
  445. td = data->state.async.tdata;
  446. DEBUGASSERT(td);
  447. DEBUGASSERT(td->thread_hnd != curl_thread_t_null);
  448. /* wait for the thread to resolve the name */
  449. if(Curl_thread_join(&td->thread_hnd)) {
  450. if(entry)
  451. result = getaddrinfo_complete(data);
  452. }
  453. else
  454. DEBUGASSERT(0);
  455. data->state.async.done = TRUE;
  456. if(entry)
  457. *entry = data->state.async.dns;
  458. if(!data->state.async.dns && report)
  459. /* a name was not resolved, report error */
  460. result = Curl_resolver_error(data);
  461. destroy_async_data(&data->state.async);
  462. if(!data->state.async.dns && report)
  463. connclose(data->conn, "asynch resolve failed");
  464. return result;
  465. }
  466. /*
  467. * Until we gain a way to signal the resolver threads to stop early, we must
  468. * simply wait for them and ignore their results.
  469. */
  470. void Curl_resolver_kill(struct Curl_easy *data)
  471. {
  472. struct thread_data *td = data->state.async.tdata;
  473. /* If we are still resolving, we must wait for the threads to fully clean up,
  474. unfortunately. Otherwise, we can simply cancel to clean up any resolver
  475. data. */
  476. if(td && td->thread_hnd != curl_thread_t_null
  477. && (data->set.quick_exit != 1L))
  478. (void)thread_wait_resolv(data, NULL, FALSE);
  479. else
  480. Curl_resolver_cancel(data);
  481. }
  482. /*
  483. * Curl_resolver_wait_resolv()
  484. *
  485. * Waits for a resolve to finish. This function should be avoided since using
  486. * this risk getting the multi interface to "hang".
  487. *
  488. * If 'entry' is non-NULL, make it point to the resolved dns entry
  489. *
  490. * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved,
  491. * CURLE_OPERATION_TIMEDOUT if a time-out occurred, or other errors.
  492. *
  493. * This is the version for resolves-in-a-thread.
  494. */
  495. CURLcode Curl_resolver_wait_resolv(struct Curl_easy *data,
  496. struct Curl_dns_entry **entry)
  497. {
  498. return thread_wait_resolv(data, entry, TRUE);
  499. }
  500. /*
  501. * Curl_resolver_is_resolved() is called repeatedly to check if a previous
  502. * name resolve request has completed. It should also make sure to time-out if
  503. * the operation seems to take too long.
  504. */
  505. CURLcode Curl_resolver_is_resolved(struct Curl_easy *data,
  506. struct Curl_dns_entry **entry)
  507. {
  508. struct thread_data *td = data->state.async.tdata;
  509. int done = 0;
  510. DEBUGASSERT(entry);
  511. *entry = NULL;
  512. if(!td) {
  513. DEBUGASSERT(td);
  514. return CURLE_COULDNT_RESOLVE_HOST;
  515. }
  516. Curl_mutex_acquire(td->tsd.mtx);
  517. done = td->tsd.done;
  518. Curl_mutex_release(td->tsd.mtx);
  519. if(done) {
  520. getaddrinfo_complete(data);
  521. if(!data->state.async.dns) {
  522. CURLcode result = Curl_resolver_error(data);
  523. destroy_async_data(&data->state.async);
  524. return result;
  525. }
  526. destroy_async_data(&data->state.async);
  527. *entry = data->state.async.dns;
  528. }
  529. else {
  530. /* poll for name lookup done with exponential backoff up to 250ms */
  531. /* should be fine even if this converts to 32-bit */
  532. timediff_t elapsed = Curl_timediff(Curl_now(),
  533. data->progress.t_startsingle);
  534. if(elapsed < 0)
  535. elapsed = 0;
  536. if(td->poll_interval == 0)
  537. /* Start at 1ms poll interval */
  538. td->poll_interval = 1;
  539. else if(elapsed >= td->interval_end)
  540. /* Back-off exponentially if last interval expired */
  541. td->poll_interval *= 2;
  542. if(td->poll_interval > 250)
  543. td->poll_interval = 250;
  544. td->interval_end = elapsed + td->poll_interval;
  545. Curl_expire(data, td->poll_interval, EXPIRE_ASYNC_NAME);
  546. }
  547. return CURLE_OK;
  548. }
  549. int Curl_resolver_getsock(struct Curl_easy *data, curl_socket_t *socks)
  550. {
  551. int ret_val = 0;
  552. timediff_t milli;
  553. timediff_t ms;
  554. struct resdata *reslv = (struct resdata *)data->state.async.resolver;
  555. #ifndef CURL_DISABLE_SOCKETPAIR
  556. struct thread_data *td = data->state.async.tdata;
  557. #else
  558. (void)socks;
  559. #endif
  560. #ifndef CURL_DISABLE_SOCKETPAIR
  561. if(td) {
  562. /* return read fd to client for polling the DNS resolution status */
  563. socks[0] = td->tsd.sock_pair[0];
  564. td->tsd.data = data;
  565. ret_val = GETSOCK_READSOCK(0);
  566. }
  567. else {
  568. #endif
  569. ms = Curl_timediff(Curl_now(), reslv->start);
  570. if(ms < 3)
  571. milli = 0;
  572. else if(ms <= 50)
  573. milli = ms/3;
  574. else if(ms <= 250)
  575. milli = 50;
  576. else
  577. milli = 200;
  578. Curl_expire(data, milli, EXPIRE_ASYNC_NAME);
  579. #ifndef CURL_DISABLE_SOCKETPAIR
  580. }
  581. #endif
  582. return ret_val;
  583. }
  584. #ifndef HAVE_GETADDRINFO
  585. /*
  586. * Curl_getaddrinfo() - for platforms without 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 resdata *reslv = (struct resdata *)data->state.async.resolver;
  594. *waitp = 0; /* default to synchronous response */
  595. reslv->start = Curl_now();
  596. /* fire up a new resolver thread! */
  597. if(init_resolve_thread(data, hostname, port, NULL)) {
  598. *waitp = 1; /* expect asynchronous response */
  599. return NULL;
  600. }
  601. failf(data, "getaddrinfo() thread failed");
  602. return NULL;
  603. }
  604. #else /* !HAVE_GETADDRINFO */
  605. /*
  606. * Curl_resolver_getaddrinfo() - for getaddrinfo
  607. */
  608. struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data,
  609. const char *hostname,
  610. int port,
  611. int *waitp)
  612. {
  613. struct addrinfo hints;
  614. int pf = PF_INET;
  615. struct resdata *reslv = (struct resdata *)data->state.async.resolver;
  616. *waitp = 0; /* default to synchronous response */
  617. #ifdef CURLRES_IPV6
  618. if((data->conn->ip_version != CURL_IPRESOLVE_V4) && Curl_ipv6works(data)) {
  619. /* The stack seems to be IPv6-enabled */
  620. if(data->conn->ip_version == CURL_IPRESOLVE_V6)
  621. pf = PF_INET6;
  622. else
  623. pf = PF_UNSPEC;
  624. }
  625. #endif /* CURLRES_IPV6 */
  626. memset(&hints, 0, sizeof(hints));
  627. hints.ai_family = pf;
  628. hints.ai_socktype = (data->conn->transport == TRNSPRT_TCP) ?
  629. SOCK_STREAM : SOCK_DGRAM;
  630. reslv->start = Curl_now();
  631. /* fire up a new resolver thread! */
  632. if(init_resolve_thread(data, hostname, port, &hints)) {
  633. *waitp = 1; /* expect asynchronous response */
  634. return NULL;
  635. }
  636. failf(data, "getaddrinfo() thread failed to start");
  637. return NULL;
  638. }
  639. #endif /* !HAVE_GETADDRINFO */
  640. CURLcode Curl_set_dns_servers(struct Curl_easy *data,
  641. char *servers)
  642. {
  643. (void)data;
  644. (void)servers;
  645. return CURLE_NOT_BUILT_IN;
  646. }
  647. CURLcode Curl_set_dns_interface(struct Curl_easy *data,
  648. const char *interf)
  649. {
  650. (void)data;
  651. (void)interf;
  652. return CURLE_NOT_BUILT_IN;
  653. }
  654. CURLcode Curl_set_dns_local_ip4(struct Curl_easy *data,
  655. const char *local_ip4)
  656. {
  657. (void)data;
  658. (void)local_ip4;
  659. return CURLE_NOT_BUILT_IN;
  660. }
  661. CURLcode Curl_set_dns_local_ip6(struct Curl_easy *data,
  662. const char *local_ip6)
  663. {
  664. (void)data;
  665. (void)local_ip6;
  666. return CURLE_NOT_BUILT_IN;
  667. }
  668. #endif /* CURLRES_THREADED */