According to POSIX, if we use a select()
to decide when we can use a read without blocking, is it possible that the read()
is interrupted by a signal and returns EINTR
?
If we use a
select()
to decide when we can use a read without blocking, is it possible that theread()
is interrupted by a signal and returnsEINTR
?
Yes.
I infer that the question is at least in part motivated by the recognition that read()
indicates EINTR
only if it is interrupted before transferring any data. But "before transferring any data" is not the same thing as "while blocked on data becoming available". As far as the specifications are concerned, the question of whether there is any data available to read, such that a read()
call would not block, is orthogonal to the question of whether a read()
call might be interrupted by a signal before transferring any data.
If you are looking for more than that then consider also that read()
is a cancellation point, so it checks on entry whether there is a pending cancellation request. Since it does non-trivial work before performing any data transfer, there is necessarily at least a narrow window in which read()
could receive a signal before it starts transferring data, even when data are already available.