In short: they're almost always the same value, but for portability it's recommended to check for both values (and treat both values the same way).
For most systems, EAGAIN
and EWOULDBLOCK
will be the same. There are only a few systems in which they are different, and you can see the list of those systems in this answer.
Even the errno manpage mentions that they "may be the same [value]".
Historically, however, EWOULDBLOCK
was defined for "operation would block" - that is, the operation would have blocked, but the descriptor was placed in non-blocking mode. EAGAIN
originally indicated when a "temporary resource shortage made an operation impossible". The example used by the gnu documentation is when there are not enough resources to fork()
. Because the resource shortage was expected to be temporary, a subsequent attempt to perform the action might succeed (hence the name "again").
Practically speaking, those types of temporary resource shortages are not that common (but pretty serious when they do occur).
Most systems define these values as the same, and the systems which don't will become more and more uncommon in the future. Nevertheless, for portability reasons you should check for both values, but you should also treat both errors in the same way. As the GNU documentation states:
Portability Note: In many older Unix systems ... [EWOULDBLOCK was] a distinct error code different from EAGAIN. To make your program portable, you should check for both codes and treat them the same.