title: Can I use select to combine stdin and accept?
body: <p>I am trying to implement a server in C++/Linux that regularly takes user input from the terminal. Initially I had implemented two separate threads to handle this behavior. But I realized that I would need something like pthread_cancel to cancel the server thread in case the user wanted to shut down the server.</p>
  
  <p>I then decided that it might be better to handle both actions in the same thread, so I dont have to worry about resource leakage. So what I have now is a 'select' call that selects over the stdin fd as well as my accepting fd. My code looks something like this...</p>
  
  <pre><code>fdset readfds;
  FD_SET(acceptfd, &amp;readfds);
  FD_SET(stdinfd, &amp;readfds);
  while(1) {
    select(n, &amp;readfds, NULL, NULL, NULL);
    ....
  }
  </code></pre>
  
  <p>For some reason I am no longer able to read input from stdin. This works fine when I remove either one of the two fds from my fd set, the other ome performs as expected. But when I leave them both in, while the acceptfd still accepts incoming connections, the stdinfd fails to respond to terminal input.</p>
  
  <p>Does anyone know what I might be doing wrong here? Is this approach inherently flawed? Should I be focusing on keeping the two actions as separate threads and figuring out a way to exit cleanly instead?</p>
  
  <p>Thanks for reading!!</p>