line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2011-2015 by [Mark Overmeer]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
5
|
5
|
|
|
5
|
|
4004377
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
196
|
|
6
|
5
|
|
|
5
|
|
26
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
178
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package IOMux::Pipe::Read; |
9
|
5
|
|
|
5
|
|
27
|
use vars '$VERSION'; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
277
|
|
10
|
|
|
|
|
|
|
$VERSION = '1.00'; |
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
23
|
use base 'IOMux::Handler::Read'; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
1125
|
|
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
26
|
use Log::Report 'iomux'; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
32
|
|
15
|
5
|
|
|
5
|
|
1246
|
use Fcntl; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
1654
|
|
16
|
5
|
|
|
5
|
|
68
|
use POSIX qw/:errno_h :sys_wait_h/; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
26
|
|
17
|
5
|
|
|
5
|
|
2531
|
use File::Basename 'basename'; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
3358
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init($) |
21
|
2
|
|
|
2
|
0
|
6
|
{ my ($self, $args) = @_; |
22
|
|
|
|
|
|
|
my $command = $args->{command} |
23
|
2
|
50
|
|
|
|
10
|
or error __x"no command to run specified in {pkg}", pkg => __PACKAGE__; |
24
|
|
|
|
|
|
|
|
25
|
2
|
50
|
|
|
|
20
|
my ($cmd, @cmdopts) = ref $command eq 'ARRAY' ? @$command : $command; |
26
|
2
|
|
|
|
|
118
|
my $name = $args->{name} = (basename $cmd)."|"; |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
4
|
my ($rh, $wh); |
29
|
2
|
50
|
|
|
|
52
|
pipe $rh, $wh |
30
|
|
|
|
|
|
|
or fault __x"cannot create pipe for {cmd}", cmd => $name; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
2573
|
my $pid = fork; |
33
|
2
|
50
|
|
|
|
150
|
defined $pid |
34
|
|
|
|
|
|
|
or fault __x"failed to fork for pipe {cmd}", cmd => $name; |
35
|
|
|
|
|
|
|
|
36
|
2
|
100
|
|
|
|
120
|
if($pid==0) |
37
|
|
|
|
|
|
|
{ # client |
38
|
1
|
|
|
|
|
76
|
close $rh; |
39
|
1
|
|
|
|
|
525
|
open STDIN, '<', File::Spec->devnull; |
40
|
1
|
50
|
|
|
|
67
|
open STDOUT, '>&', $wh |
41
|
|
|
|
|
|
|
or fault __x"failed to redirect STDOUT for pipe {cmd}", cmd=>$name; |
42
|
1
|
|
|
|
|
65
|
open STDERR, '>', File::Spec->devnull; |
43
|
|
|
|
|
|
|
|
44
|
1
|
0
|
|
|
|
0
|
exec $cmd, @cmdopts |
45
|
|
|
|
|
|
|
or fault __x"failed to exec for pipe {cmd}", cmd => $name; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# parent |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
86
|
$self->{IMPR_pid} = $pid; |
51
|
1
|
|
50
|
|
|
68
|
$args->{read_size} ||= 4096; # Unix typical BUFSIZ |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
14
|
close $wh; |
54
|
1
|
|
|
|
|
16
|
fcntl $rh, F_SETFL, O_NONBLOCK; |
55
|
1
|
|
|
|
|
13
|
$args->{fh} = $rh; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
89
|
$self->SUPER::init($args); |
58
|
1
|
|
|
|
|
39
|
$self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub bare($%) |
63
|
2
|
|
|
2
|
1
|
6
|
{ my ($class, %args) = @_; |
64
|
2
|
|
|
|
|
6
|
my $self = bless {}, $class; |
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
4
|
my ($rh, $wh); |
67
|
2
|
50
|
|
|
|
32
|
pipe $rh, $wh |
68
|
|
|
|
|
|
|
or fault __x"cannot create bare pipe reader"; |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
50
|
|
|
10
|
$args{read_size} ||= 4096; # Unix typical BUFSIZ |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
6
|
fcntl $rh, F_SETFL, O_NONBLOCK; |
73
|
2
|
|
|
|
|
4
|
$args{fh} = $rh; |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
14
|
$self->SUPER::init(\%args); |
76
|
2
|
|
|
|
|
8
|
($self, $wh); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub open($$@) |
81
|
0
|
|
|
0
|
1
|
0
|
{ my ($class, $mode, $cmd) = (shift, shift, shift); |
82
|
0
|
0
|
|
|
|
0
|
ref $cmd eq 'ARRAY' |
83
|
|
|
|
|
|
|
? $class->new(command => $cmd, mode => $mode, @_) |
84
|
|
|
|
|
|
|
: $class->new(command => [$cmd, @_] , mode => $mode); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#------------------- |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
1
|
0
|
sub mode() {shift->{IMPR_mode}} |
90
|
0
|
|
|
0
|
1
|
0
|
sub childPid() {shift->{IMPR_pid}} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#------------------- |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub close($) |
95
|
2
|
|
|
2
|
1
|
1401
|
{ my ($self, $cb) = @_; |
96
|
|
|
|
|
|
|
my $pid = $self->{IMPR_pid} |
97
|
2
|
100
|
|
|
|
23
|
or return $self->SUPER::close($cb); |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
19
|
waitpid $pid, WNOHANG; |
100
|
1
|
|
|
|
|
7
|
local $?; |
101
|
1
|
|
|
|
|
13
|
$self->SUPER::close($cb); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |