aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/eloop_win.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2013-02-03 15:13:37 (GMT)
committerJouni Malinen <j@w1.fi>2013-02-03 15:14:45 (GMT)
commit328bc71776dccb74824737e88009ffb6ef25af21 (patch)
tree15d35a660c408e8d7601c555428f6860ab913917 /src/utils/eloop_win.c
parent5960afcd183222e41d79a5ce1148bfe2f33d13d0 (diff)
downloadhostap-328bc71776dccb74824737e88009ffb6ef25af21.zip
hostap-328bc71776dccb74824737e88009ffb6ef25af21.tar.gz
hostap-328bc71776dccb74824737e88009ffb6ef25af21.tar.bz2
eloop_win: Update to be closer to the current eloop.c
Some fixes had were made only in eloop.c. Signed-hostap: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'src/utils/eloop_win.c')
-rw-r--r--src/utils/eloop_win.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/utils/eloop_win.c b/src/utils/eloop_win.c
index 666c957..206f1c3 100644
--- a/src/utils/eloop_win.c
+++ b/src/utils/eloop_win.c
@@ -241,10 +241,13 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs,
struct eloop_timeout *timeout, *tmp;
os_time_t now_sec;
- timeout = os_malloc(sizeof(*timeout));
+ timeout = os_zalloc(sizeof(*timeout));
if (timeout == NULL)
return -1;
- os_get_time(&timeout->time);
+ if (os_get_time(&timeout->time) < 0) {
+ os_free(timeout);
+ return -1;
+ }
now_sec = timeout->time.sec;
timeout->time.sec += secs;
if (timeout->time.sec < now_sec) {
@@ -279,6 +282,13 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs,
}
+static void eloop_remove_timeout(struct eloop_timeout *timeout)
+{
+ dl_list_del(&timeout->list);
+ os_free(timeout);
+}
+
+
int eloop_cancel_timeout(eloop_timeout_handler handler,
void *eloop_data, void *user_data)
{
@@ -292,8 +302,7 @@ int eloop_cancel_timeout(eloop_timeout_handler handler,
eloop_data == ELOOP_ALL_CTX) &&
(timeout->user_data == user_data ||
user_data == ELOOP_ALL_CTX)) {
- dl_list_del(&timeout->list);
- os_free(timeout);
+ eloop_remove_timeout(timeout);
removed++;
}
}
@@ -487,10 +496,12 @@ void eloop_run(void)
if (timeout) {
os_get_time(&now);
if (!os_time_before(&now, &timeout->time)) {
- dl_list_del(&timeout->list);
- timeout->handler(timeout->eloop_data,
- timeout->user_data);
- os_free(timeout);
+ void *eloop_data = timeout->eloop_data;
+ void *user_data = timeout->user_data;
+ eloop_timeout_handler handler =
+ timeout->handler;
+ eloop_remove_timeout(timeout);
+ handler(eloop_data, user_data);
}
}
@@ -551,8 +562,7 @@ void eloop_destroy(void)
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
struct eloop_timeout, list) {
- dl_list_del(&timeout->list);
- os_free(timeout);
+ eloop_remove_timeout(timeout);
}
os_free(eloop.readers);
os_free(eloop.signals);