asyn-thread.c 19 KB

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