]> git.ipfire.org Git - pakfire.git/commitdiff
httpclient: Launch transfers as soon as they are enqueued when not in standalone...
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Feb 2025 14:00:54 +0000 (14:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Feb 2025 14:00:54 +0000 (14:00 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/httpclient.c

index 19a257f194799d5d32e2699f192c7aebf510f8fb..fb9af9e6d0b91231f1b966d3677743584c1a536f 100644 (file)
@@ -55,7 +55,7 @@ struct pakfire_httpclient {
 
        // Flags
        enum {
-               PAKFIRE_HTTPCLIENT_OWN_LOOP = (1 << 0),
+               PAKFIRE_HTTPCLIENT_STANDALONE = (1 << 0),
        } flags;
 
        // Base URL
@@ -303,7 +303,7 @@ static int pakfire_httpclient_check(struct pakfire_httpclient* self) {
                return r;
 
        // If we control the loop, terminate it if there are no more transfers left
-       if (pakfire_httpclient_has_flag(self, PAKFIRE_HTTPCLIENT_OWN_LOOP)) {
+       if (pakfire_httpclient_has_flag(self, PAKFIRE_HTTPCLIENT_STANDALONE)) {
                if (self->still_running <= 0)
                        return sd_event_exit(self->loop, 0);
        }
@@ -481,8 +481,8 @@ static int pakfire_httpclient_setup_loop(struct pakfire_httpclient* self, sd_eve
                        return r;
                }
 
-               // This is our very own loop
-               self->flags |= PAKFIRE_HTTPCLIENT_OWN_LOOP;
+               // We are no in standalone-mode
+               self->flags |= PAKFIRE_HTTPCLIENT_STANDALONE;
        }
 
        // Create a new timer
@@ -694,7 +694,12 @@ int pakfire_httpclient_enqueue(struct pakfire_httpclient* self, struct pakfire_x
        // Keep a reference to the xfer
        TAILQ_INSERT_TAIL(&self->xfers, e, nodes);
 
-       return 0;
+       // We are done if we are running in standalone mode
+       if (pakfire_httpclient_has_flag(self, PAKFIRE_HTTPCLIENT_STANDALONE))
+               return 0;
+
+       // Otherwise we launch the transfer straight away
+       return pakfire_httpclient_launch_one(self, e);
 }
 
 int pakfire_httpclient_dequeue(struct pakfire_httpclient* self, struct pakfire_xfer* xfer) {
@@ -723,6 +728,12 @@ int pakfire_httpclient_dequeue(struct pakfire_httpclient* self, struct pakfire_x
 int pakfire_httpclient_run(struct pakfire_httpclient* self, const char* title) {
        int r = 0;
 
+       // This can only be run in standalone-mode
+       if (!pakfire_httpclient_has_flag(self, PAKFIRE_HTTPCLIENT_STANDALONE)) {
+               ERROR(self->ctx, "Trying to launch HTTP client that is not in standalone-mode\n");
+               return -ENOTSUP;
+       }
+
        // Cannot run without any transfers
        if (TAILQ_EMPTY(&self->xfers)) {
                DEBUG(self->ctx, "Skipping running HTTP client without any transfers\n");