// Flags
enum {
- PAKFIRE_HTTPCLIENT_STANDALONE = (1 << 0),
+ PAKFIRE_HTTPCLIENT_TERMINATE_ON_COMPLETION = (1 << 0),
} flags;
// Base URL
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;
}
return r;
}
-
- // We are no in standalone-mode
- self->flags |= PAKFIRE_HTTPCLIENT_STANDALONE;
}
// Create a new timer
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);
// We are finished!
pakfire_progress_finish(self->progress);
+ // Reset
+ self->flags &= ~PAKFIRE_HTTPCLIENT_TERMINATE_ON_COMPLETION;
+
return r;
}