I know this question is old but I think there's more to be said. To answer the specific question in the title: basically, never.
Aside from select
and poll
, EINTR
can only happen if you've installed (either by mistake/not understanding how to use sigaction
, or because you want to be able to interrupt blocking operations) interrupting signal handlers. Looping to retry when a function fails with EINTR
just undoes that. Doing so is an old anti-pattern from the 80s and early to mid 90s when lots of operating systems were buggy and reportedly generated EINTR
under non-conforming circumstances, but these bugs are long gone.
It is possible that, even in an application where you want to be able to interrupt things with signals, there is some code whose successful completion is so important that you can't treat EINTR
as an error condition and return back to the caller without completing the operation. In such a circumstance, it might make sense to install a retry loop, but it's probably better to mask signals (at least the potentially-interrupting ones) during the operation and unmasks after it finishes.