I have been searching an answer for this question and I came across the functions timerfd_create
and epoll
in Linux. In a tutorial it was said that epoll_ctl()
has an epoll_data_t
union member of the epoll_event
structure which can be used to execute a callback
function on a timerfd
event firing. But I am not sure on how to do it. Can anyone please help.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
You can't put a callback function pointer into
epoll_event
because it can't fit in any of these slots:What you could do instead is store the timer fd in the
epoll_event
and check to see if that's the one that fires:With that setup, then when we call
epoll_wait
, we can check to see if theevent
that fired was fortimerfd
:Alternatively, if you're open to giving up some performance, you can just create a complete object hierarchy for events:
You can store an
EventHandler*
intoptr
:And that way, if everything we put into
epoll
is anEventHandler
: