title: How to use select() on sockets properly?
body: <p>I'm trying to wrap my head around calling <code>select</code> on sockets and I can't understand what I'm doing wrong.</p>
  
  <p><code>setup_server_socket</code> calls <code>bind</code> and <code>listen</code> and sets the socket to nonblocking mode.</p>
  
  <p>The following code blocks on the <code>select</code> call it seems, not moving forward to <code>FD_ISSET</code>. I tried connecting a client and it seems to succeed but <code>select</code> never returns anything.</p>
  
  <p>What's the proper way to do this? </p>
  
  <pre><code>...
  int listenfd = setup_server_socket( serverPort );
  
  if( -1 == listenfd )
      return 1;
  
  fd_set read_fds;
  FD_ZERO(&amp;read_fds);
  int fdmax = listenfd;
  
  
  // loop forever
  while( 1 )
  {
      if (select(fdmax+1, &amp;read_fds, NULL,NULL,NULL) == -1){
          perror("select");
          exit(4);
      }
  
      for (int i = 0; i&lt;= fdmax; i++){
          printf("Testing: %d, %d\n", i, FD_ISSET(i,&amp;read_fds));
  
      }return 0;
  ...
  </code></pre>