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/alpm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/libalpm/alpm.c') diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index d1265214..34c5b4b2 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -70,6 +70,11 @@ alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath, goto cleanup; } +#ifdef HAVE_LIBCURL + curl_global_init(CURL_GLOBAL_ALL); + myhandle->curlm = curl_multi_init(); +#endif + #ifdef ENABLE_NLS bindtextdomain("libalpm", LOCALEDIR); #endif @@ -104,13 +109,14 @@ int SYMEXPORT alpm_release(alpm_handle_t *myhandle) ret = -1; } - _alpm_handle_unlock(myhandle); - _alpm_handle_free(myhandle); - #ifdef HAVE_LIBCURL + curl_multi_cleanup(myhandle->curlm); curl_global_cleanup(); #endif + _alpm_handle_unlock(myhandle); + _alpm_handle_free(myhandle); + return ret; } -- cgit v1.2.3-54-g00ecf