title: select() always returns 0
body: <p>I seem to have a problem with <code>select</code>.</p>
  
  <pre><code>while(!sendqueue.empty())
  {                                   
    if(!atms_connection.connected)
    {
      //print error message
      goto RECONNECT;
    }
  
    //select new
    FD_ZERO(&amp;wfds);
    FD_SET(atms_connection.socket, &amp;wfds);
  
    tv.tv_sec = 1;
    tv.tv_usec = 0;
  
    retval = select(atms_connection.socket + 1, NULL, &amp;wfds, NULL, &amp;tv);
  
    if (retval == -1) {
      printf("Select failed\n");                      
      break;
    }                     
    else if (retval) {
      printf("Sent a Message.\n"); 
    }
    else {
      //printf("retval value is %d\n",retval);
      printf("Server buffer is full, try again...\n");                        
      break;
    }
    n = write(atms_connection.socket, sendqueue.front().c_str(), sendqueue.front().length());
  }
  </code></pre>
  
  <p>The function belongs to a thread, which, when it acquires the lock cleans a queue using select() and writes to socket in a loop until the queue is empty.</p>
  
  <p>The first time the thread gets the lock it <code>select()</code> fine, but the second time it gets the lock and enters the while it always returns 0.</p>
  
  <p>For the record, it used to work fine a while ago, and I haven't changed that code since then.</p>