| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyrights 2011-2020 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
|
|
|
|
|
|
|
# This code is part of distribution IOMux. Meta-POD processed with OODoc |
|
6
|
|
|
|
|
|
|
# into POD and HTML manual-pages. See README.md |
|
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package IOMux::Bundle; |
|
10
|
3
|
|
|
3
|
|
722
|
use vars '$VERSION'; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
123
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.01'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
13
|
use base 'IOMux::Handler::Read', 'IOMux::Handler::Write'; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
706
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
83
|
|
|
16
|
3
|
|
|
3
|
|
12
|
use strict; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
52
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
3
|
|
|
3
|
|
11
|
use Log::Report 'iomux'; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
11
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
3
|
|
|
3
|
|
581
|
use Scalar::Util qw(blessed); |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
2743
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
##### WORK IN PROGRESS! |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub init($) |
|
26
|
1
|
|
|
1
|
0
|
12
|
{ my ($self, $args) = @_; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# stdin to be a writer is a bit counter-intuitive, therefore some |
|
29
|
|
|
|
|
|
|
# extra tests. |
|
30
|
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
6
|
my @filenos; |
|
32
|
1
|
|
|
|
|
17
|
my $name = $args->{name}; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $in = $self->{IMB_stdin} = $args->{stdin} |
|
35
|
1
|
50
|
|
|
|
30
|
or error __x"no stdin handler for {name}", name => $name; |
|
36
|
1
|
50
|
33
|
|
|
58
|
blessed $in && $in->isa('IOMux::Handler::Write') |
|
37
|
|
|
|
|
|
|
or error __x"stdin {name} is not at writer", name => $name; |
|
38
|
1
|
|
|
|
|
47
|
push @filenos, $in->fileno; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $out = $self->{IMB_stdout} = $args->{stdout} |
|
41
|
1
|
50
|
|
|
|
14
|
or error __x"no stdout handler for {name}", name => $name; |
|
42
|
1
|
50
|
33
|
|
|
53
|
blessed $out && $out->isa('IOMux::Handler::Read') |
|
43
|
|
|
|
|
|
|
or error __x"stdout {name} is not at reader", name => $name; |
|
44
|
1
|
|
|
|
|
20
|
push @filenos, $out->fileno; |
|
45
|
|
|
|
|
|
|
|
|
46
|
1
|
50
|
|
|
|
15
|
if(my $err = $self->{IMB_stderr} = $args->{stderr}) |
|
47
|
0
|
0
|
0
|
|
|
0
|
{ blessed $err && $err->isa('IOMux::Handler::Read') |
|
48
|
|
|
|
|
|
|
or error __x"stderr {name} is not at reader", name => $name; |
|
49
|
0
|
|
|
|
|
0
|
push @filenos, $err->fileno; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
14
|
$args->{name} .= ', ('.join(',',@filenos).')'; |
|
53
|
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
38
|
$self->SUPER::init($args); |
|
55
|
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
6
|
$self->{IMB_filenos} = \@filenos; |
|
57
|
1
|
|
|
|
|
9
|
$self; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#--------------- |
|
61
|
|
|
|
|
|
|
|
|
62
|
2
|
|
|
2
|
1
|
1001586
|
sub stdin() {shift->{IMB_stdin}} |
|
63
|
0
|
|
|
0
|
1
|
0
|
sub stdout() {shift->{IMB_stdout}} |
|
64
|
0
|
|
|
0
|
1
|
0
|
sub stderr() {shift->{IMB_stderr}} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub connections() |
|
68
|
1
|
|
|
1
|
1
|
2
|
{ my $s = shift; |
|
69
|
1
|
|
|
|
|
21
|
grep defined, $s->{IMB_stdin}, $s->{IMB_stdout}, $s->{IMB_stderr}; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#--------------- |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# say, print and printf use write() |
|
75
|
2
|
|
|
2
|
1
|
23
|
sub write(@) { shift->{IMB_stdin}->write(@_) } |
|
76
|
0
|
|
|
0
|
1
|
0
|
sub muxOutbufferEmpty() { shift->{IMB_stdin}->muxOutbufferEmpty(@_) } |
|
77
|
0
|
|
|
0
|
1
|
0
|
sub muxOutputWaiting() { shift->{IMB_stdin}->muxOutputWaiting(@_) } |
|
78
|
0
|
|
|
0
|
1
|
0
|
sub muxWriteFlagged() { shift->{IMB_stdin}->muxWriteFlagged(@_) } |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
0
|
1
|
0
|
sub readline(@) { shift->{IMB_stdout}->readline(@_) } |
|
81
|
1
|
|
|
1
|
1
|
17
|
sub slurp(@) { shift->{IMB_stdout}->slurp(@_) } |
|
82
|
0
|
|
|
0
|
1
|
0
|
sub muxInput($) { shift->{IMB_stdout}->muxInput(@_) } |
|
83
|
0
|
|
|
0
|
1
|
0
|
sub muxEOF($) { shift->{IMB_stdout}->muxEOF(@_) } |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub muxReadFlagged($) |
|
86
|
0
|
|
|
0
|
1
|
0
|
{ my ($self, $fileno) = @_; |
|
87
|
0
|
0
|
|
|
|
0
|
if(my $e = $self->{IMB_stderr}) |
|
88
|
0
|
0
|
|
|
|
0
|
{ return $e->muxReadFlagged(@_) |
|
89
|
|
|
|
|
|
|
if $fileno==$e->fileno; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
0
|
|
|
|
|
0
|
$self->{IMB_stdin}->muxReadFlagged(@_); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
0
|
1
|
0
|
sub timeout() { shift->{IMB_stdin}->timeout(@_) } |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub close(;$) |
|
97
|
1
|
|
|
1
|
1
|
3
|
{ my ($self, $cb) = @_; |
|
98
|
|
|
|
|
|
|
my $close_error = sub |
|
99
|
1
|
50
|
|
1
|
|
16
|
{ if(my $err = $self->{IMB_stderr}) { $err->close($cb) } |
|
|
0
|
50
|
|
|
|
0
|
|
|
100
|
0
|
|
|
|
|
0
|
elsif($cb) { $cb->($self) } |
|
101
|
1
|
|
|
|
|
14
|
}; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $close_out = sub |
|
104
|
1
|
50
|
|
1
|
|
3
|
{ if(my $out = $self->{IMB_stdout}) { $out->close($close_error) } |
|
|
1
|
|
|
|
|
9
|
|
|
105
|
0
|
|
|
|
|
0
|
else { $close_error->() } |
|
106
|
1
|
|
|
|
|
9
|
}; |
|
107
|
|
|
|
|
|
|
|
|
108
|
1
|
50
|
|
|
|
4
|
if(my $in = $self->{IMB_stdin}) { $in->close($close_out) } |
|
|
1
|
|
|
|
|
5
|
|
|
109
|
0
|
|
|
|
|
0
|
else { $close_out->() } |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub muxRemove() |
|
113
|
0
|
|
|
0
|
1
|
0
|
{ my $self = shift; |
|
114
|
0
|
|
|
|
|
0
|
$_->muxRemove for $self->connections; |
|
115
|
0
|
|
|
|
|
0
|
trace "mux remove bundle ".$self->name; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub muxInit($) |
|
119
|
1
|
|
|
1
|
1
|
2
|
{ my ($self, $mux) = @_; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
$_->muxInit($mux, $self) # I want control |
|
122
|
1
|
|
|
|
|
14
|
for $self->connections; |
|
123
|
|
|
|
|
|
|
|
|
124
|
1
|
|
|
|
|
32
|
trace "mux add bundle ".$self->name; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#--------------- |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub muxError($) |
|
130
|
0
|
|
|
0
|
1
|
|
{ my ($self, $errbuf) = @_; |
|
131
|
0
|
|
|
|
|
|
print STDERR $$errbuf; |
|
132
|
0
|
|
|
|
|
|
$$errbuf = ''; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#--------------- |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub show() |
|
138
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
|
139
|
0
|
|
|
|
|
|
join "\n", (map $_->show, $self->connections), ''; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
0
|
1
|
|
sub fdset() {panic} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |