What does errno 126 (ENOTCONN) mean?

 
Could be also:
ConstantTypeOS
ERROR_MOD_NOT_FOUNDWin32 errorWindows
EADDRNOTAVAILerrnoSolaris
SYSTEM_THREAD_EXCEPTION_NOT_HANDLEDBugCheck CodeWindows
Previous Next
ENOPROTOOPT ENOTRECOVERABLE

ENOTCONN

ENOTCONN means a connection-oriented operation was issued without a current peer association. It can occur because connection establishment never completed, a prior failure cleared the state, the application raced a close against I/O, or a pooled socket was returned before its lifecycle was fully reset.

Native Winsock code uses WSAENOTCONN through WSAGetLastError(). A wrapper may expose this portable macro, but the root cause is found in the socket state machine: each send or receive needs to be associated with a connection attempt and a terminal outcome.

Check the lifecycle boundary

  • Record when the socket was created, bound, connected, accepted, shut down, and closed, with a monotonic sequence number.
  • Verify that completion of a nonblocking connect was checked before scheduling data I/O.
  • Prevent a close callback from racing with a queued send or receive; ownership must decide which operation wins.
  • For datagram code, distinguish a connected datagram socket from an unconnected one that requires a destination on each send.

References


Looking for a different code? Search another status or error code.