title: Is it possible (and safe) to make an accepting socket non-blocking?
body: <p>I'm looking for a way to interrupt an <a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/accept.html"><code>accept()</code></a> call on a blocking socket. Using signals is not an option, as this is meant to be in a library and I don't want to clutter the user signals. Using <code>select()</code> is another option, buf for various reason it's not very appealing in my case.</p>
  
  <p>What would work well, if possible, is to set the socket to non-blocking mode (using <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html"><code>fcntl()</code></a> and <code>O_NONBLOCK</code>) from another thread, while the socket is blocked on an <code>accept()</code> call. The expected behaviour is that the <code>accept()</code> call will return with <code>EAGAIN</code> or <code>EWOULDBLOCK</code> in <code>errno</code>.</p>
  
  <p>Would it indeed work like that? Is it safe? Portable?</p>
  
  <p>If you know about the applicability of this method to Windows (where you need to use <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms741621%28v=vs.85%29.aspx"><code>WSAIoctl()</code></a> and <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb736550%28v=vs.85%29.aspx"><code>FONBIO</code></a>), I'm also interested.</p>