| 1 | package Linux::Event::Fork; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 40 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 40 | our $VERSION = '0.007'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 40 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 40 | ▶ | use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 40 | ▶ | use Linux::Event::Fork::Child (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 40 | ▶ | use Linux::Event::Fork::Request (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | ▶ | sub new ($class, $loop, %args) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=19.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 44 | ▶ | croak "loop is required" if !$loop || !ref($loop); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$loop and ref $loop
MC/DC0%0/2
$loop and ref $loop
$loop
ref $loop
Truth table33%1/3
A and B
A= $loopB= ref $loop
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 44 | my $max_children = delete $args{max_children}; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 44 | ▶ | $max_children = 0 if !defined $max_children; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 44 | ▶ | croak "max_children must be a non-negative integer" if $max_children !~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 44 | ▶ | croak "unknown args: " . join(", ", sort keys %args) if %args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 44 | return bless { | |||||||||||||||||||||||||||||||||||||||||
| 26 | loop => $loop, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | max_children => 0 + $max_children, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | running => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | queue => [], | ||||||||||||||||||||||||||||||||||||||||||
| 30 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub loop ($self) {return $self->{loop} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 5 | ▶ | sub running ($self) {return $self->{running} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
running: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | ▶ | sub queued ($self) {return scalar @{ $self->{queue} } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
queued: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | ▶ | sub max_children ($self, $new = undef) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_children: called CC=8 SCAR=22.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | if (defined $new) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | ▶ | croak "max_children must be a non-negative integer" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | if $new !~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | $self->{max_children} = 0 + $new; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # If we increased the limit, try to start queued work. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | while ($self->{max_children} && $self->{running} < $self->{max_children}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"max_children"} and $self->{"running"} < $self->{"max_children"}
MC/DC0%0/2
$self->{"max_children"} and $self->{"running"} < $self->{"max_children"}
$self->{"max_children"}
$self->{"running"} < $self->{"max_children"}
Truth table33%1/3
A and B
A= $self->{"max_children"}B= $self->{"running"} < $self->{"max_children"}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | my $req = shift @{ $self->{queue} } or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | next if $req->_canceled; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | $req->_start; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $self->_maybe_fire_drain; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | return $self->{max_children}; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | ▶ | sub spawn ($self, %spec) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spawn: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | # Controlled parallelism: if max_children is set and we are at capacity, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # enqueue the request and return a Request handle. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 139 | ▶ | if ($self->{max_children} && $self->{running} >= $self->{max_children}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"max_children"} and $self->{"running"} >= $self->{"max_children"}
MC/DC100%2/2
$self->{"max_children"} and $self->{"running"} >= $self->{"max_children"}
$self->{"max_children"}
$self->{"running"} >= $self->{"max_children"}
Truth table100%3/3
A and B
A= $self->{"max_children"}B= $self->{"running"} >= $self->{"max_children"}
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 86 | my $req = Linux::Event::Fork::Request->_new(fork => $self, spec => \%spec); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 86 | push @{ $self->{queue} }, $req; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 86 | return $req; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 53 | return $self->_spawn_now(\%spec); | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | ▶ | sub _spawn_now ($self, $spec) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_spawn_now: called CC=80 SCAR=52.8
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 85 | my %spec = %$spec; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 85 | my $cmd = delete $spec{cmd}; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 85 | my $child = delete $spec{child}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 85 | ▶ | if (defined $cmd && defined $child) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $cmd and defined $child
MC/DC0%0/2
defined $cmd and defined $child
defined $cmd
defined $child
Truth table66%2/3
A and B
A= defined $cmdB= defined $child
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | croak "provide exactly one of cmd or child"; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 85 | ▶ | if (!defined $cmd && !defined $child) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $cmd or defined $child
MC/DC0%0/2
defined $cmd or defined $child
defined $cmd
defined $child
Truth table66%2/3
A or B
A= defined $cmdB= defined $child
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | croak "cmd or child is required"; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 85 | ▶ | if (defined $cmd) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 76 | ▶ | croak "cmd must be an arrayref" if ref($cmd) ne 'ARRAY' || !@$cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $cmd ne "ARRAY" or not @$cmd
MC/DC0%0/2
ref $cmd ne "ARRAY" or not @$cmd
ref $cmd ne "ARRAY"
not @$cmd
Truth table33%1/3
A or not(B)
A= ref $cmd ne "ARRAY"B= not @$cmd
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 9 | ▶ | croak "child must be a coderef" if ref($child) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 85 | my $on_stdout = delete $spec{on_stdout}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 85 | my $on_stderr = delete $spec{on_stderr}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 85 | my $on_exit = delete $spec{on_exit}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 85 | my $on_timeout = delete $spec{on_timeout}; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 85 | my $timeout = delete $spec{timeout}; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 85 | my $timeout_kill = delete $spec{timeout_kill}; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 85 | my $on_start = delete $spec{on_start}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 85 | my $tag = delete $spec{tag}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 85 | my $data = delete $spec{data}; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 85 | ▶ | croak "on_stdout must be a coderef" if defined($on_stdout) && ref($on_stdout) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $on_stdout and ref $on_stdout ne "CODE"
MC/DC0%0/2
defined $on_stdout and ref $on_stdout ne "CODE"
defined $on_stdout
ref $on_stdout ne "CODE"
Truth table66%2/3
A and B
A= defined $on_stdoutB= ref $on_stdout ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 85 | ▶ | croak "on_stderr must be a coderef" if defined($on_stderr) && ref($on_stderr) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $on_stderr and ref $on_stderr ne "CODE"
MC/DC0%0/2
defined $on_stderr and ref $on_stderr ne "CODE"
defined $on_stderr
ref $on_stderr ne "CODE"
Truth table66%2/3
A and B
A= defined $on_stderrB= ref $on_stderr ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 85 | ▶ | croak "on_exit must be a coderef" if defined($on_exit) && ref($on_exit) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $on_exit and ref $on_exit ne "CODE"
MC/DC0%0/2
defined $on_exit and ref $on_exit ne "CODE"
defined $on_exit
ref $on_exit ne "CODE"
Truth table66%2/3
A and B
A= defined $on_exitB= ref $on_exit ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 85 | ▶ | croak "on_timeout must be a coderef" if defined($on_timeout) && ref($on_timeout) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $on_timeout and ref $on_timeout ne "CODE"
MC/DC0%0/2
defined $on_timeout and ref $on_timeout ne "CODE"
defined $on_timeout
ref $on_timeout ne "CODE"
Truth table66%2/3
A and B
A= defined $on_timeoutB= ref $on_timeout ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 85 | ▶ | croak "on_start must be a coderef" if defined($on_start) && ref($on_start) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $on_start and ref $on_start ne "CODE"
MC/DC0%0/2
defined $on_start and ref $on_start ne "CODE"
defined $on_start
ref $on_start ne "CODE"
Truth table66%2/3
A and B
A= defined $on_startB= ref $on_start ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 85 | ▶ | croak "timeout must be numeric seconds" if defined($timeout) && ref($timeout); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $timeout and ref $timeout
MC/DC0%0/2
defined $timeout and ref $timeout
defined $timeout
ref $timeout
Truth table66%2/3
A and B
A= defined $timeoutB= ref $timeout
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 85 | ▶ | croak "timeout_kill must be numeric seconds" if defined($timeout_kill) && ref($timeout_kill); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $timeout_kill and ref $timeout_kill
MC/DC0%0/2
defined $timeout_kill and ref $timeout_kill
defined $timeout_kill
ref $timeout_kill
Truth table33%1/3
A and B
A= defined $timeout_killB= ref $timeout_kill
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 85 | my $capture_stdout = delete $spec{capture_stdout}; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 85 | my $capture_stderr = delete $spec{capture_stderr}; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 85 | my $stdin = delete $spec{stdin}; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 85 | my $stdin_pipe = delete $spec{stdin_pipe}; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 85 | ▶ | $stdin_pipe = $stdin_pipe ? 1 : 0 if defined $stdin_pipe; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 85 | my $cwd = delete $spec{cwd}; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 85 | my $umask = delete $spec{umask}; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 85 | my $env = delete $spec{env}; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 85 | my $clear_env = delete $spec{clear_env}; | |||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 85 | ▶ | croak "cwd must be a string" if defined($cwd) && ref($cwd); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $cwd and ref $cwd
MC/DC0%0/2
defined $cwd and ref $cwd
defined $cwd
ref $cwd
Truth table33%1/3
A and B
A= defined $cwdB= ref $cwd
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 85 | ▶ | croak "umask must be an integer" if defined($umask) && ref($umask); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $umask and ref $umask
MC/DC0%0/2
defined $umask and ref $umask
defined $umask
ref $umask
Truth table33%1/3
A and B
A= defined $umaskB= ref $umask
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 85 | ▶ | croak "env must be a hashref" if defined($env) && ref($env) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $env and ref $env ne "HASH"
MC/DC0%0/2
defined $env and ref $env ne "HASH"
defined $env
ref $env ne "HASH"
Truth table66%2/3
A and B
A= defined $envB= ref $env ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 85 | ▶ | $clear_env = $clear_env ? 1 : 0 if defined $clear_env; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 85 | ▶ | croak "unknown args: " . join(", ", sort keys %spec) if %spec; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 85 | ▶ | $capture_stdout = defined($capture_stdout) ? ($capture_stdout ? 1 : 0) : (defined($on_stdout) ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 85 | ▶ | $capture_stderr = defined($capture_stderr) ? ($capture_stderr ? 1 : 0) : (defined($on_stderr) ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 85 | my ($out_r, $out_w); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 85 | my ($err_r, $err_w); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 85 | my ($in_r, $in_w); | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 85 | ▶ | if ($capture_stdout) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 13 | ▶ | pipe($out_r, $out_w) or croak "pipe(stdout): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 13 | _set_nonblock($out_r); | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 85 | ▶ | if ($capture_stderr) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 6 | ▶ | pipe($err_r, $err_w) or croak "pipe(stderr): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | _set_nonblock($err_r); | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 85 | ▶ | my $want_stdin = (defined($stdin) || $stdin_pipe) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $stdin or $stdin_pipe
MC/DC50%1/2
defined $stdin or $stdin_pipe
defined $stdin
$stdin_pipe
Truth table66%2/3
A or B
A= defined $stdinB= $stdin_pipe
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 85 | ▶ | if ($want_stdin) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 4 | ▶ | pipe($in_r, $in_w) or croak "pipe(stdin): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 4 | _set_nonblock($in_w); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 85 | my $pid = fork(); | |||||||||||||||||||||||||||||||||||||||||
| 149 | 85 | ▶ | croak "fork: $!" if !defined $pid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 85 | ▶ | if ($pid == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 29 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 153 | 29 | ▶ | if ($want_stdin) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | close($in_w); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | ▶ | POSIX::dup2(fileno($in_r), fileno(*STDIN)) or die "dup2(stdin): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 29 | ▶ | if ($capture_stdout) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 6 | close($out_r); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 6 | ▶ | POSIX::dup2(fileno($out_w), fileno(*STDOUT)) or die "dup2(stdout): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 29 | ▶ | if ($capture_stderr) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 2 | close($err_r); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | ▶ | POSIX::dup2(fileno($err_w), fileno(*STDERR)) or die "dup2(stderr): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 29 | ▶ | close($in_r) if $want_stdin; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 29 | ▶ | close($out_w) if $capture_stdout; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 29 | ▶ | close($err_w) if $capture_stderr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 29 | ▶ | if (defined $umask) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | umask($umask) or die "umask($umask): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 29 | ▶ | if (defined $cwd) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | chdir($cwd) or die "chdir($cwd): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 29 | ▶ | if ($clear_env) { %ENV = () } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 29 | ▶ | if (defined $env) { %ENV = (%ENV, %$env) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 29 | ▶ | if (defined $cmd) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 26 | exec { $cmd->[0] } @$cmd; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | die "exec($cmd->[0]): $!"; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | $child->(); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | die "child callback returned"; | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | if (defined $err && $err ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $err and $err ne ""
MC/DC0%0/2
defined $err and $err ne ""
defined $err
$err ne ""
Truth table0%0/3
A and B
A= defined $errB= $err ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $err =~ s/\s+\z/\n/; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | syswrite(*STDERR, "Linux::Event::Fork child error: $err"); | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | POSIX::_exit(127); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 56 | ▶ | close($out_w) if $capture_stdout; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 56 | ▶ | close($err_w) if $capture_stderr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 56 | ▶ | close($in_r) if $want_stdin; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | # Wrap on_exit so we always release capacity and start the next queued job, | ||||||||||||||||||||||||||||||||||||||||||
| 205 | # even if user code throws. | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 56 | my $user_on_exit = $on_exit; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 56 | ▶ | my $managed = $self->{max_children} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | ▶ | $on_exit = sub ($child_obj, $exit_obj) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 43 | ▶ | if ($user_on_exit) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 42 | eval { $user_on_exit->($child_obj, $exit_obj); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 43 | ▶ | $self->_on_child_finished($child_obj) if $managed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 56 | }; | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | my $handle = Linux::Event::Fork::Child->_new( | ||||||||||||||||||||||||||||||||||||||||||
| 217 | loop => $self->{loop}, | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 56 | ▶ | pid => $pid, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | tag => $tag, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | data => $data, | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | out_r => $out_r, | ||||||||||||||||||||||||||||||||||||||||||
| 224 | err_r => $err_r, | ||||||||||||||||||||||||||||||||||||||||||
| 225 | in_w => $in_w, | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | on_stdout => $on_stdout, | ||||||||||||||||||||||||||||||||||||||||||
| 228 | on_stderr => $on_stderr, | ||||||||||||||||||||||||||||||||||||||||||
| 229 | on_exit => $on_exit, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | timeout => $timeout, | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | timeout_kill => $timeout_kill, | ||||||||||||||||||||||||||||||||||||||||||
| 234 | on_timeout => $on_timeout, | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | capture_stdout => $capture_stdout, | ||||||||||||||||||||||||||||||||||||||||||
| 237 | capture_stderr => $capture_stderr, | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | managed_by_fork => ($managed ? $self : undef), | ||||||||||||||||||||||||||||||||||||||||||
| 240 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 56 | ▶ | $self->{running}++ if $managed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 56 | ▶ | if ($on_start) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 39 | eval { $on_start->($handle); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 56 | ▶ | if (defined $stdin && $stdin ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $stdin and $stdin ne ""
MC/DC0%0/2
defined $stdin and $stdin ne ""
defined $stdin
$stdin ne ""
Truth table33%1/3
A and B
A= defined $stdinB= $stdin ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $handle->stdin_write($stdin); | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 56 | ▶ | if (defined $stdin && !$stdin_pipe) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $stdin and not $stdin_pipe
MC/DC0%0/2
defined $stdin and not $stdin_pipe
defined $stdin
not $stdin_pipe
Truth table33%1/3
A and not(B)
A= defined $stdinB= not $stdin_pipe
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $handle->close_stdin; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 56 | $handle->_arm; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 56 | return $handle; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | ▶ | sub _on_child_finished ($self, $child) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_on_child_finished: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | # Idempotent: a child should only finish once, but guard anyway. | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 30 | ▶ | return if !$self->{running}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 30 | $self->{running}--; | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | # Start queued work, if any. | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 30 | ▶ | while ($self->{max_children} && $self->{running} < $self->{max_children}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"max_children"} and $self->{"running"} < $self->{"max_children"}
MC/DC50%1/2
$self->{"max_children"} and $self->{"running"} < $self->{"max_children"}
$self->{"max_children"}
$self->{"running"} < $self->{"max_children"}
Truth table66%2/3
A and B
A= $self->{"max_children"}B= $self->{"running"} < $self->{"max_children"}
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 30 | ▶ | my $req = shift @{ $self->{queue} } or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 29 | ▶ | next if $req->_canceled; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 29 | $req->_start; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 20 | $self->_maybe_fire_drain; | |||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 20 | return; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | ▶ | sub drain ($self, %args) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drain: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 7 | my $on_done = delete $args{on_done}; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 7 | ▶ | croak "on_done is required" if !defined $on_done; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 7 | ▶ | croak "on_done must be a coderef" if ref($on_done) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 7 | ▶ | croak "unknown args: " . join(", ", sort keys %args) if %args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 7 | $self->{_drain_on_done} = $on_done; | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 6 | $self->_maybe_fire_drain; | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 7 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | ▶ | sub _maybe_fire_drain ($self) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_maybe_fire_drain: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 29 | ▶ | my $cb = $self->{_drain_on_done} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 18 | ▶ | return if $self->{running}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | ▶ | return if @{ $self->{queue} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | delete $self->{_drain_on_done}; | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | eval { $cb->($self); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | ▶ | sub cancel_queued ($self, $pred = undef) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cancel_queued: called CC=9 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | ▶ | croak "cancel_queued predicate must be a coderef" if defined($pred) && ref($pred) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $pred and ref $pred ne "CODE"
MC/DC0%0/2
defined $pred and ref $pred ne "CODE"
defined $pred
ref $pred ne "CODE"
Truth table33%1/3
A and B
A= defined $predB= ref $pred ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 2 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 2 | my @keep; | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 2 | for my $req (@{ $self->{queue} }) { | |||||||||||||||||||||||||||||||||||||||||
| 308 | 8 | ▶ | next if !defined $req; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 8 | ▶ | if (!$req->_canceled && (!defined($pred) || $pred->($req))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $req->_canceled and !defined($pred) || &$pred($req)
not defined $pred or &$pred($req)
MC/DC33%1/3
not $req->_canceled and !defined($pred) || &$pred($req)
not $req->_canceled
not defined $pred
&$pred($req)
Truth table50%2/4
not(A) and not(B) or C
A= not $req->_canceledB= not defined $predC= &$pred($req)
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 6 | $req->cancel; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 6 | $n++; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | push @keep, $req; | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 2 | $self->{queue} = \@keep; | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | $self->_maybe_fire_drain; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | return $n; | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | ▶ | sub _set_nonblock ($fh) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_nonblock: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 23 | my $flags = fcntl($fh, F_GETFL, 0); | |||||||||||||||||||||||||||||||||||||||||
| 328 | 23 | ▶ | croak "fcntl(F_GETFL): $!" if !defined $flags; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 23 | my $ok = fcntl($fh, F_SETFL, $flags | O_NONBLOCK); | |||||||||||||||||||||||||||||||||||||||||
| 330 | 23 | ▶ | croak "fcntl(F_SETFL,O_NONBLOCK): $!" if !$ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 23 | return; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | __END__ | ||||||||||||||||||||||||||||||||||||||||||