title: How do you know a socket client disconnected?
body: <p>I'm having a little trouble using sockets in a Perl server.</p>
  
  <p>How can you know a (non-blocking) client just disconnected ?
  In C, I'm used to doing</p>
  
  <pre><code>if (recv(sock, buff, size, flags) == 0) {
      printf("Client disconnected\n";
  }
  </code></pre>
  
  <p>or the equivalent in python or other languages : <code>recv</code> returns -1 if no data is available, 0 if client exited, a positive number if data could be read.</p>
  
  <p>But perl's <code>recv</code> doesn't work this way, and using <code>$data = &lt;$sock&gt;</code> does not seem to give any possibility to know.</p>
  
  <p>Is there any (simple) possibility ?</p>