From: Michael Tremer Date: Thu, 26 Jun 2025 14:02:29 +0000 (+0000) Subject: httpclient: Only use the context's event loop X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51a6e194b6a30dc1089704479fc092c77cb4b731;p=pakfire.git httpclient: Only use the context's event loop Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/client.c b/src/pakfire/client.c index 0bc8847b..6a06bd7d 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -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; diff --git a/src/pakfire/httpclient.c b/src/pakfire/httpclient.c index 2ef55bcd..e02d2f47 100644 --- a/src/pakfire/httpclient.c +++ b/src/pakfire/httpclient.c @@ -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; diff --git a/src/pakfire/httpclient.h b/src/pakfire/httpclient.h index 9f09123f..18d4ba74 100644 --- a/src/pakfire/httpclient.h +++ b/src/pakfire/httpclient.h @@ -21,16 +21,12 @@ #ifndef PAKFIRE_HTTPCLIENT_H #define PAKFIRE_HTTPCLIENT_H -// systemd -#include - struct pakfire_httpclient; #include #include -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); diff --git a/src/pakfire/transaction.c b/src/pakfire/transaction.c index 8bfb865e..4af17604 100644 --- a/src/pakfire/transaction.c +++ b/src/pakfire/transaction.c @@ -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; diff --git a/tests/libpakfire/httpclient.c b/tests/libpakfire/httpclient.c index b4dadf82..7ba9d0ce 100644 --- a/tests/libpakfire/httpclient.c +++ b/tests/libpakfire/httpclient.c @@ -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; diff --git a/tests/testsuite.c b/tests/testsuite.c index fbba9f12..9807c64b 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -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;