From e5e74e55002349b44d27ea0f25e43bc5d7e7f74e Mon Sep 17 00:00:00 2001 From: Kyeyoon Park Date: Wed, 6 Nov 2013 00:11:35 -0800 Subject: [PATCH] eloop: Add support for replenishing a registered timeout eloop_replenish_timeout() finds a registered matching timeout. If found, replenishes the timeout if remaining time is less than the requested time. Signed-hostap: Jouni Malinen --- src/utils/eloop.c | 31 +++++++++++++++++++++++++++++++ src/utils/eloop.h | 16 ++++++++++++++++ src/utils/eloop_win.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/src/utils/eloop.c b/src/utils/eloop.c index 12aa1251b..ddddcf17c 100644 --- a/src/utils/eloop.c +++ b/src/utils/eloop.c @@ -599,6 +599,37 @@ int eloop_is_timeout_registered(eloop_timeout_handler handler, } +int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs, + eloop_timeout_handler handler, void *eloop_data, + void *user_data) +{ + struct os_time now, requested, remaining; + struct eloop_timeout *tmp; + + dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) { + if (tmp->handler == handler && + tmp->eloop_data == eloop_data && + tmp->user_data == user_data) { + requested.sec = req_secs; + requested.usec = req_usecs; + os_get_time(&now); + os_time_sub(&tmp->time, &now, &remaining); + if (os_time_before(&remaining, &requested)) { + eloop_cancel_timeout(handler, eloop_data, + user_data); + eloop_register_timeout(requested.sec, + requested.usec, + handler, eloop_data, + user_data); + return 1; + } + } + } + + return 0; +} + + #ifndef CONFIG_NATIVE_WINDOWS static void eloop_handle_alarm(int sig) { diff --git a/src/utils/eloop.h b/src/utils/eloop.h index 0037c6355..befb0703e 100644 --- a/src/utils/eloop.h +++ b/src/utils/eloop.h @@ -222,6 +222,22 @@ int eloop_cancel_timeout_one(eloop_timeout_handler handler, int eloop_is_timeout_registered(eloop_timeout_handler handler, void *eloop_data, void *user_data); +/** + * eloop_replenish_timeout - Replenish a timeout that is already registered + * @req_secs: Requested number of seconds to the timeout + * @req_usecs: Requested number of microseconds to the timeout + * @handler: Matching callback function + * @eloop_data: Matching eloop_data + * @user_data: Matching user_data + * Returns: 1 if the timeout is replenished, 0 if no change is made + * + * Find a registered matching timeout. If found, + * replenish the timeout if remaining time is less than the requested time. + */ +int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs, + eloop_timeout_handler handler, void *eloop_data, + void *user_data); + /** * eloop_register_signal - Register handler for signals * @sig: Signal number (e.g., SIGHUP) diff --git a/src/utils/eloop_win.c b/src/utils/eloop_win.c index eda412f1b..1f40530cf 100644 --- a/src/utils/eloop_win.c +++ b/src/utils/eloop_win.c @@ -354,6 +354,37 @@ int eloop_is_timeout_registered(eloop_timeout_handler handler, } +int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs, + eloop_timeout_handler handler, void *eloop_data, + void *user_data) +{ + struct os_time now, requested, remaining; + struct eloop_timeout *tmp; + + dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) { + if (tmp->handler == handler && + tmp->eloop_data == eloop_data && + tmp->user_data == user_data) { + requested.sec = req_secs; + requested.usec = req_usecs; + os_get_time(&now); + os_time_sub(&tmp->time, &now, &remaining); + if (os_time_before(&remaining, &requested)) { + eloop_cancel_timeout(handler, eloop_data, + user_data); + eloop_register_timeout(requested.sec, + requested.usec, + handler, eloop_data, + user_data); + return 1; + } + } + } + + return 0; +} + + /* TODO: replace with suitable signal handler */ #if 0 static void eloop_handle_signal(int sig)