| Previous | Next |
| ENOTBLK |
EAGAIN
On a socket, EAGAIN is normally a backpressure signal rather than a broken connection. A nonblocking receive has no data available yet, or a nonblocking send cannot currently accept more bytes into the local output buffer. The same code can also be returned when a socket receive timeout expires before data arrives.
Portable code must also consider EWOULDBLOCK. POSIX allows the two names to have different numeric values, even though many systems define them as the same value. An event loop should stop the current read or write pass when it receives either result, wait for the appropriate readiness event, and then retry. Repeating the system call in a tight loop only burns CPU.
What to check
- Confirm whether
O_NONBLOCK,MSG_DONTWAIT, or a socket timeout is in use. - For writes, preserve unsent bytes and resume from the correct offset after the socket becomes writable.
- For reads, distinguish
EAGAINfrom a zero-length return, which has different stream-socket semantics.
On Linux, an unbound Internet datagram socket can also report EAGAIN when every ephemeral port is in use, so the failing call and socket type matter.
Linux recv(2) · Linux send(2) · POSIX error definitions
Looking for a different code? Search another status or error code.