title: How to set a timeout for a login in C++?
body: <p>I'm writing a timeout for a simple login on a server written in C++.
  Well, this is the code:</p>
  
  <pre><code>char username[this-&gt;BUFSIZE];
      clean(username);
      char password[this-&gt;BUFSIZE];
      clean(password);
      send(client_fd, "USER", 4, 0);
  
      //Start timer
      time_t end,start;
      double dif;
      time (&amp;start);
  
      recv(client_fd,username,BUFSIZE,0);
      send(client_fd, "PASS", 4, 0);
      recv(client_fd,password,BUFSIZE,0);
  
      //End timer
      time (&amp;end);
      dif = difftime (end,start);
              //If dif&gt;10 seconds disconnect the client.
      if(dif&gt;10)
          close(client_fd);
  </code></pre>
  
  <p>Ok it works fine, but there is just a problem: the disconnect happens only when the client end typing user + password. My goal is that the timer must close the connection at 10 seconds, independently if the client did the login or not.</p>
  
  <p>Is it possible?
  Thank you!</p>