| Previous | Next |
| ENETUNREACH | ENETRESET |
ENOTSOCK
ENOTSOCK is a handle-identity failure: the object supplied to a socket operation is not a socket in the current API context. The common causes are passing a file handle through a generic descriptor abstraction, using a closed or recycled value, mixing CRT file descriptors with Winsock SOCKET values, or corrupting ownership across threads.
Native Winsock reports WSAENOTSOCK via WSAGetLastError(). Do not cast one handle type to another just because both are integer-like on a particular build. Their lifetime, invalid sentinel, close function, and error channel are different.
Evidence for a handle mismatch
- Log the operation, logical object type, creation site, close site, native handle value, and any conversion performed by a wrapper.
- Track generations or ownership tokens so a recycled handle value cannot be mistaken for the previous socket.
- Use
closesocketonly for Winsock sockets and the documented close path for CRT or Win32 handles. - Make wrapper types non-interchangeable where possible; compile-time separation prevents many runtime handle bugs.
References
Looking for a different code? Search another status or error code.