title: How does the poll function work in c?
body: <p>I am new to socket programming and I'm trying to figure out how poll works. So I made a little example program. The program seems to work as how I expect it to, but when I comment out the line that has <code>int dummy</code>  the <code>for</code> loop only runs one iteration when it's suppose to do ten. What I don't understand is how that variable has anything to do with the <code>for</code> loop. The program is suppose to print "timeout" after 3.5 secs and print "return hit" if there is input available.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;poll.h&gt;
  
  int main(int argc, char *argv[]) {
      int a;
      int b;
      int c;
      char buf[10];
      int i;
      struct pollfd ufds[1];      
      ufds[0].fd = 0;
      ufds[0].events = POLLIN;
      int rv;
      int dummy;
      for(i=0; i &lt; 10; i++) {
          printf("%i ", i);
          if((rv = poll(ufds, 2, 3500)) == -1) perror("select");
          else if (rv == 0) printf("Timeout occurred!\n");
          else if (ufds[0].revents &amp; POLLIN) {
              printf("return hit\n");
              read(0, buf, 10);
          }   
          fflush(stdout); 
      }   
      return 0;
  }
  </code></pre>