From f02805c676d0ffbbd400c7a311477f14b8ecfe0f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 26 Jun 2022 16:24:39 +0200 Subject: -improve anastasis-gtk with hanging provider: shorten timeout when applicable --- src/reducer/anastasis_api_redux.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/reducer/anastasis_api_redux.c b/src/reducer/anastasis_api_redux.c index 8090e00..7554b06 100644 --- a/src/reducer/anastasis_api_redux.c +++ b/src/reducer/anastasis_api_redux.c @@ -137,6 +137,16 @@ struct ConfigRequest */ struct ConfigReduxWaiting *w_tail; + /** + * When did we start? + */ + struct GNUNET_TIME_Absolute start_time; + + /** + * When do we time out? + */ + struct GNUNET_TIME_Absolute timeout_at; + /** * Obtained status code. */ @@ -673,12 +683,34 @@ check_config (struct GNUNET_TIME_Relative timeout, cr->url)) continue; if (NULL != cr->co) + { + struct GNUNET_TIME_Relative duration; + struct GNUNET_TIME_Relative left; + struct GNUNET_TIME_Relative xleft; + + duration = GNUNET_TIME_absolute_get_duration (cr->start_time); + left = GNUNET_TIME_relative_subtract (timeout, + duration); + xleft = GNUNET_TIME_absolute_get_remaining (cr->timeout_at); + if (GNUNET_TIME_relative_cmp (left, + <, + xleft)) + { + /* new timeout is shorter! */ + cr->timeout_at = GNUNET_TIME_relative_to_absolute (left); + GNUNET_SCHEDULER_cancel (cr->tt); + cr->tt = GNUNET_SCHEDULER_add_at (cr->timeout_at, + &config_request_timeout, + cr); + } return cr; /* already on it */ + } break; } if (NULL == cr) { cr = GNUNET_new (struct ConfigRequest); + cr->start_time = GNUNET_TIME_absolute_get (); cr->url = GNUNET_strdup (url); GNUNET_CONTAINER_DLL_insert (cr_head, cr_tail, @@ -695,9 +727,10 @@ check_config (struct GNUNET_TIME_Relative timeout, GNUNET_break (0); return NULL; } - cr->tt = GNUNET_SCHEDULER_add_delayed (timeout, - &config_request_timeout, - cr); + cr->timeout_at = GNUNET_TIME_relative_to_absolute (timeout); + cr->tt = GNUNET_SCHEDULER_add_at (cr->timeout_at, + &config_request_timeout, + cr); return cr; } -- cgit v1.2.3