c - Repeating timerfd event works with epoll and not with poll -


I am implementing a timer using timerfd. This is a relative timer that I need to repeat it at a rate forever. I want to vote on this incident and basically tried to use voting. When I did this, I used to watch the timer incident for the first time and never again. However, when I changed to use Impol (how timerfold was installed it did not change at all) it works as expected.

Here's the code with a poll:

  # include & lt; Sys / timerfd.h & gt; # Include & lt; Sys / poll.h & gt; # Include & lt; Sys / epoll.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Strings.h & gt; # Include & lt; Unistd.h & gt; Int main (int ac, char * av []) {struct pollfd p; Int Timfred; Struct itimerspec timerValue; / * Clear pollfd * / berboo (& amp; amp; amp; amp; nbsp;; p; sizeof (P)); / * Set timerified * / timerfood = timerfade_create (CLOCK_REALTIME, 0); If (timerfunds & lt; 0) {printf ("Failed to create timer FD \ n"); Exit (1); } Berboo (and timer well, shape (timer value)); TimerValue.it_value.tv_sec = 1; TimerValue.it_value.tv_nsec = 0; TimerValue.it_interval.tv_sec = 1; TimerValue.it_interval.tv_nsec = 0; / * Set event * / p.fd = timerfd; P.revents = 0; P.events = POLLIN; / * Start timer * / if (timerfade_settime (timerfood, 0, and timervalue, tap) & lt; 0) {printf ("Could not start timer \ n"); Exit (1); } / * Wait for events / / (1) {int numEvents = poll (and p, 1, -1); If (numEvents> gt; 0) {int timers Elapsed = 0; (Zero) read (PFD, and timer appended, 8); Printf ("The timer was spent:% d \ n", timer allephased); }} Exit (0); }   

And here is the code with Apollo:

  #include & lt; Sys / timerfd.h & gt; # Include & lt; Sys / poll.h & gt; # Include & lt; Sys / epoll.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Strings.h & gt; # Include & lt; Unistd.h & gt; Int main (int ac, char * av []) {struct epoll_event epollEvent; Struct epoll_event newEvents; Int Timfred; Int. Efold; Struct itimerspec timerValue; / * Set timerfund * / timerfood = timerfood_create (CLOCK_MONOTONIC, 0); If (timerfunds & lt; 0) {printf ("Failed to create timer FD \ n"); Exit (1); } Berboo (and timer well, shape (timer value)); TimerValue.it_value.tv_sec = 1; TimerValue.it_value.tv_nsec = 0; TimerValue.it_interval.tv_sec = 1; TimerValue.it_interval.tv_nsec = 0; / * Set event * / epollfd = epoll_create1 (0); EpollEvent.events = EPOLLIN; EpollEvent.data.fd = timerfd; Apoll / CTL (ApollFeed, EPOLLTCLL_ADD, TimerFode, and Apollovent); / * Start timer * / if (timerfade_settime (timerfood, 0, and timervalue, tap) & lt; 0) {printf ("Could not start timer \ n"); Exit (1); } / * Wait for events * / while (1) {int numEvents = epoll_wait (epollfd, and newEvents, 1, 0); If (numEvents> gt; 0) {int timers Elapsed = 0; (Zero) read (apolivet dtfad, and timer application, 8); Printf ("The timer was spent:% d \ n", timer allephased); }} Exit (0); }   

Any idea what I am doing wrong in the election? It probably does not mean that the timerfed should be used like this? It seems that there is a problem with Fedora (or my installation of Fedora). This system is running 3.16, and the choice () does not work.

However, on a separate Ubuntu installation with 3.13, the above mentioned survey () code works just fine. As I am using Ubuntu in the future, I will not try to track this issue on Fedora. Although I'm curious if others are seeing this same problem on the Fedora system.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -