EINTR
and EAGAIN
processing often should be slightly different. EAGAIN
is always some kind of temporary error representing the state of the socket buffer (or rather, that your operation may be blocked).
As soon as you press EAGAIN
, you most likely want a sleeping bit or return the control to the event loop (if you use it).
With EINTR
situation is slightly different. If your application receives signals non-stop, this may be a problem in your application or environment, and for this reason I have some kind of internal counter eintr_max
, so I was not stuck in a theoretical situation, when I just continue to loop endlessly on EINTR
.
Alnitak's answer (sufficient for most cases) should also keep errno
somewhere, as it can be tailored to perror()
(although it can be omitted for brevity).
source share