From dc98d0ea09f3632cd28a12099f3f09d466dcad1d Mon Sep 17 00:00:00 2001 From: Anatol Pomozov Date: Mon, 9 Mar 2020 15:23:12 -0700 Subject: Add multi_curl handle to ALPM global context To be able to run multiple download in parallel efficiently we need to use curl_multi interface [1]. It introduces a set of APIs over new type of handler 'CURLM'. Create CURLM object at the application start and set it to global ALPM context. The 'single-download' CURL handle moves to payload struct. A new CURL handle is created for each payload with intention to be processed by CURLM. Note that curl_download_internal() is not ported to CURLM interface due to the fact that the function will go away soon. [1] https://curl.haxx.se/libcurl/c/libcurl-multi.html Signed-off-by: Allan McRae --- lib/libalpm/dload.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'lib/libalpm/dload.c') diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 8dc259f2..71b26d23 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -72,15 +72,6 @@ static char *get_fullpath(const char *path, const char *filename, return filepath; } -static CURL *get_libcurl_handle(alpm_handle_t *handle) -{ - if(!handle->curl) { - curl_global_init(CURL_GLOBAL_SSL); - handle->curl = curl_easy_init(); - } - return handle->curl; -} - enum { ABORT_SIGINT = 1, ABORT_OVER_MAXFILESIZE @@ -241,7 +232,7 @@ static size_t dload_parseheader_cb(void *ptr, size_t size, size_t nmemb, void *u } } - curl_easy_getinfo(payload->handle->curl, CURLINFO_RESPONSE_CODE, &respcode); + curl_easy_getinfo(payload->curl, CURLINFO_RESPONSE_CODE, &respcode); if(payload->respcode != respcode) { payload->respcode = respcode; } @@ -377,8 +368,9 @@ static int curl_download_internal(struct dload_payload *payload, struct sigaction orig_sig_pipe, orig_sig_int; /* shortcut to our handle within the payload */ alpm_handle_t *handle = payload->handle; - CURL *curl = get_libcurl_handle(handle); + CURL *curl = curl_easy_init(); handle->pm_errno = ALPM_ERR_OK; + payload->curl = curl; /* make sure these are NULL */ FREE(payload->tempfile_name); @@ -592,6 +584,9 @@ cleanup: unlink(payload->tempfile_name); } + curl_easy_cleanup(curl); + payload->curl = NULL; + /* restore the old signal handlers */ unmask_signal(SIGINT, &orig_sig_int); unmask_signal(SIGPIPE, &orig_sig_pipe); -- cgit v1.2.3-54-g00ecf