diff --git a/src/event/xdbd_event.c b/src/event/xdbd_event.c index 52dee9c..482e57b 100644 --- a/src/event/xdbd_event.c +++ b/src/event/xdbd_event.c @@ -403,5 +403,7 @@ void xdbd_process_events_and_timers(xdbd_t *xdbd) { xdbd_event_process_posted(xdbd, &xdbd_posted_accept_events); + xdbd_expire_timers(); + xdbd_event_process_posted(xdbd, &xdbd_posted_events); } diff --git a/src/event/xdbd_timer.c b/src/event/xdbd_timer.c index eee6e6a..6cb4dfe 100644 --- a/src/event/xdbd_timer.c +++ b/src/event/xdbd_timer.c @@ -51,7 +51,7 @@ xdbd_remove_timer(xdbd_timer_t *timer) } xdbd_msec_t -xdbd_first_timeout() +xdbd_first_timeout(void) { xdbd_timer_t *timer; xdbd_msec_t timeout; @@ -65,3 +65,26 @@ xdbd_first_timeout() return (xdbd_msec_t) (timeout > 0 ? timeout : 0); } + +int +xdbd_expire_timers(void) +{ + xdbd_timer_t *timer; + xdbd_msec_t timeout; + int retval; + + for (;;) { + timeout = xdbd_first_timeout(); + if (timeout) + break; + + timer = xdbd_first_timer(); + xdbd_remove_timer(timer); + + retval = timer->func(timer, timer->pdata); + if (retval) + return retval; + } + + return 0; +} diff --git a/src/event/xdbd_timer.h b/src/event/xdbd_timer.h index 5eff019..a5a87f4 100644 --- a/src/event/xdbd_timer.h +++ b/src/event/xdbd_timer.h @@ -9,9 +9,15 @@ #include #include +typedef int +(*xdbd_timer_func_t)(xdbd_timer_t *timer, void *pdata); + struct xdbd_timer_s { bfdev_heap_node_t node; xdbd_msec_t time; + + xdbd_timer_func_t func; + void *pdata; }; extern bfdev_heap_root_t @@ -27,6 +33,9 @@ extern void xdbd_remove_timer(xdbd_timer_t *timer); extern xdbd_msec_t -xdbd_first_timeout(); +xdbd_first_timeout(void); + +extern int +xdbd_expire_timers(void); #endif /* __XDBD_TIMER__H__ */