]> git.ipfire.org Git - pakfire.git/commitdiff
httpclient: Don't terminate the loop if we don't control it
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Jan 2025 10:52:07 +0000 (10:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Jan 2025 10:52:07 +0000 (10:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/httpclient.c

index f16d73606d744a685b47091705486f8ebcd22c08..d2e85ec1d719026cfd75d38bc38ec6881b6c59c5 100644 (file)
@@ -45,6 +45,11 @@ struct pakfire_httpclient {
        struct pakfire_ctx* ctx;
        int nrefs;
 
+       // Flags
+       enum {
+               PAKFIRE_HTTPCLIENT_OWN_LOOP = (1 << 0),
+       } flags;
+
        // Base URL
        char baseurl[PATH_MAX];
 
@@ -74,6 +79,10 @@ struct pakfire_httpclient {
        unsigned int total_downloadsize;
 };
 
+static int pakfire_httpclient_has_flag(struct pakfire_httpclient* self, int flags) {
+       return self->flags & flags;
+}
+
 static int pakfire_httpclient_xfer_create(
                struct pakfire_httpclient_xfer** x, struct pakfire_xfer* xfer) {
        struct pakfire_httpclient_xfer* e = NULL;
@@ -157,9 +166,11 @@ static int pakfire_httpclient_check(struct pakfire_httpclient* client) {
                }
        }
 
-       // Terminate the event loop if there are no more transfers left
-       if (client->still_running <= 0)
-               return sd_event_exit(client->loop, 0);
+       // If we control the loop, terminate it if there are no more transfers left
+       if (pakfire_httpclient_has_flag(client, PAKFIRE_HTTPCLIENT_OWN_LOOP)) {
+               if (client->still_running <= 0)
+                       return sd_event_exit(client->loop, 0);
+       }
 
        return 0;
 }
@@ -333,6 +344,9 @@ static int pakfire_httpclient_setup_loop(struct pakfire_httpclient* client, sd_e
 
                        return r;
                }
+
+               // This is our very own loop
+               client->flags |= PAKFIRE_HTTPCLIENT_OWN_LOOP;
        }
 
        // Create a new timer