From: Michael Tremer Date: Wed, 22 Jan 2025 10:52:07 +0000 (+0000) Subject: httpclient: Don't terminate the loop if we don't control it X-Git-Tag: 0.9.30~398 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4ea2b9ee9d48765e51551a5ceffb135bbbb1bed;p=pakfire.git httpclient: Don't terminate the loop if we don't control it Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/httpclient.c b/src/pakfire/httpclient.c index f16d7360..d2e85ec1 100644 --- a/src/pakfire/httpclient.c +++ b/src/pakfire/httpclient.c @@ -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