I use timerfd
with zmq.
How can I use timerfd_create
and timerfd_set
to wait one second for the timer (https://man7.org/linux/man-pages/man2/timerfd_create.2.html)?
I have looked through the link but I still do not get how I can initilize a timer that waits one second per tick with create and set. This is exactly my task:
We start a timer with
timerfd_create()
, which is 1 / sec. ticking. When setting a timer with timer_set_(..)
acounter is simply incremented, which is decremented with every tick. When the counter reaches 0, the timerhas expired.
In this project we have a function timer _ set _()
, where the timer is set with the function timerfd_create and timerfd_settimer()
. I hope you can help me.
This is my progress (part of my code):
struct itimerspec timerValue; g_items[n].socket = nullptr; g_items[n].events = ZMQ_POLLIN; g_items[n].fd = timerfd_create(CLOCK_REALTIME, 0); if(g_items[n].fd == -1 ){ printf("timerfd_create() failed: errno=%d\n", errno); return -1; } timerValue.it_value.tv_sec = 1; timerValue.it_value.tv_nsec = 0; timerValue.it_interval.tv_sec = 1; timerValue.it_interval.tv_nsec = 0; timerfd_settime(g_items[n].fd, 0, &timerValue, NULL);