From: Michael Tremer Date: Thu, 26 Jun 2025 13:58:05 +0000 (+0000) Subject: httpclient: Make the termination code clearer X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1eac13546a528d6c0c78690deb68be39b77d2af4;p=pakfire.git httpclient: Make the termination code clearer We now simply set a flag when we launched the loop ourselves and automatically terminate once everything is done. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/httpclient.c b/src/pakfire/httpclient.c index 9662da42..2ef55bcd 100644 --- a/src/pakfire/httpclient.c +++ b/src/pakfire/httpclient.c @@ -55,7 +55,7 @@ struct pakfire_httpclient { // Flags enum { - PAKFIRE_HTTPCLIENT_STANDALONE = (1 << 0), + PAKFIRE_HTTPCLIENT_TERMINATE_ON_COMPLETION = (1 << 0), } flags; // Base URL @@ -316,10 +316,9 @@ static int pakfire_httpclient_check(struct pakfire_httpclient* self) { return r; // If we control the loop, terminate it if there are no more transfers left - if (pakfire_httpclient_has_flag(self, PAKFIRE_HTTPCLIENT_STANDALONE)) { - if (self->still_running <= 0) - return sd_event_exit(self->loop, 0); - } + if (pakfire_httpclient_has_flag(self, PAKFIRE_HTTPCLIENT_TERMINATE_ON_COMPLETION) + && (self->still_running <= 0)) + return sd_event_exit(self->loop, 0); return 0; } @@ -519,9 +518,6 @@ static int pakfire_httpclient_setup_loop(struct pakfire_httpclient* self, sd_eve return r; } - - // We are no in standalone-mode - self->flags |= PAKFIRE_HTTPCLIENT_STANDALONE; } // Create a new timer @@ -771,11 +767,10 @@ int pakfire_httpclient_dequeue(struct pakfire_httpclient* self, struct pakfire_x int pakfire_httpclient_run(struct pakfire_httpclient* self, const char* title) { int r = 0; - // This can only be run in standalone-mode - if (!pakfire_httpclient_has_flag(self, PAKFIRE_HTTPCLIENT_STANDALONE)) { - ERROR(self->ctx, "Trying to launch HTTP client that is not in standalone-mode\n"); - return -ENOTSUP; - } + // This function will start the event loop (usually used when we are running + // without an event loop in place). We need to remember to terminate the event + // loop once we have completed all transfers. + self->flags |= PAKFIRE_HTTPCLIENT_TERMINATE_ON_COMPLETION; // Set the title r = pakfire_progress_set_title(self->progress, "%s", title); @@ -815,5 +810,8 @@ ERROR: // We are finished! pakfire_progress_finish(self->progress); + // Reset + self->flags &= ~PAKFIRE_HTTPCLIENT_TERMINATE_ON_COMPLETION; + return r; }