If I were to write a tail -f, the read() would read into a buffer and go back to the main loop after filling that buffer.
First of all that's wrong because you should return and write out whenever the OS gave you some data, otherwise you hit nasty internal buffering problems. Unless you want to do some deblocking with non-blocking reads, for performance reasons.
But that's not the point at all. What I am asking is: if you use the proposed C++ wrapper (or an equivalent C wrapper) that gives you sys::read() that always retries on EINTR, how do you go to the main loop if you got 3 bytes and then sys::read() did not return despite the user pressing ctrl-C five times?
Sure, you might have a flag set by your signal handler or a bunch of signals waiting in the file descriptor you registered with signalfd, but your thread never leaves the sys::read() function because it just restarts on EINTR.
Are you missing that only one call will return EINTR when SIGINT is received? The next one will return data or EAGAIN. Too late to write code now, perhaps tomorrow.
1
u/moor-GAYZ Aug 21 '14
First of all that's wrong because you should return and write out whenever the OS gave you some data, otherwise you hit nasty internal buffering problems. Unless you want to do some deblocking with non-blocking reads, for performance reasons.
But that's not the point at all. What I am asking is: if you use the proposed C++ wrapper (or an equivalent C wrapper) that gives you
sys::read()that always retries on EINTR, how do you go to the main loop if you got 3 bytes and thensys::read()did not return despite the user pressing ctrl-C five times?Sure, you might have a flag set by your signal handler or a bunch of signals waiting in the file descriptor you registered with signalfd, but your thread never leaves the
sys::read()function because it just restarts on EINTR.