asyn-thread.c 19 KB

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