]> git.ipfire.org Git - pakfire.git/commitdiff
httpclient: Tell cURL how many transfers we want to run in parallel
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 12 Aug 2024 14:10:40 +0000 (14:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 12 Aug 2024 14:10:40 +0000 (14:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/httpclient.c

index 825fe5d8dde15cd0618b30f1a635e9f9650795ae..2af55f02c35ae5e3f4fe15be1c46480cd216182f 100644 (file)
@@ -32,7 +32,7 @@
 #include <pakfire/xfer.h>
 
 // The number of concurrent downloads
-#define MAX_PARALLEL                   4
+#define DEFAULT_MAX_PARALLEL                   4
 
 struct pakfire_xfer_element {
        TAILQ_ENTRY(pakfire_xfer_element) nodes;
@@ -54,7 +54,8 @@ struct pakfire_httpclient {
        // Progress
        struct pakfire_progress* progress;
 
-       int parallel;
+       // How many transfers in parallel?
+       long max_parallel;
 
        // cURL share handle
        CURLSH* share;
@@ -94,7 +95,7 @@ static int pakfire_httpclient_start_transfers(
        int r;
 
        // Keep running until we have reached our ceiling
-       while (client->still_running < client->parallel) {
+       while (client->still_running < client->max_parallel) {
                // We are done if there are no more transfers in the queue
                if (TAILQ_EMPTY(&client->xfers_queued))
                        break;
@@ -440,6 +441,15 @@ static int pakfire_httpclient_setup_curl(struct pakfire_httpclient* client) {
                return r;
        }
 
+       // Limit parallel transfers
+       r = curl_multi_setopt(client->curl, CURLMOPT_MAXCONNECTS, client->max_parallel);
+       if (r) {
+               CTX_ERROR(client->ctx, "Could not set max parallel transfers: %s\n",
+                       curl_multi_strerror(r));
+
+               return r;
+       }
+
        return 0;
 }
 
@@ -516,7 +526,7 @@ int pakfire_httpclient_create(struct pakfire_httpclient** client, struct pakfire
        c->nrefs = 1;
 
        // Set parallelism
-       c->parallel = MAX_PARALLEL;
+       c->max_parallel = DEFAULT_MAX_PARALLEL;
 
        // Init transfer queues
        TAILQ_INIT(&c->xfers_queued);