I just spotted this note and have a couple of questions on this myself. I have a piece of code that also uses can_read() and needs to deal with signals. Or does it?
My code is actually modeled after the example in the IO:Select man page here - http://perldoc.perl.org/IO/Select.html which does not do anything special about premature wakeup:
while(@ready = $sel->can_read) {
foreach $fh (@ready) {
if($fh == $lsn) {
# Create a new socket
$new = $lsn->accept;
$sel->add($new);
}
else {
# Process socket
# Maybe we have finished with the socket
$sel->remove($fh);
$fh->close;
}
}
}
Since my code DOES seems to work correctly, even when dealing with hundreds of connections while an alarm is going off every second, my question becomes WHY does it work when I'm not paying any attention to EINTR? Am I just lucky - I highly doubt it? A number of people have been using this code for years...
When I instrumented the code it looks like the timer interrupt is indeed waking it from the can_read(). But then it immediately falls through the loop and cycles around back to the can_read(), and also wakes when there real data to process and deal with it appropriately.
As an aside, I also did try the recommended way for doing this, which pays attention to EINTR, and that works as well. So the questions then become is one way preferred to the other and why does my code, written the way it is, seem to be rock solid?
-mark |