title: Can you _close(), _read(), and _write() a socket on windows?
body: <p>MSDN says <code>closesocket()</code> is the function to use. However, I couldn't help wondering if <code>_close()</code> will work also?</p>
  
  <p>MSDN appears to say no in their description of SOCKET type: (<a href="http://msdn.microsoft.com/en-us/windows/ms740516(v=vs.80)" rel="nofollow">http://msdn.microsoft.com/en-us/windows/ms740516(v=vs.80)</a>):</p>
  
  <blockquote>
    <p>In Winsock applications, a socket descriptor is not a file descriptor and must be used with the Winsock functions.</p>
  </blockquote>
  
  <p>and more specifically from its <a href="http://msdn.microsoft.com/en-us/windows/ms740126%28v=vs.80%29" rel="nofollow">note on renamed socket functions</a>:</p>
  
  <blockquote>
    <p>Sockets are represented by standard file descriptors in Berkeley Sockets, so the <code>close</code> function can be used to close sockets as well as regular files. While nothing in Windows Sockets prevents an implementation from using regular file handles to identify sockets, nothing requires it either. On Windows, sockets must be closed by using the <code>closesocket</code> routine. On Windows, using the <code>close</code> function to close a socket is incorrect and the effects of doing so are undefined by this specification.</p>
  </blockquote>
  
  <p>However, even despite the above, some of the Windows file functions might work with sockets in practice:</p>
  
  <p>Given that <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467%28v=vs.85%29.aspx" rel="nofollow"><code>ReadFile</code></a> and <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365747%28v=vs.85%29.aspx" rel="nofollow"><code>WriteFile</code></a> work on sockets, I suspect <code>_read</code> and <code>_write</code>, for instance, might also work with sockets as well as file handles.</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms740522%28v=vs.85%29.aspx" rel="nofollow">MSDN's overview of socket handles</a> states:</p>
  
  <blockquote>
    <p>A socket handle can optionally be a file handle in Windows Sockets 2. A socket handle from a Winsock provider can be used with other non-Winsock functions such as <code>ReadFile</code>, <code>WriteFile</code>, <code>ReadFileEx</code>, and <code>WriteFileEx</code>.</p>
  </blockquote>