]> git.ipfire.org Git - pakfire.git/commitdiff
httpclient: Only use the context's event loop
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 Jun 2025 14:02:29 +0000 (14:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 Jun 2025 14:02:29 +0000 (14:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/client.c
src/pakfire/httpclient.c
src/pakfire/httpclient.h
src/pakfire/transaction.c
tests/libpakfire/httpclient.c
tests/testsuite.c

index 0bc8847bd6db35c2c30fd187f4a2da08c0ceb928..6a06bd7d972ecca813500aaa05aed1ecd44f6856 100644 (file)
@@ -494,7 +494,7 @@ int pakfire_client_create(struct pakfire_client** client,
                goto ERROR;
 
        // Create a new HTTP client
-       r = pakfire_httpclient_create(&self->httpclient, self->ctx, self->loop);
+       r = pakfire_httpclient_create(&self->httpclient, self->ctx);
        if (r < 0)
                goto ERROR;
 
index 2ef55bcddac66099c53aca4acb2ef26680c361f7..e02d2f4703d407fe2ebaf09fb1a92c2801d0139a 100644 (file)
@@ -503,21 +503,15 @@ static int pakfire_httpclient_exited(sd_event_source* event, void* data) {
        return sd_event_add_defer(self->loop, NULL, pakfire_httpclient_started, self);
 }
 
-static int pakfire_httpclient_setup_loop(struct pakfire_httpclient* self, sd_event* loop) {
+static int pakfire_httpclient_setup_loop(struct pakfire_httpclient* self) {
        int r;
 
-       // Use the given loop
-       if (loop) {
-               self->loop = sd_event_ref(loop);
-
-       // Otherwise create a new loop
-       } else {
-               r = pakfire_ctx_loop(self->ctx, &self->loop);
-               if (r < 0) {
-                       ERROR(self->ctx, "Could not setup event loop: %s\n", strerror(-r));
+       // Fetch the context's loop
+       r = pakfire_ctx_loop(self->ctx, &self->loop);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not setup event loop: %s\n", strerror(-r));
 
-                       return r;
-               }
+               return r;
        }
 
        // Create a new timer
@@ -659,7 +653,7 @@ static void pakfire_httpclient_free(struct pakfire_httpclient* self) {
 }
 
 int pakfire_httpclient_create(struct pakfire_httpclient** client,
-               struct pakfire_ctx* ctx, sd_event* loop) {
+               struct pakfire_ctx* ctx) {
        struct pakfire_httpclient* self = NULL;
        int r;
 
@@ -681,7 +675,7 @@ int pakfire_httpclient_create(struct pakfire_httpclient** client,
        TAILQ_INIT(&self->xfers);
 
        // Setup event loop
-       r = pakfire_httpclient_setup_loop(self, loop);
+       r = pakfire_httpclient_setup_loop(self);
        if (r)
                goto ERROR;
 
index 9f09123f70afaff4c6c9aec29e82dab667dc230d..18d4ba744ecb6a126811abeb71cbd919a9612654 100644 (file)
 #ifndef PAKFIRE_HTTPCLIENT_H
 #define PAKFIRE_HTTPCLIENT_H
 
-// systemd
-#include <systemd/sd-event.h>
-
 struct pakfire_httpclient;
 
 #include <pakfire/ctx.h>
 #include <pakfire/xfer.h>
 
-int pakfire_httpclient_create(struct pakfire_httpclient** client,
-       struct pakfire_ctx* ctx, sd_event* loop);
+int pakfire_httpclient_create(struct pakfire_httpclient** client, struct pakfire_ctx* ctx);
 
 struct pakfire_httpclient* pakfire_httpclient_ref(struct pakfire_httpclient* self);
 struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* self);
index 8bfb865e45b42e3decc6d44116b91148dfa77926..4af176049bf01baccdcaf18b254aea7e6ec36243 100644 (file)
@@ -1999,7 +1999,7 @@ int pakfire_transaction_download(struct pakfire_transaction* transaction) {
        int r;
 
        // Initialize the HTTP client
-       r = pakfire_httpclient_create(&httpclient, transaction->ctx, NULL);
+       r = pakfire_httpclient_create(&httpclient, transaction->ctx);
        if (r) {
                ERROR(transaction->ctx, "Could not initialize HTTP client: %m\n");
                return 1;
index b4dadf82286edc528d761d988dc2aa061a86560e..7ba9d0cea9659f7b63a1c58af0b65bf256b400c1 100644 (file)
@@ -31,7 +31,7 @@ static int test_create(const struct test* t) {
        int r = EXIT_FAILURE;
 
        // Create a HTTP client
-       ASSERT_SUCCESS(pakfire_httpclient_create(&client, t->ctx, NULL));
+       ASSERT_SUCCESS(pakfire_httpclient_create(&client, t->ctx));
 
        // Everything passed
        r = EXIT_SUCCESS;
index fbba9f12aadab0feebcf03e965c6771147deb25a..9807c64b16510529b351313311903644e5ec01bc 100644 (file)
@@ -85,7 +85,7 @@ static int test_run(int i, struct test* t) {
 
        // Create a HTTP client (if requested)
        if (t->flags & TEST_WANTS_HTTPCLIENT) {
-               r = pakfire_httpclient_create(&t->httpclient, t->ctx, NULL);
+               r = pakfire_httpclient_create(&t->httpclient, t->ctx);
                if (r < 0) {
                        LOG("ERROR: Could not initialize the HTTP client: %s\n", strerror(-r));
                        goto ERROR;