title: Repeating timerfd event works with epoll and not with poll
body: <p>I am implementing a timer using timerfd. This is a relative timer that I just need to repeat forever at the rate it is set to. I want to poll on this event and originally tried using poll. When I did this, I would see the timer event the first time and then never again. However, when I changed to using epoll (no change at all to how the timerfd was set up) it works as expected.</p>
  
  <p>Here is the code with poll:</p>
  
  <pre><code>#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 timerfd;
      struct itimerspec timerValue;
  
      /* clear pollfd */
      bzero(&amp;p, sizeof(p));
  
      /* set timerfd */
      timerfd = timerfd_create(CLOCK_REALTIME, 0);
      if (timerfd &lt; 0) {
          printf("failed to create timer fd\n");
          exit(1);
      }
      bzero(&amp;timerValue, sizeof(timerValue));
      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 events */
      p.fd = timerfd;
      p.revents = 0;
      p.events = POLLIN;
  
      /* start timer */
      if (timerfd_settime(timerfd, 0, &amp;timerValue, NULL) &lt; 0) {
          printf("could not start timer\n");
          exit(1);
      }
  
      /* wait for events */
      while (1) {
          int numEvents = poll(&amp;p, 1, -1);
          if (numEvents &gt; 0) {
              int timersElapsed = 0;
              (void) read(p.fd, &amp;timersElapsed, 8);
              printf("timers elapsed: %d\n", timersElapsed);
          }
      }
  
      exit(0);
  }
  </code></pre>
  
  <p>And here is the code with epoll:</p>
  
  <pre><code>#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 timerfd;
      int epollfd;
      struct itimerspec timerValue;
  
      /* set timerfd */
      timerfd = timerfd_create(CLOCK_MONOTONIC, 0);
      if (timerfd &lt; 0) {
          printf("failed to create timer fd\n");
          exit(1);
      }
      bzero(&amp;timerValue, sizeof(timerValue));
      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 events */
      epollfd = epoll_create1(0);
      epollEvent.events = EPOLLIN;
      epollEvent.data.fd = timerfd;
      epoll_ctl(epollfd, EPOLL_CTL_ADD, timerfd, &amp;epollEvent);
  
      /* start timer */
      if (timerfd_settime(timerfd, 0, &amp;timerValue, NULL) &lt; 0) {
          printf("could not start timer\n");
          exit(1);
      }
  
      /* wait for events */
      while (1) {
          int numEvents = epoll_wait(epollfd, &amp;newEvents, 1, 0);
          if (numEvents &gt; 0) {
              int timersElapsed = 0;
              (void) read(epollEvent.data.fd, &amp;timersElapsed, 8);
              printf("timers elapsed: %d\n", timersElapsed);
          }
      }
  
      exit(0);
  }
  </code></pre>
  
  <p>Any idea what I might be doing wrong with poll? Maybe it is not meant to be used this way with a timerfd? Thank you.</p>