title: epoll_wait always sets EPOLLOUT bit?
body: <p>On a listening socket I set the <code>EPOLLIN</code> bit however on client connections I set <code>EPOLLIN | EPOLLOUT</code> bits to <code>struct epoll_event</code> like so:</p>
  
  <pre><code>struct epoll_event ev;
  
  ev.data.fd = fd;
  ev.events = EPOLLIN | EPOLLOUT;
  if (epoll_ctl(evs-&gt;epoll_fd, EPOLL_CTL_ADD, fd, &amp;ev) &lt; 0)
       ...
  </code></pre>
  
  <p>And this is how I test bits:</p>
  
  <pre><code>if ((events &amp; EPOLLIN) == EPOLLIN)
       ...
  if ((events &amp; EPOLLOUT) == EPOLLOUT)
       ...
  </code></pre>
  
  <p>I've also tried like:</p>
  
  <pre><code>if (events &amp; EPOLLIN)
       ...
  if (events &amp; EPOLLOUT)
       ...
  </code></pre>
  
  <p>Both ways are ALWAYS true!</p>
  
  <p>However, whenever I call epoll_wait on my epoll fd, the active file descriptor returned ALWAYS has both bits set even though send() didn't return EAGAIN but when I try to recv() it returns EAGAIN.</p>
  
  <p>I have no idea what am I supposed to do when recv() returns EAGAIN, am I supposed to remove the <code>EPOLLOUT</code> flag or what?</p>
  
  <p>More code as requested by @Nikolai N Fetissov:</p>
  
  <pre><code>static int get_active_fd(events *evs, int index, sstate_t *flags)
  {
      uint32_t events = evs-&gt;events[index].events;
      int fd = evs-&gt;events[index].data.fd;;
  
      if ((events &amp; EPOLLERR) == EPOLLERR || (events &amp; EPOLLHUP) == EPOLLHUP) {
          close(fd);
          return -1;
      }
  
      if (events &amp; EPOLLIN)
          *flags |= DATA_IN;
  
      return fd;
  }
  
  void sockset_add(events *evs, int fd)
  {
      struct epoll_event ev;
      ...
      ev.data.fd = fd;
      ev.events = EPOLLIN;
      if (epoll_ctl(evs-&gt;epoll_fd, EPOLL_CTL_ADD, fd, &amp;ev) &lt; 0)
          eprintf("sockset_add(): epoll_ctl(%d) returned an error %d(%s)\n",
                  fd, errno, strerror(errno));
  }
  </code></pre>
  
  <p>Then later where I call epoll_wait():</p>
  
  <pre><code>if (flags &amp; DATA_IN) {
         /* try to read which is impossible because this is never set.  */
  </code></pre>