title: how to use timeouts with read() on a socket in c++ on Unix
body: <p>I want to use read() with ioctl(), but want to control how much time read should wait, by using a timeout.
  Any idea on how to do this?</p>
  
  <p>so far what i know is:</p>
  
  <pre><code>//CLIENT.cpp
  struct timeval tv={1,0};
  setsockopt( mysocket, SOL_SOCKET, SO_RCVTIMEO, (char *) &amp;tv, sizeof(tv));
  connect(mysocket, &amp;sock_dest, sizeof(struct sockaddr));
  len = read(mysocket, buffer, 10);
  </code></pre>
  
  <p>I tried using a 5 sec delay on server, but it did not timeout...</p>