On unix everything is a file approach of function read()
, write()
, close()
is not supported on Win32.
I
Not sure where you're getting the idea that Windows won't allow you to use SOCKET
handles as files - as clearly stated on the Socket Handles page:
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 ReadFile, WriteFile, ReadFileEx, and WriteFileEx.
Anyways, as to how to distinguish between them on Windows, see the function NtQueryObject, which will return a handle name of \Device\Tcp
if the handle passed to it is an open SOCKET
. Read the "Remarks" section for the structure returned by this call.
Note that this approach only works XP and up, and will fail on Windows 2000 (which I'm assuming is old enough that it doesn't affect you.)