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
|
|
79
|
sub _time { time } |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub select { |
12
|
6
|
50
|
|
6
|
1
|
16493
|
die( (caller 0)[3] . ' must have 4 arguments!' ) if @_ != 4; |
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
|
|
58
|
$os_error = $!; |
15
|
|
|
|
|
|
|
|
16
|
6
|
|
50
|
|
|
134
|
$timer_cr = $TIME_CR || Time::HiRes->can('time') || \&_time; |
17
|
|
|
|
|
|
|
|
18
|
6
|
|
|
|
|
17
|
$start = $timer_cr->(); |
19
|
6
|
|
|
|
|
24
|
$last_loop_time = $start; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
SELECT: { |
22
|
6
|
|
|
|
|
8
|
($nfound, $timeleft) = CORE::select( $_[0], $_[1], $_[2], $_[3] - $last_loop_time + $start ); |
|
26
|
|
|
|
|
9520331
|
|
23
|
26
|
100
|
|
|
|
641
|
if ($nfound == -1) { |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#Use of %! will autoload Errno.pm, |
26
|
|
|
|
|
|
|
#which can affect the value of $!. |
27
|
20
|
|
|
|
|
10190
|
my $select_error = $!; |
28
|
|
|
|
|
|
|
|
29
|
20
|
50
|
|
|
|
140
|
if ($! == Errno::EINTR()) { |
30
|
20
|
|
|
|
|
74
|
$last_loop_time = $timer_cr->(); |
31
|
20
|
|
|
|
|
108
|
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
|
|
|
|
|
19
|
$! = $os_error; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
6
|
100
|
|
|
|
58
|
return wantarray ? ($nfound, $timeleft) : $nfound; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |