title: How to filter epoll events?
body: <p>Lets say I am listening at multiple network ports:
    80 with TCP
    81-250 with UDP</p>
  
  <p>This requires multiple different ways of handling inputs.<br>
  - New socket at port 80 ( add new file descriptor to epoll list )<br>
  - Read from client socket at port 80<br>
  - Read from any of the other 170 UDP ports</p>
  
  <p>This are quite a lot different handles, while I would like to use epoll to only react to the ones being updated.<br>
  Is there any way epoll events can be filtered, so every event gets its needed handle, without looping through all file descriptors?</p>
  
  <p>Thanks in advance,<br>
  Sinned</p>
  
  <p>Example code:</p>
  
  <pre><code>int epfd = epoll_create( 10 );
  
  int tcpFd = createTCPSocket( 80 );
  registerListenEvent( epfd, tcpFd );
  
  int udpFds[ 170 ];
  for ( int i = 0; i &lt; 170; i++ ) {
    udpSockets[ i ] = createUdpSocket( 81 + i );
    registerUdpPacketEvent( epfd, udpFds[ i ] );
  }
  
  int tcpClientFds[ 256 ];
  int tcpClientId = 0;
  
  struct epoll_event events[ 64 ];
  
  while ( 1 ) {
    int nfds = epoll_wait( epfd, events, 64, -1 );
    for ( int i = 0; i &lt; nfds; i++ ) {
      struct epoll_event event = events[ i ];
      int fd = event.data.fd;
  
      // This kind of filtering can take quite a while
      if ( fd == tcpFd ) {
        int acceptedFd = accept( tcpFd );
        registerTcpClientEvent( epfd, acceptedFd );
        tcpClientFds[ tcpClientId++ ] = acceptedFd;
      } else {
        for ( int i = 0; i &lt; 170; i++ )
          if ( udpFds[ i ] == fd ) {
            handleUdpMessage( fd );
            return;
          }
       for ( int i = 0; i &lt; tcpClientId; i++ ) {
         if ( tcpClientFds[ i ] == fd ) {
           handleTcpMessage( fd );
           return;
         }
       }
      }
    }
  }
  </code></pre>
  
  <p>You can imagine going through 170 - 426 loops for every event can be quite costly.
  I hoped the event could be identified without this.
  Is this possible?</p>