2
0

easy.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  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. #ifdef HAVE_NETINET_IN_H
  26. #include <netinet/in.h>
  27. #endif
  28. #ifdef HAVE_NETDB_H
  29. #include <netdb.h>
  30. #endif
  31. #ifdef HAVE_ARPA_INET_H
  32. #include <arpa/inet.h>
  33. #endif
  34. #ifdef HAVE_NET_IF_H
  35. #include <net/if.h>
  36. #endif
  37. #ifdef HAVE_SYS_IOCTL_H
  38. #include <sys/ioctl.h>
  39. #endif
  40. #ifdef HAVE_SYS_PARAM_H
  41. #include <sys/param.h>
  42. #endif
  43. #include "urldata.h"
  44. #include <curl/curl.h>
  45. #include "transfer.h"
  46. #include "vtls/vtls.h"
  47. #include "url.h"
  48. #include "getinfo.h"
  49. #include "hostip.h"
  50. #include "share.h"
  51. #include "strdup.h"
  52. #include "progress.h"
  53. #include "easyif.h"
  54. #include "multiif.h"
  55. #include "select.h"
  56. #include "cfilters.h"
  57. #include "sendf.h" /* for failf function prototype */
  58. #include "connect.h" /* for Curl_getconnectinfo */
  59. #include "slist.h"
  60. #include "mime.h"
  61. #include "amigaos.h"
  62. #include "macos.h"
  63. #include "warnless.h"
  64. #include "sigpipe.h"
  65. #include "vssh/ssh.h"
  66. #include "setopt.h"
  67. #include "http_digest.h"
  68. #include "system_win32.h"
  69. #include "http2.h"
  70. #include "dynbuf.h"
  71. #include "altsvc.h"
  72. #include "hsts.h"
  73. #include "easy_lock.h"
  74. /* The last 3 #include files should be in this order */
  75. #include "curl_printf.h"
  76. #include "curl_memory.h"
  77. #include "memdebug.h"
  78. /* true globals -- for curl_global_init() and curl_global_cleanup() */
  79. static unsigned int initialized;
  80. static long easy_init_flags;
  81. #ifdef GLOBAL_INIT_IS_THREADSAFE
  82. static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT;
  83. #define global_init_lock() curl_simple_lock_lock(&s_lock)
  84. #define global_init_unlock() curl_simple_lock_unlock(&s_lock)
  85. #else
  86. #define global_init_lock()
  87. #define global_init_unlock()
  88. #endif
  89. /*
  90. * strdup (and other memory functions) is redefined in complicated
  91. * ways, but at this point it must be defined as the system-supplied strdup
  92. * so the callback pointer is initialized correctly.
  93. */
  94. #if defined(_WIN32_WCE)
  95. #define system_strdup _strdup
  96. #elif !defined(HAVE_STRDUP)
  97. #define system_strdup Curl_strdup
  98. #else
  99. #define system_strdup strdup
  100. #endif
  101. #if defined(_MSC_VER) && defined(_DLL)
  102. # pragma warning(push)
  103. # pragma warning(disable:4232) /* MSVC extension, dllimport identity */
  104. #endif
  105. /*
  106. * If a memory-using function (like curl_getenv) is used before
  107. * curl_global_init() is called, we need to have these pointers set already.
  108. */
  109. curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
  110. curl_free_callback Curl_cfree = (curl_free_callback)free;
  111. curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
  112. curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)system_strdup;
  113. curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
  114. #if defined(_WIN32) && defined(UNICODE)
  115. curl_wcsdup_callback Curl_cwcsdup = Curl_wcsdup;
  116. #endif
  117. #if defined(_MSC_VER) && defined(_DLL)
  118. # pragma warning(pop)
  119. #endif
  120. #ifdef DEBUGBUILD
  121. static char *leakpointer;
  122. #endif
  123. /**
  124. * curl_global_init() globally initializes curl given a bitwise set of the
  125. * different features of what to initialize.
  126. */
  127. static CURLcode global_init(long flags, bool memoryfuncs)
  128. {
  129. if(initialized++)
  130. return CURLE_OK;
  131. if(memoryfuncs) {
  132. /* Setup the default memory functions here (again) */
  133. Curl_cmalloc = (curl_malloc_callback)malloc;
  134. Curl_cfree = (curl_free_callback)free;
  135. Curl_crealloc = (curl_realloc_callback)realloc;
  136. Curl_cstrdup = (curl_strdup_callback)system_strdup;
  137. Curl_ccalloc = (curl_calloc_callback)calloc;
  138. #if defined(_WIN32) && defined(UNICODE)
  139. Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
  140. #endif
  141. }
  142. if(Curl_trc_init()) {
  143. DEBUGF(fprintf(stderr, "Error: Curl_trc_init failed\n"));
  144. goto fail;
  145. }
  146. if(!Curl_ssl_init()) {
  147. DEBUGF(fprintf(stderr, "Error: Curl_ssl_init failed\n"));
  148. goto fail;
  149. }
  150. if(Curl_win32_init(flags)) {
  151. DEBUGF(fprintf(stderr, "Error: win32_init failed\n"));
  152. goto fail;
  153. }
  154. if(Curl_amiga_init()) {
  155. DEBUGF(fprintf(stderr, "Error: Curl_amiga_init failed\n"));
  156. goto fail;
  157. }
  158. if(Curl_macos_init()) {
  159. DEBUGF(fprintf(stderr, "Error: Curl_macos_init failed\n"));
  160. goto fail;
  161. }
  162. if(Curl_resolver_global_init()) {
  163. DEBUGF(fprintf(stderr, "Error: resolver_global_init failed\n"));
  164. goto fail;
  165. }
  166. if(Curl_ssh_init()) {
  167. DEBUGF(fprintf(stderr, "Error: Curl_ssh_init failed\n"));
  168. goto fail;
  169. }
  170. easy_init_flags = flags;
  171. #ifdef DEBUGBUILD
  172. if(getenv("CURL_GLOBAL_INIT"))
  173. /* alloc data that will leak if *cleanup() is not called! */
  174. leakpointer = malloc(1);
  175. #endif
  176. return CURLE_OK;
  177. fail:
  178. initialized--; /* undo the increase */
  179. return CURLE_FAILED_INIT;
  180. }
  181. /**
  182. * curl_global_init() globally initializes curl given a bitwise set of the
  183. * different features of what to initialize.
  184. */
  185. CURLcode curl_global_init(long flags)
  186. {
  187. CURLcode result;
  188. global_init_lock();
  189. result = global_init(flags, TRUE);
  190. global_init_unlock();
  191. return result;
  192. }
  193. /*
  194. * curl_global_init_mem() globally initializes curl and also registers the
  195. * user provided callback routines.
  196. */
  197. CURLcode curl_global_init_mem(long flags, curl_malloc_callback m,
  198. curl_free_callback f, curl_realloc_callback r,
  199. curl_strdup_callback s, curl_calloc_callback c)
  200. {
  201. CURLcode result;
  202. /* Invalid input, return immediately */
  203. if(!m || !f || !r || !s || !c)
  204. return CURLE_FAILED_INIT;
  205. global_init_lock();
  206. if(initialized) {
  207. /* Already initialized, do not do it again, but bump the variable anyway to
  208. work like curl_global_init() and require the same amount of cleanup
  209. calls. */
  210. initialized++;
  211. global_init_unlock();
  212. return CURLE_OK;
  213. }
  214. /* set memory functions before global_init() in case it wants memory
  215. functions */
  216. Curl_cmalloc = m;
  217. Curl_cfree = f;
  218. Curl_cstrdup = s;
  219. Curl_crealloc = r;
  220. Curl_ccalloc = c;
  221. /* Call the actual init function, but without setting */
  222. result = global_init(flags, FALSE);
  223. global_init_unlock();
  224. return result;
  225. }
  226. /**
  227. * curl_global_cleanup() globally cleanups curl, uses the value of
  228. * "easy_init_flags" to determine what needs to be cleaned up and what does
  229. * not.
  230. */
  231. void curl_global_cleanup(void)
  232. {
  233. global_init_lock();
  234. if(!initialized) {
  235. global_init_unlock();
  236. return;
  237. }
  238. if(--initialized) {
  239. global_init_unlock();
  240. return;
  241. }
  242. Curl_ssl_cleanup();
  243. Curl_resolver_global_cleanup();
  244. #ifdef _WIN32
  245. Curl_win32_cleanup(easy_init_flags);
  246. #endif
  247. Curl_amiga_cleanup();
  248. Curl_ssh_cleanup();
  249. #ifdef DEBUGBUILD
  250. free(leakpointer);
  251. #endif
  252. easy_init_flags = 0;
  253. global_init_unlock();
  254. }
  255. /**
  256. * curl_global_trace() globally initializes curl logging.
  257. */
  258. CURLcode curl_global_trace(const char *config)
  259. {
  260. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  261. CURLcode result;
  262. global_init_lock();
  263. result = Curl_trc_opt(config);
  264. global_init_unlock();
  265. return result;
  266. #else
  267. (void)config;
  268. return CURLE_OK;
  269. #endif
  270. }
  271. /*
  272. * curl_global_sslset() globally initializes the SSL backend to use.
  273. */
  274. CURLsslset curl_global_sslset(curl_sslbackend id, const char *name,
  275. const curl_ssl_backend ***avail)
  276. {
  277. CURLsslset rc;
  278. global_init_lock();
  279. rc = Curl_init_sslset_nolock(id, name, avail);
  280. global_init_unlock();
  281. return rc;
  282. }
  283. /*
  284. * curl_easy_init() is the external interface to alloc, setup and init an
  285. * easy handle that is returned. If anything goes wrong, NULL is returned.
  286. */
  287. CURL *curl_easy_init(void)
  288. {
  289. CURLcode result;
  290. struct Curl_easy *data;
  291. /* Make sure we inited the global SSL stuff */
  292. global_init_lock();
  293. if(!initialized) {
  294. result = global_init(CURL_GLOBAL_DEFAULT, TRUE);
  295. if(result) {
  296. /* something in the global init failed, return nothing */
  297. DEBUGF(fprintf(stderr, "Error: curl_global_init failed\n"));
  298. global_init_unlock();
  299. return NULL;
  300. }
  301. }
  302. global_init_unlock();
  303. /* We use curl_open() with undefined URL so far */
  304. result = Curl_open(&data);
  305. if(result) {
  306. DEBUGF(fprintf(stderr, "Error: Curl_open failed\n"));
  307. return NULL;
  308. }
  309. return data;
  310. }
  311. #ifdef DEBUGBUILD
  312. struct socketmonitor {
  313. struct socketmonitor *next; /* the next node in the list or NULL */
  314. struct pollfd socket; /* socket info of what to monitor */
  315. };
  316. struct events {
  317. long ms; /* timeout, run the timeout function when reached */
  318. bool msbump; /* set TRUE when timeout is set by callback */
  319. int num_sockets; /* number of nodes in the monitor list */
  320. struct socketmonitor *list; /* list of sockets to monitor */
  321. int running_handles; /* store the returned number */
  322. };
  323. #define DEBUG_EV_POLL 0
  324. /* events_timer
  325. *
  326. * Callback that gets called with a new value when the timeout should be
  327. * updated.
  328. */
  329. static int events_timer(CURLM *multi, /* multi handle */
  330. long timeout_ms, /* see above */
  331. void *userp) /* private callback pointer */
  332. {
  333. struct events *ev = userp;
  334. (void)multi;
  335. #if DEBUG_EV_POLL
  336. fprintf(stderr, "events_timer: set timeout %ldms\n", timeout_ms);
  337. #endif
  338. ev->ms = timeout_ms;
  339. ev->msbump = TRUE;
  340. return 0;
  341. }
  342. /* poll2cselect
  343. *
  344. * convert from poll() bit definitions to libcurl's CURL_CSELECT_* ones
  345. */
  346. static int poll2cselect(int pollmask)
  347. {
  348. int omask = 0;
  349. if(pollmask & POLLIN)
  350. omask |= CURL_CSELECT_IN;
  351. if(pollmask & POLLOUT)
  352. omask |= CURL_CSELECT_OUT;
  353. if(pollmask & POLLERR)
  354. omask |= CURL_CSELECT_ERR;
  355. return omask;
  356. }
  357. /* socketcb2poll
  358. *
  359. * convert from libcurl' CURL_POLL_* bit definitions to poll()'s
  360. */
  361. static short socketcb2poll(int pollmask)
  362. {
  363. short omask = 0;
  364. if(pollmask & CURL_POLL_IN)
  365. omask |= POLLIN;
  366. if(pollmask & CURL_POLL_OUT)
  367. omask |= POLLOUT;
  368. return omask;
  369. }
  370. /* events_socket
  371. *
  372. * Callback that gets called with information about socket activity to
  373. * monitor.
  374. */
  375. static int events_socket(CURL *easy, /* easy handle */
  376. curl_socket_t s, /* socket */
  377. int what, /* see above */
  378. void *userp, /* private callback
  379. pointer */
  380. void *socketp) /* private socket
  381. pointer */
  382. {
  383. struct events *ev = userp;
  384. struct socketmonitor *m;
  385. struct socketmonitor *prev = NULL;
  386. bool found = FALSE;
  387. struct Curl_easy *data = easy;
  388. #if defined(CURL_DISABLE_VERBOSE_STRINGS)
  389. (void) easy;
  390. #endif
  391. (void)socketp;
  392. m = ev->list;
  393. while(m) {
  394. if(m->socket.fd == s) {
  395. found = TRUE;
  396. if(what == CURL_POLL_REMOVE) {
  397. struct socketmonitor *nxt = m->next;
  398. /* remove this node from the list of monitored sockets */
  399. if(prev)
  400. prev->next = nxt;
  401. else
  402. ev->list = nxt;
  403. free(m);
  404. infof(data, "socket cb: socket %" FMT_SOCKET_T " REMOVED", s);
  405. }
  406. else {
  407. /* The socket 's' is already being monitored, update the activity
  408. mask. Convert from libcurl bitmask to the poll one. */
  409. m->socket.events = socketcb2poll(what);
  410. infof(data, "socket cb: socket %" FMT_SOCKET_T
  411. " UPDATED as %s%s", s,
  412. (what&CURL_POLL_IN) ? "IN" : "",
  413. (what&CURL_POLL_OUT) ? "OUT" : "");
  414. }
  415. break;
  416. }
  417. prev = m;
  418. m = m->next; /* move to next node */
  419. }
  420. if(!found) {
  421. if(what == CURL_POLL_REMOVE) {
  422. /* should not happen if our logic is correct, but is no drama. */
  423. DEBUGF(infof(data, "socket cb: asked to REMOVE socket %"
  424. FMT_SOCKET_T "but not present!", s));
  425. DEBUGASSERT(0);
  426. }
  427. else {
  428. m = malloc(sizeof(struct socketmonitor));
  429. if(m) {
  430. m->next = ev->list;
  431. m->socket.fd = s;
  432. m->socket.events = socketcb2poll(what);
  433. m->socket.revents = 0;
  434. ev->list = m;
  435. infof(data, "socket cb: socket %" FMT_SOCKET_T " ADDED as %s%s", s,
  436. (what&CURL_POLL_IN) ? "IN" : "",
  437. (what&CURL_POLL_OUT) ? "OUT" : "");
  438. }
  439. else
  440. return CURLE_OUT_OF_MEMORY;
  441. }
  442. }
  443. return 0;
  444. }
  445. /*
  446. * events_setup()
  447. *
  448. * Do the multi handle setups that only event-based transfers need.
  449. */
  450. static void events_setup(struct Curl_multi *multi, struct events *ev)
  451. {
  452. /* timer callback */
  453. curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, events_timer);
  454. curl_multi_setopt(multi, CURLMOPT_TIMERDATA, ev);
  455. /* socket callback */
  456. curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, events_socket);
  457. curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, ev);
  458. }
  459. /* wait_or_timeout()
  460. *
  461. * waits for activity on any of the given sockets, or the timeout to trigger.
  462. */
  463. static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
  464. {
  465. bool done = FALSE;
  466. CURLMcode mcode = CURLM_OK;
  467. CURLcode result = CURLE_OK;
  468. while(!done) {
  469. CURLMsg *msg;
  470. struct socketmonitor *m;
  471. struct pollfd *f;
  472. struct pollfd fds[4];
  473. int numfds = 0;
  474. int pollrc;
  475. int i;
  476. struct curltime before;
  477. /* populate the fds[] array */
  478. for(m = ev->list, f = &fds[0]; m; m = m->next) {
  479. f->fd = m->socket.fd;
  480. f->events = m->socket.events;
  481. f->revents = 0;
  482. #if DEBUG_EV_POLL
  483. fprintf(stderr, "poll() %d check socket %d\n", numfds, f->fd);
  484. #endif
  485. f++;
  486. numfds++;
  487. }
  488. /* get the time stamp to use to figure out how long poll takes */
  489. before = Curl_now();
  490. if(numfds) {
  491. /* wait for activity or timeout */
  492. #if DEBUG_EV_POLL
  493. fprintf(stderr, "poll(numfds=%d, timeout=%ldms)\n", numfds, ev->ms);
  494. #endif
  495. pollrc = Curl_poll(fds, (unsigned int)numfds, ev->ms);
  496. #if DEBUG_EV_POLL
  497. fprintf(stderr, "poll(numfds=%d, timeout=%ldms) -> %d\n",
  498. numfds, ev->ms, pollrc);
  499. #endif
  500. if(pollrc < 0)
  501. return CURLE_UNRECOVERABLE_POLL;
  502. }
  503. else {
  504. #if DEBUG_EV_POLL
  505. fprintf(stderr, "poll, but no fds, wait timeout=%ldms\n", ev->ms);
  506. #endif
  507. pollrc = 0;
  508. if(ev->ms > 0)
  509. Curl_wait_ms(ev->ms);
  510. }
  511. ev->msbump = FALSE; /* reset here */
  512. if(!pollrc) {
  513. /* timeout! */
  514. ev->ms = 0;
  515. /* fprintf(stderr, "call curl_multi_socket_action(TIMEOUT)\n"); */
  516. mcode = curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0,
  517. &ev->running_handles);
  518. }
  519. else {
  520. /* here pollrc is > 0 */
  521. struct Curl_llist_node *e = Curl_llist_head(&multi->process);
  522. struct Curl_easy *data;
  523. DEBUGASSERT(e);
  524. data = Curl_node_elem(e);
  525. DEBUGASSERT(data);
  526. /* loop over the monitored sockets to see which ones had activity */
  527. for(i = 0; i < numfds; i++) {
  528. if(fds[i].revents) {
  529. /* socket activity, tell libcurl */
  530. int act = poll2cselect(fds[i].revents); /* convert */
  531. /* sending infof "randomly" to the first easy handle */
  532. infof(data, "call curl_multi_socket_action(socket "
  533. "%" FMT_SOCKET_T ")", (curl_socket_t)fds[i].fd);
  534. mcode = curl_multi_socket_action(multi, fds[i].fd, act,
  535. &ev->running_handles);
  536. }
  537. }
  538. if(!ev->msbump && ev->ms >= 0) {
  539. /* If nothing updated the timeout, we decrease it by the spent time.
  540. * If it was updated, it has the new timeout time stored already.
  541. */
  542. timediff_t timediff = Curl_timediff(Curl_now(), before);
  543. if(timediff > 0) {
  544. #if DEBUG_EV_POLL
  545. fprintf(stderr, "poll timeout %ldms not updated, decrease by "
  546. "time spent %ldms\n", ev->ms, (long)timediff);
  547. #endif
  548. if(timediff > ev->ms)
  549. ev->ms = 0;
  550. else
  551. ev->ms -= (long)timediff;
  552. }
  553. }
  554. }
  555. if(mcode)
  556. return CURLE_URL_MALFORMAT;
  557. /* we do not really care about the "msgs_in_queue" value returned in the
  558. second argument */
  559. msg = curl_multi_info_read(multi, &pollrc);
  560. if(msg) {
  561. result = msg->data.result;
  562. done = TRUE;
  563. }
  564. }
  565. return result;
  566. }
  567. /* easy_events()
  568. *
  569. * Runs a transfer in a blocking manner using the events-based API
  570. */
  571. static CURLcode easy_events(struct Curl_multi *multi)
  572. {
  573. /* this struct is made static to allow it to be used after this function
  574. returns and curl_multi_remove_handle() is called */
  575. static struct events evs = {-1, FALSE, 0, NULL, 0};
  576. /* if running event-based, do some further multi inits */
  577. events_setup(multi, &evs);
  578. return wait_or_timeout(multi, &evs);
  579. }
  580. #else /* DEBUGBUILD */
  581. /* when not built with debug, this function does not exist */
  582. #define easy_events(x) CURLE_NOT_BUILT_IN
  583. #endif
  584. static CURLcode easy_transfer(struct Curl_multi *multi)
  585. {
  586. bool done = FALSE;
  587. CURLMcode mcode = CURLM_OK;
  588. CURLcode result = CURLE_OK;
  589. while(!done && !mcode) {
  590. int still_running = 0;
  591. mcode = curl_multi_poll(multi, NULL, 0, 1000, NULL);
  592. if(!mcode)
  593. mcode = curl_multi_perform(multi, &still_running);
  594. /* only read 'still_running' if curl_multi_perform() return OK */
  595. if(!mcode && !still_running) {
  596. int rc;
  597. CURLMsg *msg = curl_multi_info_read(multi, &rc);
  598. if(msg) {
  599. result = msg->data.result;
  600. done = TRUE;
  601. }
  602. }
  603. }
  604. /* Make sure to return some kind of error if there was a multi problem */
  605. if(mcode) {
  606. result = (mcode == CURLM_OUT_OF_MEMORY) ? CURLE_OUT_OF_MEMORY :
  607. /* The other multi errors should never happen, so return
  608. something suitably generic */
  609. CURLE_BAD_FUNCTION_ARGUMENT;
  610. }
  611. return result;
  612. }
  613. /*
  614. * easy_perform() is the external interface that performs a blocking
  615. * transfer as previously setup.
  616. *
  617. * CONCEPT: This function creates a multi handle, adds the easy handle to it,
  618. * runs curl_multi_perform() until the transfer is done, then detaches the
  619. * easy handle, destroys the multi handle and returns the easy handle's return
  620. * code.
  621. *
  622. * REALITY: it cannot just create and destroy the multi handle that easily. It
  623. * needs to keep it around since if this easy handle is used again by this
  624. * function, the same multi handle must be reused so that the same pools and
  625. * caches can be used.
  626. *
  627. * DEBUG: if 'events' is set TRUE, this function will use a replacement engine
  628. * instead of curl_multi_perform() and use curl_multi_socket_action().
  629. */
  630. static CURLcode easy_perform(struct Curl_easy *data, bool events)
  631. {
  632. struct Curl_multi *multi;
  633. CURLMcode mcode;
  634. CURLcode result = CURLE_OK;
  635. SIGPIPE_VARIABLE(pipe_st);
  636. if(!data)
  637. return CURLE_BAD_FUNCTION_ARGUMENT;
  638. if(data->set.errorbuffer)
  639. /* clear this as early as possible */
  640. data->set.errorbuffer[0] = 0;
  641. data->state.os_errno = 0;
  642. if(data->multi) {
  643. failf(data, "easy handle already used in multi handle");
  644. return CURLE_FAILED_INIT;
  645. }
  646. if(data->multi_easy)
  647. multi = data->multi_easy;
  648. else {
  649. /* this multi handle will only ever have a single easy handled attached
  650. to it, so make it use minimal hashes */
  651. multi = Curl_multi_handle(1, 3, 7);
  652. if(!multi)
  653. return CURLE_OUT_OF_MEMORY;
  654. }
  655. if(multi->in_callback)
  656. return CURLE_RECURSIVE_API_CALL;
  657. /* Copy the MAXCONNECTS option to the multi handle */
  658. curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, (long)data->set.maxconnects);
  659. data->multi_easy = NULL; /* pretend it does not exist */
  660. mcode = curl_multi_add_handle(multi, data);
  661. if(mcode) {
  662. curl_multi_cleanup(multi);
  663. if(mcode == CURLM_OUT_OF_MEMORY)
  664. return CURLE_OUT_OF_MEMORY;
  665. return CURLE_FAILED_INIT;
  666. }
  667. /* assign this after curl_multi_add_handle() */
  668. data->multi_easy = multi;
  669. sigpipe_init(&pipe_st);
  670. sigpipe_apply(data, &pipe_st);
  671. /* run the transfer */
  672. result = events ? easy_events(multi) : easy_transfer(multi);
  673. /* ignoring the return code is not nice, but atm we cannot really handle
  674. a failure here, room for future improvement! */
  675. (void)curl_multi_remove_handle(multi, data);
  676. sigpipe_restore(&pipe_st);
  677. /* The multi handle is kept alive, owned by the easy handle */
  678. return result;
  679. }
  680. /*
  681. * curl_easy_perform() is the external interface that performs a blocking
  682. * transfer as previously setup.
  683. */
  684. CURLcode curl_easy_perform(CURL *data)
  685. {
  686. return easy_perform(data, FALSE);
  687. }
  688. #ifdef DEBUGBUILD
  689. /*
  690. * curl_easy_perform_ev() is the external interface that performs a blocking
  691. * transfer using the event-based API internally.
  692. */
  693. CURLcode curl_easy_perform_ev(struct Curl_easy *data)
  694. {
  695. return easy_perform(data, TRUE);
  696. }
  697. #endif
  698. /*
  699. * curl_easy_cleanup() is the external interface to cleaning/freeing the given
  700. * easy handle.
  701. */
  702. void curl_easy_cleanup(CURL *ptr)
  703. {
  704. struct Curl_easy *data = ptr;
  705. if(GOOD_EASY_HANDLE(data)) {
  706. SIGPIPE_VARIABLE(pipe_st);
  707. sigpipe_ignore(data, &pipe_st);
  708. Curl_close(&data);
  709. sigpipe_restore(&pipe_st);
  710. }
  711. }
  712. /*
  713. * curl_easy_getinfo() is an external interface that allows an app to retrieve
  714. * information from a performed transfer and similar.
  715. */
  716. #undef curl_easy_getinfo
  717. CURLcode curl_easy_getinfo(CURL *data, CURLINFO info, ...)
  718. {
  719. va_list arg;
  720. void *paramp;
  721. CURLcode result;
  722. va_start(arg, info);
  723. paramp = va_arg(arg, void *);
  724. result = Curl_getinfo(data, info, paramp);
  725. va_end(arg);
  726. return result;
  727. }
  728. static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src)
  729. {
  730. CURLcode result = CURLE_OK;
  731. enum dupstring i;
  732. enum dupblob j;
  733. /* Copy src->set into dst->set first, then deal with the strings
  734. afterwards */
  735. dst->set = src->set;
  736. Curl_mime_initpart(&dst->set.mimepost);
  737. /* clear all dest string and blob pointers first, in case we error out
  738. mid-function */
  739. memset(dst->set.str, 0, STRING_LAST * sizeof(char *));
  740. memset(dst->set.blobs, 0, BLOB_LAST * sizeof(struct curl_blob *));
  741. /* duplicate all strings */
  742. for(i = (enum dupstring)0; i < STRING_LASTZEROTERMINATED; i++) {
  743. result = Curl_setstropt(&dst->set.str[i], src->set.str[i]);
  744. if(result)
  745. return result;
  746. }
  747. /* duplicate all blobs */
  748. for(j = (enum dupblob)0; j < BLOB_LAST; j++) {
  749. result = Curl_setblobopt(&dst->set.blobs[j], src->set.blobs[j]);
  750. if(result)
  751. return result;
  752. }
  753. /* duplicate memory areas pointed to */
  754. i = STRING_COPYPOSTFIELDS;
  755. if(src->set.str[i]) {
  756. if(src->set.postfieldsize == -1)
  757. dst->set.str[i] = strdup(src->set.str[i]);
  758. else
  759. /* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */
  760. dst->set.str[i] = Curl_memdup(src->set.str[i],
  761. curlx_sotouz(src->set.postfieldsize));
  762. if(!dst->set.str[i])
  763. return CURLE_OUT_OF_MEMORY;
  764. /* point to the new copy */
  765. dst->set.postfields = dst->set.str[i];
  766. }
  767. /* Duplicate mime data. */
  768. result = Curl_mime_duppart(dst, &dst->set.mimepost, &src->set.mimepost);
  769. if(src->set.resolve)
  770. dst->state.resolve = dst->set.resolve;
  771. return result;
  772. }
  773. /*
  774. * curl_easy_duphandle() is an external interface to allow duplication of a
  775. * given input easy handle. The returned handle will be a new working handle
  776. * with all options set exactly as the input source handle.
  777. */
  778. CURL *curl_easy_duphandle(CURL *d)
  779. {
  780. struct Curl_easy *data = d;
  781. struct Curl_easy *outcurl = calloc(1, sizeof(struct Curl_easy));
  782. if(!outcurl)
  783. goto fail;
  784. /*
  785. * We setup a few buffers we need. We should probably make them
  786. * get setup on-demand in the code, as that would probably decrease
  787. * the likeliness of us forgetting to init a buffer here in the future.
  788. */
  789. outcurl->set.buffer_size = data->set.buffer_size;
  790. /* copy all userdefined values */
  791. if(dupset(outcurl, data))
  792. goto fail;
  793. Curl_dyn_init(&outcurl->state.headerb, CURL_MAX_HTTP_HEADER);
  794. Curl_netrc_init(&outcurl->state.netrc);
  795. /* the connection pool is setup on demand */
  796. outcurl->state.lastconnect_id = -1;
  797. outcurl->state.recent_conn_id = -1;
  798. outcurl->id = -1;
  799. outcurl->progress.flags = data->progress.flags;
  800. outcurl->progress.callback = data->progress.callback;
  801. #ifndef CURL_DISABLE_COOKIES
  802. outcurl->state.cookielist = NULL;
  803. if(data->cookies && data->state.cookie_engine) {
  804. /* If cookies are enabled in the parent handle, we enable them
  805. in the clone as well! */
  806. outcurl->cookies = Curl_cookie_init(outcurl, NULL, outcurl->cookies,
  807. data->set.cookiesession);
  808. if(!outcurl->cookies)
  809. goto fail;
  810. }
  811. if(data->state.cookielist) {
  812. outcurl->state.cookielist = Curl_slist_duplicate(data->state.cookielist);
  813. if(!outcurl->state.cookielist)
  814. goto fail;
  815. }
  816. #endif
  817. if(data->state.url) {
  818. outcurl->state.url = strdup(data->state.url);
  819. if(!outcurl->state.url)
  820. goto fail;
  821. outcurl->state.url_alloc = TRUE;
  822. }
  823. if(data->state.referer) {
  824. outcurl->state.referer = strdup(data->state.referer);
  825. if(!outcurl->state.referer)
  826. goto fail;
  827. outcurl->state.referer_alloc = TRUE;
  828. }
  829. /* Reinitialize an SSL engine for the new handle
  830. * note: the engine name has already been copied by dupset */
  831. if(outcurl->set.str[STRING_SSL_ENGINE]) {
  832. if(Curl_ssl_set_engine(outcurl, outcurl->set.str[STRING_SSL_ENGINE]))
  833. goto fail;
  834. }
  835. #ifndef CURL_DISABLE_ALTSVC
  836. if(data->asi) {
  837. outcurl->asi = Curl_altsvc_init();
  838. if(!outcurl->asi)
  839. goto fail;
  840. if(outcurl->set.str[STRING_ALTSVC])
  841. (void)Curl_altsvc_load(outcurl->asi, outcurl->set.str[STRING_ALTSVC]);
  842. }
  843. #endif
  844. #ifndef CURL_DISABLE_HSTS
  845. if(data->hsts) {
  846. outcurl->hsts = Curl_hsts_init();
  847. if(!outcurl->hsts)
  848. goto fail;
  849. if(outcurl->set.str[STRING_HSTS])
  850. (void)Curl_hsts_loadfile(outcurl,
  851. outcurl->hsts, outcurl->set.str[STRING_HSTS]);
  852. (void)Curl_hsts_loadcb(outcurl, outcurl->hsts);
  853. }
  854. #endif
  855. #ifdef CURLRES_ASYNCH
  856. /* Clone the resolver handle, if present, for the new handle */
  857. if(Curl_resolver_duphandle(outcurl,
  858. &outcurl->state.async.resolver,
  859. data->state.async.resolver))
  860. goto fail;
  861. #endif
  862. #ifdef USE_ARES
  863. {
  864. CURLcode rc;
  865. rc = Curl_set_dns_servers(outcurl, data->set.str[STRING_DNS_SERVERS]);
  866. if(rc && rc != CURLE_NOT_BUILT_IN)
  867. goto fail;
  868. rc = Curl_set_dns_interface(outcurl, data->set.str[STRING_DNS_INTERFACE]);
  869. if(rc && rc != CURLE_NOT_BUILT_IN)
  870. goto fail;
  871. rc = Curl_set_dns_local_ip4(outcurl, data->set.str[STRING_DNS_LOCAL_IP4]);
  872. if(rc && rc != CURLE_NOT_BUILT_IN)
  873. goto fail;
  874. rc = Curl_set_dns_local_ip6(outcurl, data->set.str[STRING_DNS_LOCAL_IP6]);
  875. if(rc && rc != CURLE_NOT_BUILT_IN)
  876. goto fail;
  877. }
  878. #endif /* USE_ARES */
  879. #ifndef CURL_DISABLE_HTTP
  880. Curl_llist_init(&outcurl->state.httphdrs, NULL);
  881. #endif
  882. Curl_initinfo(outcurl);
  883. outcurl->magic = CURLEASY_MAGIC_NUMBER;
  884. /* we reach this point and thus we are OK */
  885. return outcurl;
  886. fail:
  887. if(outcurl) {
  888. #ifndef CURL_DISABLE_COOKIES
  889. free(outcurl->cookies);
  890. #endif
  891. Curl_dyn_free(&outcurl->state.headerb);
  892. Curl_altsvc_cleanup(&outcurl->asi);
  893. Curl_hsts_cleanup(&outcurl->hsts);
  894. Curl_freeset(outcurl);
  895. free(outcurl);
  896. }
  897. return NULL;
  898. }
  899. /*
  900. * curl_easy_reset() is an external interface that allows an app to re-
  901. * initialize a session handle to the default values.
  902. */
  903. void curl_easy_reset(CURL *d)
  904. {
  905. struct Curl_easy *data = d;
  906. Curl_req_hard_reset(&data->req, data);
  907. /* zero out UserDefined data: */
  908. Curl_freeset(data);
  909. memset(&data->set, 0, sizeof(struct UserDefined));
  910. (void)Curl_init_userdefined(data);
  911. /* zero out Progress data: */
  912. memset(&data->progress, 0, sizeof(struct Progress));
  913. /* zero out PureInfo data: */
  914. Curl_initinfo(data);
  915. data->progress.flags |= PGRS_HIDE;
  916. data->state.current_speed = -1; /* init to negative == impossible */
  917. data->state.retrycount = 0; /* reset the retry counter */
  918. /* zero out authentication data: */
  919. memset(&data->state.authhost, 0, sizeof(struct auth));
  920. memset(&data->state.authproxy, 0, sizeof(struct auth));
  921. #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_DIGEST_AUTH)
  922. Curl_http_auth_cleanup_digest(data);
  923. #endif
  924. }
  925. /*
  926. * curl_easy_pause() allows an application to pause or unpause a specific
  927. * transfer and direction. This function sets the full new state for the
  928. * current connection this easy handle operates on.
  929. *
  930. * NOTE: if you have the receiving paused and you call this function to remove
  931. * the pausing, you may get your write callback called at this point.
  932. *
  933. * Action is a bitmask consisting of CURLPAUSE_* bits in curl/curl.h
  934. *
  935. * NOTE: This is one of few API functions that are allowed to be called from
  936. * within a callback.
  937. */
  938. CURLcode curl_easy_pause(CURL *d, int action)
  939. {
  940. struct SingleRequest *k;
  941. CURLcode result = CURLE_OK;
  942. int oldstate;
  943. int newstate;
  944. bool recursive = FALSE;
  945. bool keep_changed, unpause_read, not_all_paused;
  946. struct Curl_easy *data = d;
  947. if(!GOOD_EASY_HANDLE(data) || !data->conn)
  948. /* crazy input, do not continue */
  949. return CURLE_BAD_FUNCTION_ARGUMENT;
  950. if(Curl_is_in_callback(data))
  951. recursive = TRUE;
  952. k = &data->req;
  953. oldstate = k->keepon & (KEEP_RECV_PAUSE| KEEP_SEND_PAUSE);
  954. /* first switch off both pause bits then set the new pause bits */
  955. newstate = (k->keepon &~ (KEEP_RECV_PAUSE| KEEP_SEND_PAUSE)) |
  956. ((action & CURLPAUSE_RECV) ? KEEP_RECV_PAUSE : 0) |
  957. ((action & CURLPAUSE_SEND) ? KEEP_SEND_PAUSE : 0);
  958. keep_changed = ((newstate & (KEEP_RECV_PAUSE| KEEP_SEND_PAUSE)) != oldstate);
  959. not_all_paused = (newstate & (KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) !=
  960. (KEEP_RECV_PAUSE|KEEP_SEND_PAUSE);
  961. unpause_read = ((k->keepon & ~newstate & KEEP_SEND_PAUSE) &&
  962. (data->mstate == MSTATE_PERFORMING ||
  963. data->mstate == MSTATE_RATELIMITING));
  964. /* Unpausing writes is detected on the next run in
  965. * transfer.c:Curl_sendrecv(). This is because this may result
  966. * in a transfer error if the application's callbacks fail */
  967. /* Set the new keepon state, so it takes effect no matter what error
  968. * may happen afterwards. */
  969. k->keepon = newstate;
  970. /* If not completely pausing both directions now, run again in any case. */
  971. if(not_all_paused) {
  972. Curl_expire(data, 0, EXPIRE_RUN_NOW);
  973. /* reset the too-slow time keeper */
  974. data->state.keeps_speed.tv_sec = 0;
  975. /* Simulate socket events on next run for unpaused directions */
  976. if(!(newstate & KEEP_SEND_PAUSE))
  977. data->state.select_bits |= CURL_CSELECT_OUT;
  978. if(!(newstate & KEEP_RECV_PAUSE))
  979. data->state.select_bits |= CURL_CSELECT_IN;
  980. /* On changes, tell application to update its timers. */
  981. if(keep_changed && data->multi) {
  982. if(Curl_update_timer(data->multi)) {
  983. result = CURLE_ABORTED_BY_CALLBACK;
  984. goto out;
  985. }
  986. }
  987. }
  988. if(unpause_read) {
  989. result = Curl_creader_unpause(data);
  990. if(result)
  991. goto out;
  992. }
  993. if(!(k->keepon & KEEP_RECV_PAUSE) && Curl_cwriter_is_paused(data)) {
  994. Curl_conn_ev_data_pause(data, FALSE);
  995. result = Curl_cwriter_unpause(data);
  996. }
  997. out:
  998. if(!result && !data->state.done && keep_changed)
  999. /* This transfer may have been moved in or out of the bundle, update the
  1000. corresponding socket callback, if used */
  1001. result = Curl_updatesocket(data);
  1002. if(recursive)
  1003. /* this might have called a callback recursively which might have set this
  1004. to false again on exit */
  1005. Curl_set_in_callback(data, TRUE);
  1006. return result;
  1007. }
  1008. static CURLcode easy_connection(struct Curl_easy *data,
  1009. struct connectdata **connp)
  1010. {
  1011. curl_socket_t sfd;
  1012. if(!data)
  1013. return CURLE_BAD_FUNCTION_ARGUMENT;
  1014. /* only allow these to be called on handles with CURLOPT_CONNECT_ONLY */
  1015. if(!data->set.connect_only) {
  1016. failf(data, "CONNECT_ONLY is required");
  1017. return CURLE_UNSUPPORTED_PROTOCOL;
  1018. }
  1019. sfd = Curl_getconnectinfo(data, connp);
  1020. if(sfd == CURL_SOCKET_BAD) {
  1021. failf(data, "Failed to get recent socket");
  1022. return CURLE_UNSUPPORTED_PROTOCOL;
  1023. }
  1024. return CURLE_OK;
  1025. }
  1026. /*
  1027. * Receives data from the connected socket. Use after successful
  1028. * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
  1029. * Returns CURLE_OK on success, error code on error.
  1030. */
  1031. CURLcode curl_easy_recv(CURL *d, void *buffer, size_t buflen, size_t *n)
  1032. {
  1033. CURLcode result;
  1034. ssize_t n1;
  1035. struct connectdata *c;
  1036. struct Curl_easy *data = d;
  1037. if(Curl_is_in_callback(data))
  1038. return CURLE_RECURSIVE_API_CALL;
  1039. result = easy_connection(data, &c);
  1040. if(result)
  1041. return result;
  1042. if(!data->conn)
  1043. /* on first invoke, the transfer has been detached from the connection and
  1044. needs to be reattached */
  1045. Curl_attach_connection(data, c);
  1046. *n = 0;
  1047. result = Curl_conn_recv(data, FIRSTSOCKET, buffer, buflen, &n1);
  1048. if(result)
  1049. return result;
  1050. *n = (size_t)n1;
  1051. return CURLE_OK;
  1052. }
  1053. #ifndef CURL_DISABLE_WEBSOCKETS
  1054. CURLcode Curl_connect_only_attach(struct Curl_easy *data)
  1055. {
  1056. CURLcode result;
  1057. struct connectdata *c = NULL;
  1058. result = easy_connection(data, &c);
  1059. if(result)
  1060. return result;
  1061. if(!data->conn)
  1062. /* on first invoke, the transfer has been detached from the connection and
  1063. needs to be reattached */
  1064. Curl_attach_connection(data, c);
  1065. return CURLE_OK;
  1066. }
  1067. #endif /* !CURL_DISABLE_WEBSOCKETS */
  1068. /*
  1069. * Sends data over the connected socket.
  1070. *
  1071. * This is the private internal version of curl_easy_send()
  1072. */
  1073. CURLcode Curl_senddata(struct Curl_easy *data, const void *buffer,
  1074. size_t buflen, size_t *n)
  1075. {
  1076. CURLcode result;
  1077. struct connectdata *c = NULL;
  1078. SIGPIPE_VARIABLE(pipe_st);
  1079. *n = 0;
  1080. result = easy_connection(data, &c);
  1081. if(result)
  1082. return result;
  1083. if(!data->conn)
  1084. /* on first invoke, the transfer has been detached from the connection and
  1085. needs to be reattached */
  1086. Curl_attach_connection(data, c);
  1087. sigpipe_ignore(data, &pipe_st);
  1088. result = Curl_conn_send(data, FIRSTSOCKET, buffer, buflen, FALSE, n);
  1089. sigpipe_restore(&pipe_st);
  1090. if(result && result != CURLE_AGAIN)
  1091. return CURLE_SEND_ERROR;
  1092. return result;
  1093. }
  1094. /*
  1095. * Sends data over the connected socket. Use after successful
  1096. * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
  1097. */
  1098. CURLcode curl_easy_send(CURL *d, const void *buffer, size_t buflen, size_t *n)
  1099. {
  1100. size_t written = 0;
  1101. CURLcode result;
  1102. struct Curl_easy *data = d;
  1103. if(Curl_is_in_callback(data))
  1104. return CURLE_RECURSIVE_API_CALL;
  1105. result = Curl_senddata(data, buffer, buflen, &written);
  1106. *n = written;
  1107. return result;
  1108. }
  1109. /*
  1110. * Performs connection upkeep for the given session handle.
  1111. */
  1112. CURLcode curl_easy_upkeep(CURL *d)
  1113. {
  1114. struct Curl_easy *data = d;
  1115. /* Verify that we got an easy handle we can work with. */
  1116. if(!GOOD_EASY_HANDLE(data))
  1117. return CURLE_BAD_FUNCTION_ARGUMENT;
  1118. if(Curl_is_in_callback(data))
  1119. return CURLE_RECURSIVE_API_CALL;
  1120. /* Use the common function to keep connections alive. */
  1121. return Curl_cpool_upkeep(data);
  1122. }