Question

Greetings,

I was wondering if there is a way to use a timer in combination with linux poll/epoll API. I already use epoll and it would integrate very nice with the existing code if i could make the timer to be just another epoll event in my queue.

A possible way is maybe, a file-based Timer, like

echo 400;now > /dev/timer ; cat /dev/timer ; # outputs after 400ms "now"

just as an imaginary example. Is there something like this? Or are there other ways i could integrate it with the epoll API?

--Marenz

Was it helpful?

Solution

It is trivial to do timers with epoll, because epoll_wait also takes a timeout parameter; you simply put all your timers into a priority queue and set timeout to the time between now and the first one, then fire the events for that timer.

Or use use libevent which provides something similar.

Yes you COULD use timerfd() if you really wanted, but there's no need.

OTHER TIPS

Would the watch -n 0.4 command be any use in this situation?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top