easy.c 35 KB

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