title: epoll with edge triggered event
body: <p>The  man page of <a href="http://linux.die.net/man/7/epoll" rel="nofollow noreferrer">epoll</a> has a sample code  for edge triggered  like the following :</p>
  
  <pre><code>for (;;) {
      nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);
      if (nfds == -1) {
          perror("epoll_pwait");
          exit(EXIT_FAILURE);
      }
  
      for (n = 0; n &lt; nfds; ++n) {
          if (events[n].data.fd == listen_sock) {
              conn_sock = accept(listen_sock,
                          (struct sockaddr *) &amp;local, &amp;addrlen);
              if (conn_sock == -1) {
                  perror("accept");
                  exit(EXIT_FAILURE);
              }
              setnonblocking(conn_sock);
              ev.events = EPOLLIN | EPOLLET;
              ev.data.fd = conn_sock;
              if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock,
                      &amp;ev) == -1) {
                  perror("epoll_ctl: conn_sock");
                  exit(EXIT_FAILURE);
              }
          } else {
              do_use_fd(events[n].data.fd);
          }
      }
  }
  </code></pre>
  
  <p>In function do_use_fd ,  i call nonblocked recv in while loop until EAGAIN, the sample code works fine.</p>
  
  <p>I have a question about this sample code, suppose now I have 50 socket clients connections , suddenly  10 clients writes data at the same time, so epoll_wait() will return 10 and then go to for loop :</p>
  
  <pre><code>for (n = 0; n &lt; nfds; ++n)
  </code></pre>
  
  <p>it will call  <code>do_use_fd(events[n].data.fd);</code>  for those 10 clients , suppose n=5 is done , and  n=6  is not yet finished ,  suddenly the file description of event n= 3 has receive new data , after all of those 10 events are done  and back to epoll_wait , will I get the event inform me that there is a client has new data to read  ? or I will miss it because when event happened , the code not in epoll_wait !!</p>