unsigned int parallel;
+ // cURL share handle
+ CURLSH* share;
+
// cURL multi handle
CURLM* curl;
return r;
}
+ // Create a new share handle
+ downloader->share = curl_share_init();
+ if (!downloader->share) {
+ CTX_ERROR(downloader->ctx, "Could not setup cURL share handle\n");
+ return 1;
+ }
+
// Create a new multi handle
downloader->curl = curl_multi_init();
if (!downloader->curl) {
return 1;
}
+ // Share connections between handles
+ r = curl_share_setopt(downloader->share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
+ if (r) {
+ CTX_ERROR(downloader->ctx, "Could not configure the share handle: %s\n",
+ curl_share_strerror(r));
+ return r;
+ }
+
// Limit the amount of parallel downloads
curl_multi_setopt(downloader->curl, CURLMOPT_MAXCONNECTS, (long)MAX_PARALLEL);
pakfire_downloader_transfer_unref(transfer);
}
+ if (downloader->share)
+ curl_share_cleanup(downloader->share);
if (downloader->curl)
curl_multi_cleanup(downloader->curl);
if (downloader->ctx)
const char* proxy = NULL;
int r;
+ // Configure the share handle
+ r = curl_easy_setopt(transfer->handle, CURLOPT_SHARE, downloader->share);
+ if (r) {
+ CTX_ERROR(downloader->ctx, "Could not configure cURL share handle: %s\n",
+ curl_easy_strerror(r));
+ return r;
+ }
+
// Fetch global configuration
config = pakfire_ctx_get_config(downloader->ctx);