| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package IO::SigGuard; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | #Set this in lieu of using Time::HiRes or built-in time(). | 
| 4 |  |  |  |  |  |  | our $TIME_CR; | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | my ($start, $last_loop_time, $os_error, $nfound, $timeleft, $timer_cr); | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | #pre-5.16 didn’t have \&CORE::time. | 
| 9 | 26 |  |  | 26 |  | 73 | sub _time { time } | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | sub select { | 
| 12 | 6 | 50 |  | 6 | 1 | 14030 | die( (caller 0)[3] . ' must have 4 arguments!' ) if @_ != 4; | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 6 |  |  |  |  | 63 | $os_error = $!; | 
| 15 |  |  |  |  |  |  |  | 
| 16 | 6 |  | 50 |  |  | 96 | $timer_cr = $TIME_CR || Time::HiRes->can('time') || \&_time; | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 6 |  |  |  |  | 14 | $start = $timer_cr->(); | 
| 19 | 6 |  |  |  |  | 15 | $last_loop_time = $start; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | SELECT: { | 
| 22 | 6 |  |  |  |  | 9 | ($nfound, $timeleft) = CORE::select( $_[0], $_[1], $_[2], $_[3] - $last_loop_time + $start ); | 
|  | 26 |  |  |  |  | 9509134 |  | 
| 23 | 26 | 100 |  |  |  | 568 | if ($nfound == -1) { | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | #Use of %! will autoload Errno.pm, | 
| 26 |  |  |  |  |  |  | #which can affect the value of $!. | 
| 27 | 20 |  |  |  |  | 9327 | my $select_error = $!; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 20 | 50 |  |  |  | 109 | if ($! == Errno::EINTR()) { | 
| 30 | 20 |  |  |  |  | 68 | $last_loop_time = $timer_cr->(); | 
| 31 | 20 |  |  |  |  | 71 | redo SELECT; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 0 |  |  |  |  | 0 | $! = $select_error; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  | else { | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | #select() doesn’t set $! on success, so let’s not clobber what | 
| 39 |  |  |  |  |  |  | #value was there before. | 
| 40 | 6 |  |  |  |  | 16 | $! = $os_error; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 6 | 100 |  |  |  | 52 | return wantarray ? ($nfound, $timeleft) : $nfound; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | 1; |