In my code, I have asynchronous I/O with I/O Completion Ports, and for the read/write completion callbacks, I get a HANDLE (that of course can be a socket, file
HANDLE
It is just a wrapper to GetLastError if you reverse engineering ws2_32.dll, you'll find it.