From 5cfe0dfffcf423c411004ac565959c686bfb24c9 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 24 Feb 2020 09:49:13 +0000 Subject: fetchers: Apply cleaner ring handling mechanic to other fetchers Signed-off-by: Daniel Silverstone --- content/fetchers/data.c | 17 ++++++++++++++++- content/fetchers/file.c | 17 ++++++++++++++++- content/fetchers/resource.c | 17 ++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) (limited to 'content') diff --git a/content/fetchers/data.c b/content/fetchers/data.c index 8e6305dd9..8316d15f4 100644 --- a/content/fetchers/data.c +++ b/content/fetchers/data.c @@ -246,6 +246,7 @@ static void fetch_data_poll(lwc_string *scheme) { fetch_msg msg; struct fetch_data_context *c, *next; + bool was_last_item = false; if (ring == NULL) return; @@ -314,14 +315,28 @@ static void fetch_data_poll(lwc_string *scheme) * processing this item may have added to the ring. */ next = c->r_next; + was_last_item = next == c; fetch_remove_from_queues(c->parent_fetch); fetch_free(c->parent_fetch); + /* Having called into the fetch machinery, our ring might + * have been updated + */ + if (was_last_item) { + /* We were previously the last item in the ring + * so let's reset to the head of the ring + * and try again + */ + c = ring; + } else { + c = next; + } + /* Advance to next ring entry, exiting if we've reached * the start of the ring or the ring has become empty */ - } while ( (c = next) != ring && ring != NULL); + } while (ring != NULL); } nserror fetch_data_register(void) diff --git a/content/fetchers/file.c b/content/fetchers/file.c index b5b4221dc..ede001faf 100644 --- a/content/fetchers/file.c +++ b/content/fetchers/file.c @@ -792,6 +792,7 @@ static void fetch_file_process(struct fetch_file_context *ctx) static void fetch_file_poll(lwc_string *scheme) { struct fetch_file_context *c, *next; + bool was_last_item = false; if (ring == NULL) return; @@ -819,14 +820,28 @@ static void fetch_file_poll(lwc_string *scheme) * processing this item may have added to the ring. */ next = c->r_next; + was_last_item = next == c; fetch_remove_from_queues(c->fetchh); fetch_free(c->fetchh); + /* Having called into the fetch machinery, our ring might + * have been updated + */ + if (was_last_item) { + /* We were previously the last item in the ring + * so let's reset to the head of the ring + * and try again + */ + c = ring; + } else { + c = next; + } + /* Advance to next ring entry, exiting if we've reached * the start of the ring or the ring has become empty */ - } while ( (c = next) != ring && ring != NULL); + } while (ring != NULL); } nserror fetch_file_register(void) diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c index 9b3f28ce5..286f99e12 100644 --- a/content/fetchers/resource.c +++ b/content/fetchers/resource.c @@ -434,6 +434,7 @@ static void fetch_resource_abort(void *ctx) static void fetch_resource_poll(lwc_string *scheme) { struct fetch_resource_context *c, *next; + bool was_last_item = false; if (ring == NULL) return; @@ -461,14 +462,28 @@ static void fetch_resource_poll(lwc_string *scheme) * as processing this item may have added to the ring */ next = c->r_next; + was_last_item = next == c; fetch_remove_from_queues(c->fetchh); fetch_free(c->fetchh); + /* Having called into the fetch machinery, our ring might + * have been updated + */ + if (was_last_item) { + /* We were previously the last item in the ring + * so let's reset to the head of the ring + * and try again + */ + c = ring; + } else { + c = next; + } + /* Advance to next ring entry, exiting if we've reached * the start of the ring or the ring has become empty */ - } while ( (c = next) != ring && ring != NULL); + } while (ring != NULL); } nserror fetch_resource_register(void) -- cgit v1.2.3