I read the man
pages, and my understanding is that if write()
fails and sets the errno
to EAGAIN
or EINTR
, I may
EINTR
and EAGAIN
handling should often be slightly different. EAGAIN
is always some kind of transient error representing the state of the socket buffer (or perhaps, more precisely, that your operation may block).
Once you've hit an EAGAIN
you'd likely want to sleep a bit or return control to an event loop (assuming you're using one).
With EINTR
the situation is a bit different. If your application is receiving signals non-stop, then it may be an issue in your application or environment, and for that reason I tend to have some kind of internal eintr_max
counter so I am not stuck in the theoretical situation where I just continue infinitely looping on EINTR
.
Alnitak's answer (sufficient for most cases) should also be saving errno
somewhere, as it may be clobbered by perror()
(although it may have been omitted for brevity).