]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
eloop: Add support for replenishing a registered timeout
authorKyeyoon Park <kyeyoonp@qca.qualcomm.com>
Wed, 6 Nov 2013 08:11:35 +0000 (00:11 -0800)
committerJouni Malinen <j@w1.fi>
Thu, 7 Nov 2013 22:22:32 +0000 (00:22 +0200)
eloop_replenish_timeout() finds a registered matching
<handler,eloop_data,user_data> timeout. If found, replenishes
the timeout if remaining time is less than the requested time.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>

src/utils/eloop.c
src/utils/eloop.h
src/utils/eloop_win.c

index 12aa1251bf86a51085eb41da70fbdc64f882b220..ddddcf17ce3427a4e0b6fc29ffe888c2e87a45ca 100644 (file)
@@ -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)
 {
index 0037c6355fdce5bb828bd69793348a74f6388259..befb0703e2e057379a76fc7d443c365afd8b9e61 100644 (file)
@@ -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 <handler,eloop_data,user_data> 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)
index eda412f1b50feb10dd27e222ef46f18a7857875c..1f40530cf1b2134b3e903411d7684278cccef837 100644 (file)
@@ -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)