asyn-thread.c 19 KB

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