easy.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  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 "cw-out.h"
  58. #include "sendf.h" /* for failf function prototype */
  59. #include "connect.h" /* for Curl_getconnectinfo */
  60. #include "slist.h"
  61. #include "mime.h"
  62. #include "amigaos.h"
  63. #include "macos.h"
  64. #include "warnless.h"
  65. #include "sigpipe.h"
  66. #include "vssh/ssh.h"
  67. #include "setopt.h"
  68. #include "http_digest.h"
  69. #include "system_win32.h"
  70. #include "http2.h"
  71. #include "dynbuf.h"
  72. #include "altsvc.h"
  73. #include "hsts.h"
  74. #include "easy_lock.h"
  75. /* The last 3 #include files should be in this order */
  76. #include "curl_printf.h"
  77. #include "curl_memory.h"
  78. #include "memdebug.h"
  79. /* true globals -- for curl_global_init() and curl_global_cleanup() */
  80. static unsigned int initialized;
  81. static long easy_init_flags;
  82. #ifdef GLOBAL_INIT_IS_THREADSAFE
  83. static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT;
  84. #define global_init_lock() curl_simple_lock_lock(&s_lock)
  85. #define global_init_unlock() curl_simple_lock_unlock(&s_lock)
  86. #else
  87. #define global_init_lock()
  88. #define global_init_unlock()
  89. #endif
  90. /*
  91. * strdup (and other memory functions) is redefined in complicated
  92. * ways, but at this point it must be defined as the system-supplied strdup
  93. * so the callback pointer is initialized correctly.
  94. */
  95. #if defined(_WIN32_WCE)
  96. #define system_strdup _strdup
  97. #elif !defined(HAVE_STRDUP)
  98. #define system_strdup Curl_strdup
  99. #else
  100. #define system_strdup strdup
  101. #endif
  102. #if defined(_MSC_VER) && defined(_DLL)
  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(default:4232) /* MSVC extension, dllimport identity */
  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, don't 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 doesn't.
  229. */
  230. void curl_global_cleanup(void)
  231. {
  232. global_init_lock();
  233. if(!initialized) {
  234. global_init_unlock();
  235. return;
  236. }
  237. if(--initialized) {
  238. global_init_unlock();
  239. return;
  240. }
  241. Curl_ssl_cleanup();
  242. Curl_resolver_global_cleanup();
  243. #ifdef _WIN32
  244. Curl_win32_cleanup(easy_init_flags);
  245. #endif
  246. Curl_amiga_cleanup();
  247. Curl_ssh_cleanup();
  248. #ifdef DEBUGBUILD
  249. free(leakpointer);
  250. #endif
  251. easy_init_flags = 0;
  252. global_init_unlock();
  253. }
  254. /**
  255. * curl_global_trace() globally initializes curl logging.
  256. */
  257. CURLcode curl_global_trace(const char *config)
  258. {
  259. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  260. CURLcode result;
  261. global_init_lock();
  262. result = Curl_trc_opt(config);
  263. global_init_unlock();
  264. return result;
  265. #else
  266. (void)config;
  267. return CURLE_OK;
  268. #endif
  269. }
  270. /*
  271. * curl_global_sslset() globally initializes the SSL backend to use.
  272. */
  273. CURLsslset curl_global_sslset(curl_sslbackend id, const char *name,
  274. const curl_ssl_backend ***avail)
  275. {
  276. CURLsslset rc;
  277. global_init_lock();
  278. rc = Curl_init_sslset_nolock(id, name, avail);
  279. global_init_unlock();
  280. return rc;
  281. }
  282. /*
  283. * curl_easy_init() is the external interface to alloc, setup and init an
  284. * easy handle that is returned. If anything goes wrong, NULL is returned.
  285. */
  286. struct Curl_easy *curl_easy_init(void)
  287. {
  288. CURLcode result;
  289. struct Curl_easy *data;
  290. /* Make sure we inited the global SSL stuff */
  291. global_init_lock();
  292. if(!initialized) {
  293. result = global_init(CURL_GLOBAL_DEFAULT, TRUE);
  294. if(result) {
  295. /* something in the global init failed, return nothing */
  296. DEBUGF(fprintf(stderr, "Error: curl_global_init failed\n"));
  297. global_init_unlock();
  298. return NULL;
  299. }
  300. }
  301. global_init_unlock();
  302. /* We use curl_open() with undefined URL so far */
  303. result = Curl_open(&data);
  304. if(result) {
  305. DEBUGF(fprintf(stderr, "Error: Curl_open failed\n"));
  306. return NULL;
  307. }
  308. return data;
  309. }
  310. #ifdef CURLDEBUG
  311. struct socketmonitor {
  312. struct socketmonitor *next; /* the next node in the list or NULL */
  313. struct pollfd socket; /* socket info of what to monitor */
  314. };
  315. struct events {
  316. long ms; /* timeout, run the timeout function when reached */
  317. bool msbump; /* set TRUE when timeout is set by callback */
  318. int num_sockets; /* number of nodes in the monitor list */
  319. struct socketmonitor *list; /* list of sockets to monitor */
  320. int running_handles; /* store the returned number */
  321. };
  322. /* events_timer
  323. *
  324. * Callback that gets called with a new value when the timeout should be
  325. * updated.
  326. */
  327. static int events_timer(struct Curl_multi *multi, /* multi handle */
  328. long timeout_ms, /* see above */
  329. void *userp) /* private callback pointer */
  330. {
  331. struct events *ev = userp;
  332. (void)multi;
  333. if(timeout_ms == -1)
  334. /* timeout removed */
  335. timeout_ms = 0;
  336. else if(timeout_ms == 0)
  337. /* timeout is already reached! */
  338. timeout_ms = 1; /* trigger asap */
  339. ev->ms = timeout_ms;
  340. ev->msbump = TRUE;
  341. return 0;
  342. }
  343. /* poll2cselect
  344. *
  345. * convert from poll() bit definitions to libcurl's CURL_CSELECT_* ones
  346. */
  347. static int poll2cselect(int pollmask)
  348. {
  349. int omask = 0;
  350. if(pollmask & POLLIN)
  351. omask |= CURL_CSELECT_IN;
  352. if(pollmask & POLLOUT)
  353. omask |= CURL_CSELECT_OUT;
  354. if(pollmask & POLLERR)
  355. omask |= CURL_CSELECT_ERR;
  356. return omask;
  357. }
  358. /* socketcb2poll
  359. *
  360. * convert from libcurl' CURL_POLL_* bit definitions to poll()'s
  361. */
  362. static short socketcb2poll(int pollmask)
  363. {
  364. short omask = 0;
  365. if(pollmask & CURL_POLL_IN)
  366. omask |= POLLIN;
  367. if(pollmask & CURL_POLL_OUT)
  368. omask |= POLLOUT;
  369. return omask;
  370. }
  371. /* events_socket
  372. *
  373. * Callback that gets called with information about socket activity to
  374. * monitor.
  375. */
  376. static int events_socket(struct Curl_easy *easy, /* easy handle */
  377. curl_socket_t s, /* socket */
  378. int what, /* see above */
  379. void *userp, /* private callback
  380. pointer */
  381. void *socketp) /* private socket
  382. pointer */
  383. {
  384. struct events *ev = userp;
  385. struct socketmonitor *m;
  386. struct socketmonitor *prev = NULL;
  387. #if defined(CURL_DISABLE_VERBOSE_STRINGS)
  388. (void) easy;
  389. #endif
  390. (void)socketp;
  391. m = ev->list;
  392. while(m) {
  393. if(m->socket.fd == s) {
  394. if(what == CURL_POLL_REMOVE) {
  395. struct socketmonitor *nxt = m->next;
  396. /* remove this node from the list of monitored sockets */
  397. if(prev)
  398. prev->next = nxt;
  399. else
  400. ev->list = nxt;
  401. free(m);
  402. m = nxt;
  403. infof(easy, "socket cb: socket %" CURL_FORMAT_SOCKET_T
  404. " 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(easy, "socket cb: socket %" CURL_FORMAT_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(!m) {
  421. if(what == CURL_POLL_REMOVE) {
  422. /* this happens a bit too often, libcurl fix perhaps? */
  423. /* fprintf(stderr,
  424. "%s: socket %d asked to be REMOVED but not present!\n",
  425. __func__, s); */
  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(easy, "socket cb: socket %" CURL_FORMAT_SOCKET_T
  436. " ADDED as %s%s", s,
  437. (what&CURL_POLL_IN)?"IN":"",
  438. (what&CURL_POLL_OUT)?"OUT":"");
  439. }
  440. else
  441. return CURLE_OUT_OF_MEMORY;
  442. }
  443. }
  444. return 0;
  445. }
  446. /*
  447. * events_setup()
  448. *
  449. * Do the multi handle setups that only event-based transfers need.
  450. */
  451. static void events_setup(struct Curl_multi *multi, struct events *ev)
  452. {
  453. /* timer callback */
  454. curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, events_timer);
  455. curl_multi_setopt(multi, CURLMOPT_TIMERDATA, ev);
  456. /* socket callback */
  457. curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, events_socket);
  458. curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, ev);
  459. }
  460. /* wait_or_timeout()
  461. *
  462. * waits for activity on any of the given sockets, or the timeout to trigger.
  463. */
  464. static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
  465. {
  466. bool done = FALSE;
  467. CURLMcode mcode = CURLM_OK;
  468. CURLcode result = CURLE_OK;
  469. while(!done) {
  470. CURLMsg *msg;
  471. struct socketmonitor *m;
  472. struct pollfd *f;
  473. struct pollfd fds[4];
  474. int numfds = 0;
  475. int pollrc;
  476. int i;
  477. struct curltime before;
  478. struct curltime after;
  479. /* populate the fds[] array */
  480. for(m = ev->list, f = &fds[0]; m; m = m->next) {
  481. f->fd = m->socket.fd;
  482. f->events = m->socket.events;
  483. f->revents = 0;
  484. /* fprintf(stderr, "poll() %d check socket %d\n", numfds, f->fd); */
  485. f++;
  486. numfds++;
  487. }
  488. /* get the time stamp to use to figure out how long poll takes */
  489. before = Curl_now();
  490. /* wait for activity or timeout */
  491. pollrc = Curl_poll(fds, numfds, ev->ms);
  492. if(pollrc < 0)
  493. return CURLE_UNRECOVERABLE_POLL;
  494. after = Curl_now();
  495. ev->msbump = FALSE; /* reset here */
  496. if(!pollrc) {
  497. /* timeout! */
  498. ev->ms = 0;
  499. /* fprintf(stderr, "call curl_multi_socket_action(TIMEOUT)\n"); */
  500. mcode = curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0,
  501. &ev->running_handles);
  502. }
  503. else {
  504. /* here pollrc is > 0 */
  505. /* loop over the monitored sockets to see which ones had activity */
  506. for(i = 0; i< numfds; i++) {
  507. if(fds[i].revents) {
  508. /* socket activity, tell libcurl */
  509. int act = poll2cselect(fds[i].revents); /* convert */
  510. infof(multi->easyp,
  511. "call curl_multi_socket_action(socket "
  512. "%" CURL_FORMAT_SOCKET_T ")", fds[i].fd);
  513. mcode = curl_multi_socket_action(multi, fds[i].fd, act,
  514. &ev->running_handles);
  515. }
  516. }
  517. if(!ev->msbump) {
  518. /* If nothing updated the timeout, we decrease it by the spent time.
  519. * If it was updated, it has the new timeout time stored already.
  520. */
  521. timediff_t timediff = Curl_timediff(after, before);
  522. if(timediff > 0) {
  523. if(timediff > ev->ms)
  524. ev->ms = 0;
  525. else
  526. ev->ms -= (long)timediff;
  527. }
  528. }
  529. }
  530. if(mcode)
  531. return CURLE_URL_MALFORMAT;
  532. /* we don't really care about the "msgs_in_queue" value returned in the
  533. second argument */
  534. msg = curl_multi_info_read(multi, &pollrc);
  535. if(msg) {
  536. result = msg->data.result;
  537. done = TRUE;
  538. }
  539. }
  540. return result;
  541. }
  542. /* easy_events()
  543. *
  544. * Runs a transfer in a blocking manner using the events-based API
  545. */
  546. static CURLcode easy_events(struct Curl_multi *multi)
  547. {
  548. /* this struct is made static to allow it to be used after this function
  549. returns and curl_multi_remove_handle() is called */
  550. static struct events evs = {2, FALSE, 0, NULL, 0};
  551. /* if running event-based, do some further multi inits */
  552. events_setup(multi, &evs);
  553. return wait_or_timeout(multi, &evs);
  554. }
  555. #else /* CURLDEBUG */
  556. /* when not built with debug, this function doesn't exist */
  557. #define easy_events(x) CURLE_NOT_BUILT_IN
  558. #endif
  559. static CURLcode easy_transfer(struct Curl_multi *multi)
  560. {
  561. bool done = FALSE;
  562. CURLMcode mcode = CURLM_OK;
  563. CURLcode result = CURLE_OK;
  564. while(!done && !mcode) {
  565. int still_running = 0;
  566. mcode = curl_multi_poll(multi, NULL, 0, 1000, NULL);
  567. if(!mcode)
  568. mcode = curl_multi_perform(multi, &still_running);
  569. /* only read 'still_running' if curl_multi_perform() return OK */
  570. if(!mcode && !still_running) {
  571. int rc;
  572. CURLMsg *msg = curl_multi_info_read(multi, &rc);
  573. if(msg) {
  574. result = msg->data.result;
  575. done = TRUE;
  576. }
  577. }
  578. }
  579. /* Make sure to return some kind of error if there was a multi problem */
  580. if(mcode) {
  581. result = (mcode == CURLM_OUT_OF_MEMORY) ? CURLE_OUT_OF_MEMORY :
  582. /* The other multi errors should never happen, so return
  583. something suitably generic */
  584. CURLE_BAD_FUNCTION_ARGUMENT;
  585. }
  586. return result;
  587. }
  588. /*
  589. * easy_perform() is the external interface that performs a blocking
  590. * transfer as previously setup.
  591. *
  592. * CONCEPT: This function creates a multi handle, adds the easy handle to it,
  593. * runs curl_multi_perform() until the transfer is done, then detaches the
  594. * easy handle, destroys the multi handle and returns the easy handle's return
  595. * code.
  596. *
  597. * REALITY: it can't just create and destroy the multi handle that easily. It
  598. * needs to keep it around since if this easy handle is used again by this
  599. * function, the same multi handle must be reused so that the same pools and
  600. * caches can be used.
  601. *
  602. * DEBUG: if 'events' is set TRUE, this function will use a replacement engine
  603. * instead of curl_multi_perform() and use curl_multi_socket_action().
  604. */
  605. static CURLcode easy_perform(struct Curl_easy *data, bool events)
  606. {
  607. struct Curl_multi *multi;
  608. CURLMcode mcode;
  609. CURLcode result = CURLE_OK;
  610. SIGPIPE_VARIABLE(pipe_st);
  611. if(!data)
  612. return CURLE_BAD_FUNCTION_ARGUMENT;
  613. if(data->set.errorbuffer)
  614. /* clear this as early as possible */
  615. data->set.errorbuffer[0] = 0;
  616. if(data->multi) {
  617. failf(data, "easy handle already used in multi handle");
  618. return CURLE_FAILED_INIT;
  619. }
  620. if(data->multi_easy)
  621. multi = data->multi_easy;
  622. else {
  623. /* this multi handle will only ever have a single easy handled attached
  624. to it, so make it use minimal hashes */
  625. multi = Curl_multi_handle(1, 3, 7);
  626. if(!multi)
  627. return CURLE_OUT_OF_MEMORY;
  628. data->multi_easy = multi;
  629. }
  630. if(multi->in_callback)
  631. return CURLE_RECURSIVE_API_CALL;
  632. /* Copy the MAXCONNECTS option to the multi handle */
  633. curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, (long)data->set.maxconnects);
  634. mcode = curl_multi_add_handle(multi, data);
  635. if(mcode) {
  636. curl_multi_cleanup(multi);
  637. data->multi_easy = NULL;
  638. if(mcode == CURLM_OUT_OF_MEMORY)
  639. return CURLE_OUT_OF_MEMORY;
  640. return CURLE_FAILED_INIT;
  641. }
  642. sigpipe_ignore(data, &pipe_st);
  643. /* run the transfer */
  644. result = events ? easy_events(multi) : easy_transfer(multi);
  645. /* ignoring the return code isn't nice, but atm we can't really handle
  646. a failure here, room for future improvement! */
  647. (void)curl_multi_remove_handle(multi, data);
  648. sigpipe_restore(&pipe_st);
  649. /* The multi handle is kept alive, owned by the easy handle */
  650. return result;
  651. }
  652. /*
  653. * curl_easy_perform() is the external interface that performs a blocking
  654. * transfer as previously setup.
  655. */
  656. CURLcode curl_easy_perform(struct Curl_easy *data)
  657. {
  658. return easy_perform(data, FALSE);
  659. }
  660. #ifdef CURLDEBUG
  661. /*
  662. * curl_easy_perform_ev() is the external interface that performs a blocking
  663. * transfer using the event-based API internally.
  664. */
  665. CURLcode curl_easy_perform_ev(struct Curl_easy *data)
  666. {
  667. return easy_perform(data, TRUE);
  668. }
  669. #endif
  670. /*
  671. * curl_easy_cleanup() is the external interface to cleaning/freeing the given
  672. * easy handle.
  673. */
  674. void curl_easy_cleanup(struct Curl_easy *data)
  675. {
  676. if(GOOD_EASY_HANDLE(data)) {
  677. SIGPIPE_VARIABLE(pipe_st);
  678. sigpipe_ignore(data, &pipe_st);
  679. Curl_close(&data);
  680. sigpipe_restore(&pipe_st);
  681. }
  682. }
  683. /*
  684. * curl_easy_getinfo() is an external interface that allows an app to retrieve
  685. * information from a performed transfer and similar.
  686. */
  687. #undef curl_easy_getinfo
  688. CURLcode curl_easy_getinfo(struct Curl_easy *data, CURLINFO info, ...)
  689. {
  690. va_list arg;
  691. void *paramp;
  692. CURLcode result;
  693. va_start(arg, info);
  694. paramp = va_arg(arg, void *);
  695. result = Curl_getinfo(data, info, paramp);
  696. va_end(arg);
  697. return result;
  698. }
  699. static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src)
  700. {
  701. CURLcode result = CURLE_OK;
  702. enum dupstring i;
  703. enum dupblob j;
  704. /* Copy src->set into dst->set first, then deal with the strings
  705. afterwards */
  706. dst->set = src->set;
  707. Curl_mime_initpart(&dst->set.mimepost);
  708. /* clear all dest string and blob pointers first, in case we error out
  709. mid-function */
  710. memset(dst->set.str, 0, STRING_LAST * sizeof(char *));
  711. memset(dst->set.blobs, 0, BLOB_LAST * sizeof(struct curl_blob *));
  712. /* duplicate all strings */
  713. for(i = (enum dupstring)0; i< STRING_LASTZEROTERMINATED; i++) {
  714. result = Curl_setstropt(&dst->set.str[i], src->set.str[i]);
  715. if(result)
  716. return result;
  717. }
  718. /* duplicate all blobs */
  719. for(j = (enum dupblob)0; j < BLOB_LAST; j++) {
  720. result = Curl_setblobopt(&dst->set.blobs[j], src->set.blobs[j]);
  721. if(result)
  722. return result;
  723. }
  724. /* duplicate memory areas pointed to */
  725. i = STRING_COPYPOSTFIELDS;
  726. if(src->set.str[i]) {
  727. if(src->set.postfieldsize == -1)
  728. dst->set.str[i] = strdup(src->set.str[i]);
  729. else
  730. /* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */
  731. dst->set.str[i] = Curl_memdup(src->set.str[i],
  732. curlx_sotouz(src->set.postfieldsize));
  733. if(!dst->set.str[i])
  734. return CURLE_OUT_OF_MEMORY;
  735. /* point to the new copy */
  736. dst->set.postfields = dst->set.str[i];
  737. }
  738. /* Duplicate mime data. */
  739. result = Curl_mime_duppart(dst, &dst->set.mimepost, &src->set.mimepost);
  740. if(src->set.resolve)
  741. dst->state.resolve = dst->set.resolve;
  742. return result;
  743. }
  744. /*
  745. * curl_easy_duphandle() is an external interface to allow duplication of a
  746. * given input easy handle. The returned handle will be a new working handle
  747. * with all options set exactly as the input source handle.
  748. */
  749. struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
  750. {
  751. struct Curl_easy *outcurl = calloc(1, sizeof(struct Curl_easy));
  752. if(!outcurl)
  753. goto fail;
  754. /*
  755. * We setup a few buffers we need. We should probably make them
  756. * get setup on-demand in the code, as that would probably decrease
  757. * the likeliness of us forgetting to init a buffer here in the future.
  758. */
  759. outcurl->set.buffer_size = data->set.buffer_size;
  760. /* copy all userdefined values */
  761. if(dupset(outcurl, data))
  762. goto fail;
  763. Curl_dyn_init(&outcurl->state.headerb, CURL_MAX_HTTP_HEADER);
  764. /* the connection cache is setup on demand */
  765. outcurl->state.conn_cache = NULL;
  766. outcurl->state.lastconnect_id = -1;
  767. outcurl->state.recent_conn_id = -1;
  768. outcurl->id = -1;
  769. outcurl->progress.flags = data->progress.flags;
  770. outcurl->progress.callback = data->progress.callback;
  771. #ifndef CURL_DISABLE_COOKIES
  772. outcurl->state.cookielist = NULL;
  773. if(data->cookies && data->state.cookie_engine) {
  774. /* If cookies are enabled in the parent handle, we enable them
  775. in the clone as well! */
  776. outcurl->cookies = Curl_cookie_init(outcurl, NULL, outcurl->cookies,
  777. data->set.cookiesession);
  778. if(!outcurl->cookies)
  779. goto fail;
  780. }
  781. if(data->state.cookielist) {
  782. outcurl->state.cookielist = Curl_slist_duplicate(data->state.cookielist);
  783. if(!outcurl->state.cookielist)
  784. goto fail;
  785. }
  786. #endif
  787. if(data->state.url) {
  788. outcurl->state.url = strdup(data->state.url);
  789. if(!outcurl->state.url)
  790. goto fail;
  791. outcurl->state.url_alloc = TRUE;
  792. }
  793. if(data->state.referer) {
  794. outcurl->state.referer = strdup(data->state.referer);
  795. if(!outcurl->state.referer)
  796. goto fail;
  797. outcurl->state.referer_alloc = TRUE;
  798. }
  799. /* Reinitialize an SSL engine for the new handle
  800. * note: the engine name has already been copied by dupset */
  801. if(outcurl->set.str[STRING_SSL_ENGINE]) {
  802. if(Curl_ssl_set_engine(outcurl, outcurl->set.str[STRING_SSL_ENGINE]))
  803. goto fail;
  804. }
  805. #ifndef CURL_DISABLE_ALTSVC
  806. if(data->asi) {
  807. outcurl->asi = Curl_altsvc_init();
  808. if(!outcurl->asi)
  809. goto fail;
  810. if(outcurl->set.str[STRING_ALTSVC])
  811. (void)Curl_altsvc_load(outcurl->asi, outcurl->set.str[STRING_ALTSVC]);
  812. }
  813. #endif
  814. #ifndef CURL_DISABLE_HSTS
  815. if(data->hsts) {
  816. outcurl->hsts = Curl_hsts_init();
  817. if(!outcurl->hsts)
  818. goto fail;
  819. if(outcurl->set.str[STRING_HSTS])
  820. (void)Curl_hsts_loadfile(outcurl,
  821. outcurl->hsts, outcurl->set.str[STRING_HSTS]);
  822. (void)Curl_hsts_loadcb(outcurl, outcurl->hsts);
  823. }
  824. #endif
  825. #ifdef CURLRES_ASYNCH
  826. /* Clone the resolver handle, if present, for the new handle */
  827. if(Curl_resolver_duphandle(outcurl,
  828. &outcurl->state.async.resolver,
  829. data->state.async.resolver))
  830. goto fail;
  831. #endif
  832. #ifdef USE_ARES
  833. {
  834. CURLcode rc;
  835. rc = Curl_set_dns_servers(outcurl, data->set.str[STRING_DNS_SERVERS]);
  836. if(rc && rc != CURLE_NOT_BUILT_IN)
  837. goto fail;
  838. rc = Curl_set_dns_interface(outcurl, data->set.str[STRING_DNS_INTERFACE]);
  839. if(rc && rc != CURLE_NOT_BUILT_IN)
  840. goto fail;
  841. rc = Curl_set_dns_local_ip4(outcurl, data->set.str[STRING_DNS_LOCAL_IP4]);
  842. if(rc && rc != CURLE_NOT_BUILT_IN)
  843. goto fail;
  844. rc = Curl_set_dns_local_ip6(outcurl, data->set.str[STRING_DNS_LOCAL_IP6]);
  845. if(rc && rc != CURLE_NOT_BUILT_IN)
  846. goto fail;
  847. }
  848. #endif /* USE_ARES */
  849. Curl_initinfo(outcurl);
  850. outcurl->magic = CURLEASY_MAGIC_NUMBER;
  851. /* we reach this point and thus we are OK */
  852. return outcurl;
  853. fail:
  854. if(outcurl) {
  855. #ifndef CURL_DISABLE_COOKIES
  856. free(outcurl->cookies);
  857. #endif
  858. Curl_dyn_free(&outcurl->state.headerb);
  859. Curl_altsvc_cleanup(&outcurl->asi);
  860. Curl_hsts_cleanup(&outcurl->hsts);
  861. Curl_freeset(outcurl);
  862. free(outcurl);
  863. }
  864. return NULL;
  865. }
  866. /*
  867. * curl_easy_reset() is an external interface that allows an app to re-
  868. * initialize a session handle to the default values.
  869. */
  870. void curl_easy_reset(struct Curl_easy *data)
  871. {
  872. Curl_free_request_state(data);
  873. /* zero out UserDefined data: */
  874. Curl_freeset(data);
  875. memset(&data->set, 0, sizeof(struct UserDefined));
  876. (void)Curl_init_userdefined(data);
  877. /* zero out Progress data: */
  878. memset(&data->progress, 0, sizeof(struct Progress));
  879. /* zero out PureInfo data: */
  880. Curl_initinfo(data);
  881. data->progress.flags |= PGRS_HIDE;
  882. data->state.current_speed = -1; /* init to negative == impossible */
  883. data->state.retrycount = 0; /* reset the retry counter */
  884. /* zero out authentication data: */
  885. memset(&data->state.authhost, 0, sizeof(struct auth));
  886. memset(&data->state.authproxy, 0, sizeof(struct auth));
  887. #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_DIGEST_AUTH)
  888. Curl_http_auth_cleanup_digest(data);
  889. #endif
  890. }
  891. /*
  892. * curl_easy_pause() allows an application to pause or unpause a specific
  893. * transfer and direction. This function sets the full new state for the
  894. * current connection this easy handle operates on.
  895. *
  896. * NOTE: if you have the receiving paused and you call this function to remove
  897. * the pausing, you may get your write callback called at this point.
  898. *
  899. * Action is a bitmask consisting of CURLPAUSE_* bits in curl/curl.h
  900. *
  901. * NOTE: This is one of few API functions that are allowed to be called from
  902. * within a callback.
  903. */
  904. CURLcode curl_easy_pause(struct Curl_easy *data, int action)
  905. {
  906. struct SingleRequest *k;
  907. CURLcode result = CURLE_OK;
  908. int oldstate;
  909. int newstate;
  910. bool recursive = FALSE;
  911. if(!GOOD_EASY_HANDLE(data) || !data->conn)
  912. /* crazy input, don't continue */
  913. return CURLE_BAD_FUNCTION_ARGUMENT;
  914. if(Curl_is_in_callback(data))
  915. recursive = TRUE;
  916. k = &data->req;
  917. oldstate = k->keepon & (KEEP_RECV_PAUSE| KEEP_SEND_PAUSE);
  918. /* first switch off both pause bits then set the new pause bits */
  919. newstate = (k->keepon &~ (KEEP_RECV_PAUSE| KEEP_SEND_PAUSE)) |
  920. ((action & CURLPAUSE_RECV)?KEEP_RECV_PAUSE:0) |
  921. ((action & CURLPAUSE_SEND)?KEEP_SEND_PAUSE:0);
  922. if((newstate & (KEEP_RECV_PAUSE| KEEP_SEND_PAUSE)) == oldstate) {
  923. /* Not changing any pause state, return */
  924. DEBUGF(infof(data, "pause: no change, early return"));
  925. return CURLE_OK;
  926. }
  927. /* Unpause parts in active mime tree. */
  928. if((k->keepon & ~newstate & KEEP_SEND_PAUSE) &&
  929. (data->mstate == MSTATE_PERFORMING ||
  930. data->mstate == MSTATE_RATELIMITING) &&
  931. data->state.fread_func == (curl_read_callback) Curl_mime_read) {
  932. Curl_mime_unpause(data->state.in);
  933. }
  934. /* put it back in the keepon */
  935. k->keepon = newstate;
  936. if(!(newstate & KEEP_RECV_PAUSE)) {
  937. Curl_conn_ev_data_pause(data, FALSE);
  938. result = Curl_cw_out_flush(data);
  939. if(result)
  940. return result;
  941. }
  942. #ifdef USE_HYPER
  943. if(!(newstate & KEEP_SEND_PAUSE)) {
  944. /* need to wake the send body waker */
  945. if(data->hyp.send_body_waker) {
  946. hyper_waker_wake(data->hyp.send_body_waker);
  947. data->hyp.send_body_waker = NULL;
  948. }
  949. }
  950. #endif
  951. /* if there's no error and we're not pausing both directions, we want
  952. to have this handle checked soon */
  953. if((newstate & (KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) !=
  954. (KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) {
  955. Curl_expire(data, 0, EXPIRE_RUN_NOW); /* get this handle going again */
  956. /* reset the too-slow time keeper */
  957. data->state.keeps_speed.tv_sec = 0;
  958. if(!Curl_cw_out_is_paused(data))
  959. /* if not pausing again, force a recv/send check of this connection as
  960. the data might've been read off the socket already */
  961. data->state.select_bits = CURL_CSELECT_IN | CURL_CSELECT_OUT;
  962. if(data->multi) {
  963. if(Curl_update_timer(data->multi))
  964. return CURLE_ABORTED_BY_CALLBACK;
  965. }
  966. }
  967. if(!data->state.done)
  968. /* This transfer may have been moved in or out of the bundle, update the
  969. corresponding socket callback, if used */
  970. result = Curl_updatesocket(data);
  971. if(recursive)
  972. /* this might have called a callback recursively which might have set this
  973. to false again on exit */
  974. Curl_set_in_callback(data, TRUE);
  975. return result;
  976. }
  977. static CURLcode easy_connection(struct Curl_easy *data, curl_socket_t *sfd,
  978. struct connectdata **connp)
  979. {
  980. if(!data)
  981. return CURLE_BAD_FUNCTION_ARGUMENT;
  982. /* only allow these to be called on handles with CURLOPT_CONNECT_ONLY */
  983. if(!data->set.connect_only) {
  984. failf(data, "CONNECT_ONLY is required");
  985. return CURLE_UNSUPPORTED_PROTOCOL;
  986. }
  987. *sfd = Curl_getconnectinfo(data, connp);
  988. if(*sfd == CURL_SOCKET_BAD) {
  989. failf(data, "Failed to get recent socket");
  990. return CURLE_UNSUPPORTED_PROTOCOL;
  991. }
  992. return CURLE_OK;
  993. }
  994. /*
  995. * Receives data from the connected socket. Use after successful
  996. * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
  997. * Returns CURLE_OK on success, error code on error.
  998. */
  999. CURLcode curl_easy_recv(struct Curl_easy *data, void *buffer, size_t buflen,
  1000. size_t *n)
  1001. {
  1002. curl_socket_t sfd;
  1003. CURLcode result;
  1004. ssize_t n1;
  1005. struct connectdata *c;
  1006. if(Curl_is_in_callback(data))
  1007. return CURLE_RECURSIVE_API_CALL;
  1008. result = easy_connection(data, &sfd, &c);
  1009. if(result)
  1010. return result;
  1011. if(!data->conn)
  1012. /* on first invoke, the transfer has been detached from the connection and
  1013. needs to be reattached */
  1014. Curl_attach_connection(data, c);
  1015. *n = 0;
  1016. result = Curl_read(data, sfd, buffer, buflen, &n1);
  1017. if(result)
  1018. return result;
  1019. *n = (size_t)n1;
  1020. return CURLE_OK;
  1021. }
  1022. #ifdef USE_WEBSOCKETS
  1023. CURLcode Curl_connect_only_attach(struct Curl_easy *data)
  1024. {
  1025. curl_socket_t sfd;
  1026. CURLcode result;
  1027. struct connectdata *c = NULL;
  1028. result = easy_connection(data, &sfd, &c);
  1029. if(result)
  1030. return result;
  1031. if(!data->conn)
  1032. /* on first invoke, the transfer has been detached from the connection and
  1033. needs to be reattached */
  1034. Curl_attach_connection(data, c);
  1035. return CURLE_OK;
  1036. }
  1037. #endif /* USE_WEBSOCKETS */
  1038. /*
  1039. * Sends data over the connected socket.
  1040. *
  1041. * This is the private internal version of curl_easy_send()
  1042. */
  1043. CURLcode Curl_senddata(struct Curl_easy *data, const void *buffer,
  1044. size_t buflen, ssize_t *n)
  1045. {
  1046. curl_socket_t sfd;
  1047. CURLcode result;
  1048. ssize_t n1;
  1049. struct connectdata *c = NULL;
  1050. SIGPIPE_VARIABLE(pipe_st);
  1051. result = easy_connection(data, &sfd, &c);
  1052. if(result)
  1053. return result;
  1054. if(!data->conn)
  1055. /* on first invoke, the transfer has been detached from the connection and
  1056. needs to be reattached */
  1057. Curl_attach_connection(data, c);
  1058. *n = 0;
  1059. sigpipe_ignore(data, &pipe_st);
  1060. result = Curl_write(data, sfd, buffer, buflen, &n1);
  1061. sigpipe_restore(&pipe_st);
  1062. if(n1 == -1)
  1063. return CURLE_SEND_ERROR;
  1064. /* detect EAGAIN */
  1065. if(!result && !n1)
  1066. return CURLE_AGAIN;
  1067. *n = n1;
  1068. return result;
  1069. }
  1070. /*
  1071. * Sends data over the connected socket. Use after successful
  1072. * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
  1073. */
  1074. CURLcode curl_easy_send(struct Curl_easy *data, const void *buffer,
  1075. size_t buflen, size_t *n)
  1076. {
  1077. ssize_t written = 0;
  1078. CURLcode result;
  1079. if(Curl_is_in_callback(data))
  1080. return CURLE_RECURSIVE_API_CALL;
  1081. result = Curl_senddata(data, buffer, buflen, &written);
  1082. *n = (size_t)written;
  1083. return result;
  1084. }
  1085. /*
  1086. * Wrapper to call functions in Curl_conncache_foreach()
  1087. *
  1088. * Returns always 0.
  1089. */
  1090. static int conn_upkeep(struct Curl_easy *data,
  1091. struct connectdata *conn,
  1092. void *param)
  1093. {
  1094. struct curltime *now = param;
  1095. if(Curl_timediff(*now, conn->keepalive) <= data->set.upkeep_interval_ms)
  1096. return 0;
  1097. /* briefly attach for action */
  1098. Curl_attach_connection(data, conn);
  1099. if(conn->handler->connection_check) {
  1100. /* Do a protocol-specific keepalive check on the connection. */
  1101. conn->handler->connection_check(data, conn, CONNCHECK_KEEPALIVE);
  1102. }
  1103. else {
  1104. /* Do the generic action on the FIRSTSOCKE filter chain */
  1105. Curl_conn_keep_alive(data, conn, FIRSTSOCKET);
  1106. }
  1107. Curl_detach_connection(data);
  1108. conn->keepalive = *now;
  1109. return 0; /* continue iteration */
  1110. }
  1111. static CURLcode upkeep(struct conncache *conn_cache, void *data)
  1112. {
  1113. struct curltime now = Curl_now();
  1114. /* Loop over every connection and make connection alive. */
  1115. Curl_conncache_foreach(data,
  1116. conn_cache,
  1117. &now,
  1118. conn_upkeep);
  1119. return CURLE_OK;
  1120. }
  1121. /*
  1122. * Performs connection upkeep for the given session handle.
  1123. */
  1124. CURLcode curl_easy_upkeep(struct Curl_easy *data)
  1125. {
  1126. /* Verify that we got an easy handle we can work with. */
  1127. if(!GOOD_EASY_HANDLE(data))
  1128. return CURLE_BAD_FUNCTION_ARGUMENT;
  1129. if(data->multi_easy) {
  1130. /* Use the common function to keep connections alive. */
  1131. return upkeep(&data->multi_easy->conn_cache, data);
  1132. }
  1133. else {
  1134. /* No connections, so just return success */
  1135. return CURLE_OK;
  1136. }
  1137. }