]> git.ipfire.org Git - pakfire.git/commitdiff
client: Use the event loop from the HTTP client
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 Jun 2025 15:55:40 +0000 (15:55 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 Jun 2025 15:55:40 +0000 (15:55 +0000)
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 <michael.tremer@ipfire.org>
src/pakfire/client.c
src/pakfire/httpclient.c
src/pakfire/httpclient.h

index 77f4ccf0c0f32b831fce4cb4f5be9fc146437910..7450957f885dcf1502cf4e70735aadf841d1046c 100644 (file)
@@ -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)
index e45371646eba6a3861318e7ba03cba71fd1c0f85..81301be735ba7500f974cf75752fb8cca9d29954 100644 (file)
@@ -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;
index 9f09123f70afaff4c6c9aec29e82dab667dc230d..52fcbb39bc35bd553391d2db1c3026d8f99f5b4e 100644 (file)
@@ -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);