title: Socket select() works in Windows and times out in Linux
body: <p>I'm porting a windows network application to linux and faced a timeout problem with select call on linux. The following function blocks for the entire timeout value and returns while I checked with a packet sniffer that client has already sent the data.</p>
  
  <pre><code>int recvTimeOutTCP( SOCKET socket, long sec, long usec )
  {
    struct timeval timeout;
    fd_set fds;.
  
    timeout.tv_sec = sec;
    timeout.tv_usec = usec;
    FD_ZERO( &amp;fds );
    FD_SET( socket, &amp;fds );
  
    // Possible return values:
    // -1: error occurred
    // 0: timed out
    // &gt; 0: data ready to be read
    cerr &lt;&lt; "Waiting on fd " &lt;&lt; socket &lt;&lt; endl;
    return select(1, &amp;fds, 0, 0, &amp;timeout);
  }
  </code></pre>