From: Michael Tremer Date: Tue, 24 Jun 2025 15:55:40 +0000 (+0000) Subject: client: Use the event loop from the HTTP client X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5fbaac11828152b530e6d4b028bd012595a6fd85;p=pakfire.git client: Use the event loop from the HTTP client The HTTP client needs to have more control so that it can automatically terminate the event loop when it is done. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/client.c b/src/pakfire/client.c index 77f4ccf0..7450957f 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -284,14 +284,14 @@ int pakfire_client_create(struct pakfire_client** client, // Initialize the reference counter self->nrefs = 1; - // Store a reference to the event loop - self->loop = sd_event_ref(loop); - // Create a new HTTP client - r = pakfire_httpclient_create(&self->httpclient, self->ctx, self->loop); + r = pakfire_httpclient_create(&self->httpclient, self->ctx, loop); if (r < 0) goto ERROR; + // Store a reference to the event loop + self->loop = pakfire_httpclient_get_loop(self->httpclient); + // Store the URL r = pakfire_string_set(self->url, url); if (r < 0) diff --git a/src/pakfire/httpclient.c b/src/pakfire/httpclient.c index e4537164..81301be7 100644 --- a/src/pakfire/httpclient.c +++ b/src/pakfire/httpclient.c @@ -691,6 +691,10 @@ struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* s return NULL; } +sd_event* pakfire_httpclient_get_loop(struct pakfire_httpclient* self) { + return sd_event_ref(self->loop); +} + int pakfire_httpclient_enqueue(struct pakfire_httpclient* self, struct pakfire_xfer* xfer) { struct pakfire_httpclient_xfer* e = NULL; int r; diff --git a/src/pakfire/httpclient.h b/src/pakfire/httpclient.h index 9f09123f..52fcbb39 100644 --- a/src/pakfire/httpclient.h +++ b/src/pakfire/httpclient.h @@ -35,6 +35,8 @@ int pakfire_httpclient_create(struct pakfire_httpclient** client, struct pakfire_httpclient* pakfire_httpclient_ref(struct pakfire_httpclient* self); struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* self); +sd_event* pakfire_httpclient_get_loop(struct pakfire_httpclient* self); + int pakfire_httpclient_enqueue(struct pakfire_httpclient* self, struct pakfire_xfer* xfer); int pakfire_httpclient_dequeue(struct pakfire_httpclient* self, struct pakfire_xfer* xfer);