title: epoll (EPOLLET) depends on count of read bytes?
body: <p>I use epoll in edge triggered mode. to avoid starvation the code read MAX_FREAD_LENGTH bytes at once from one socket. later assembles the fragments till EOL occurs. I noticed that the epoll stuck when MAX_FREAD_LENGTH is small. I think it should work for any size of read blocks. It worked well with 512 bytes, but sometimes hangs (means no EPOLLIN event). If I increment the MAX_FREAD_LENGTH it becomes more stable. how can I fix this issue? </p>
  
  <p>Many thanks for considering my question!</p>
  
  <blockquote>
    <p>EPOLL initialize</p>
  </blockquote>
  
  <pre><code>int res;
  epFd = epoll_create(EPOLL_SIZE);
  event.data.fd = serverFd;
  event.events = EPOLLIN|EPOLLET;
  res=epoll_ctl(epFd, EPOLL_CTL_ADD, serverFd, &amp;event);
  if (res == -1){
    perror ("epoll_ctl error: ");
    return EH_ERROR;
  }
  events = calloc (MAX_EVENTS, sizeof event);
  </code></pre>
  
  <blockquote>
    <p>register net event:</p>
  </blockquote>
  
  <pre><code>while (TRUE){
    int nfds;
    do{
      nfds = epoll_wait(epFd, events, MAX_EVENTS, -1);
    } while (nfds &lt; 0 &amp;&amp; errno == EINTR);
  
    int i = 0;
    for (;i&lt;nfds;i++){
      if ( (events[i].data.fd == serverFd) &amp;&amp; (events[i].events &amp; EPOLLIN)){
        if ((clientFd = accept(serverFd,(struct sockaddr *) &amp;clientAddr, &amp;clientLen)) &lt; 0){
          char log[255];
          sprintf(log,"dispatch_net_event: Socket accept failed: %s",strerror(errno));
          logger-&gt;log(LOGG_ERROR,log);
        }
        if(newclient(clientFd)!=EH_ERROR){
          /* client created */
          setnonblocking(fd,NONBLOCKING);
          event.data.fd = clientFd;
          event.events = EPOLLIN |EPOLLET;
          if(epoll_ctl(epFd, EPOLL_CTL_ADD, fd, &amp;event)&lt;0){
            fprintf(stderr,"Epoll insertion error (fd=%d): ",clientFd);
            return EH_ERROR;             
          }    
          continue;
        }
        else{
          logger-&gt;log(LOGG_ERROR,"Client creation error");
          continue;
        }
      }
      else{
       dispatch_event(events[i].data.fd,NET_EVENT);
      }
    }
  }
  </code></pre>
  
  <blockquote>
    <p>handle a net event</p>
  </blockquote>
  
  <pre><code>#define SMTP_MAX_LINE_LENGTH MAX_FREAD_LENGTH
  ssize_t count;
  char buf[SMTP_MAX_LINE_LENGTH];
  
  memset(buf,'\0', SMTP_MAX_LINE_LENGTH);
  count = read (fd, buf,MAX_FREAD_LENGTH );
  
  if (count==-1){
    if (errno == EAGAIN)
      return KEEP_IT;
    else if (errno == EWOULDBLOCK)
      return KEEP_IT;
    else{
      char log[255];
      sprintf(log,"handle_net_event: Read error: %s",strerror(errno));
      logger-&gt;log(LOGG_ERROR,log);
    }
  }
  else{   /* count &gt; 0 there are data in the buffer */
    /* assemble possible partial lines, TRUE if line is whole (end with \r\n)*/
    whole=assemble_line(count,client,&amp;buf[0]);
  }
   /* process the line */
  </code></pre>
  
  <blockquote>
    <p>EDIT:</p>
  </blockquote>
  
  <p>I forgot to mention, the epoll run in a separate thread than the other parts</p>