line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
our $debug = 0; |
3
|
|
|
|
|
|
|
our $edebug = 0; |
4
|
|
|
|
|
|
|
our $sdebug = 0; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
{ |
7
|
|
|
|
|
|
|
package IO::Event; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 0.813; |
10
|
|
|
|
|
|
|
|
11
|
58
|
|
|
58
|
|
435129
|
use strict; |
|
58
|
|
|
|
|
137
|
|
|
58
|
|
|
|
|
2373
|
|
12
|
58
|
|
|
58
|
|
311
|
no strict 'refs'; |
|
58
|
|
|
|
|
118
|
|
|
58
|
|
|
|
|
1649
|
|
13
|
58
|
|
|
58
|
|
324
|
use warnings; |
|
58
|
|
|
|
|
126
|
|
|
58
|
|
|
|
|
1984
|
|
14
|
58
|
|
|
58
|
|
321
|
use Carp qw(confess); |
|
58
|
|
|
|
|
113
|
|
|
58
|
|
|
|
|
88415
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $base; |
17
|
|
|
|
|
|
|
our @ISA; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub idle |
20
|
|
|
|
|
|
|
{ |
21
|
3
|
50
|
|
3
|
0
|
59
|
IO::Event->import('no_emulate_Event') unless $base; |
22
|
3
|
|
|
|
|
6
|
&{$base . "::idle"}(@_); |
|
3
|
|
|
|
|
33
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub loop |
26
|
|
|
|
|
|
|
{ |
27
|
12
|
50
|
|
12
|
0
|
8832
|
IO::Event->import('no_emulate_Event') unless $base; |
28
|
12
|
|
|
|
|
43
|
&{$base . "::loop"}(@_); |
|
12
|
|
|
|
|
184
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub unloop |
32
|
|
|
|
|
|
|
{ |
33
|
0
|
|
|
0
|
0
|
0
|
&{$base . "::unloop"}(@_); |
|
0
|
|
|
|
|
0
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub unloop_all |
37
|
|
|
|
|
|
|
{ |
38
|
8
|
|
|
8
|
0
|
45825
|
&{$base . "::unloop_all"}(@_); |
|
8
|
|
|
|
|
508
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub timer |
42
|
|
|
|
|
|
|
{ |
43
|
9
|
|
|
9
|
0
|
648
|
shift; |
44
|
9
|
50
|
|
|
|
37
|
IO::Event->import('no_emulate_Event') unless $base; |
45
|
9
|
|
|
|
|
75
|
$base->timer(@_); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new |
49
|
|
|
|
|
|
|
{ |
50
|
543
|
100
|
|
543
|
1
|
391742714
|
IO::Event->import('no_emulate_Event') unless $base; |
51
|
543
|
|
|
|
|
3683
|
&{$base . "::new"}(@_); |
|
543
|
|
|
|
|
2670014
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub import |
55
|
|
|
|
|
|
|
{ |
56
|
135
|
|
|
135
|
|
3868890
|
my ($pkg, @stuff) = @_; |
57
|
135
|
|
|
|
|
713
|
for my $s (@stuff) { |
58
|
57
|
100
|
|
|
|
1410
|
if ($s eq 'emulate_Event') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
59
|
19
|
|
|
|
|
38
|
$base = 'IO::Event::Emulate'; |
60
|
19
|
|
|
|
|
11271
|
require IO::Event::Emulate; |
61
|
|
|
|
|
|
|
} elsif ($s eq 'no_emulate_Event') { |
62
|
18
|
|
|
|
|
1928
|
require Event; |
63
|
18
|
|
|
|
|
37696
|
require IO::Event::Event; |
64
|
18
|
|
|
|
|
290
|
$base = 'IO::Event::Event'; |
65
|
|
|
|
|
|
|
} elsif ($s eq 'AnyEvent') { |
66
|
20
|
|
|
|
|
211
|
require AnyEvent; |
67
|
20
|
|
|
|
|
15958
|
require IO::Event::AnyEvent; |
68
|
20
|
|
|
|
|
129
|
$base = 'IO::Event::AnyEvent'; |
69
|
|
|
|
|
|
|
} else { |
70
|
0
|
|
|
|
|
0
|
die "unknown import: $s"; |
71
|
|
|
|
|
|
|
} |
72
|
57
|
|
|
|
|
4896
|
@ISA = $base; |
73
|
|
|
|
|
|
|
} |
74
|
135
|
|
|
|
|
35198
|
return 1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub AUTOLOAD |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
80
|
0
|
|
|
|
|
0
|
our $AUTOLOAD; |
81
|
0
|
|
|
|
|
0
|
my $a = $AUTOLOAD; |
82
|
0
|
|
|
|
|
0
|
$a =~ s/.*:://; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# for whatever reason, UNIVERSAL::can() |
85
|
|
|
|
|
|
|
# doesn't seem to work on some filehandles |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
0
|
my $r; |
88
|
|
|
|
|
|
|
my @r; |
89
|
0
|
|
|
|
|
0
|
my $fh = ${*$self}{ie_fh}; |
|
0
|
|
|
|
|
0
|
|
90
|
0
|
0
|
|
|
|
0
|
if ($fh) { |
91
|
0
|
0
|
|
|
|
0
|
if (wantarray) { |
92
|
0
|
|
|
|
|
0
|
eval { @r = $fh->$a(@_) }; |
|
0
|
|
|
|
|
0
|
|
93
|
|
|
|
|
|
|
} else { |
94
|
0
|
|
|
|
|
0
|
eval { $r = $fh->$a(@_) }; |
|
0
|
|
|
|
|
0
|
|
95
|
|
|
|
|
|
|
} |
96
|
0
|
0
|
0
|
|
|
0
|
if ($@ && $@ =~ /Can't locate object method "(.*?)" via package/) { |
97
|
0
|
|
|
|
|
0
|
my $event = ${*$self}{ie_event}; |
|
0
|
|
|
|
|
0
|
|
98
|
0
|
0
|
0
|
|
|
0
|
if ($1 ne $a) { |
|
|
0
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# nothing to do |
100
|
|
|
|
|
|
|
} elsif ($event && $event->can($a)) { |
101
|
0
|
0
|
|
|
|
0
|
if (wantarray) { |
102
|
0
|
|
|
|
|
0
|
eval { @r = $event->$a(@_) }; |
|
0
|
|
|
|
|
0
|
|
103
|
|
|
|
|
|
|
} else { |
104
|
0
|
|
|
|
|
0
|
eval { $r = $event->$a(@_) }; |
|
0
|
|
|
|
|
0
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} else { |
107
|
0
|
|
0
|
|
|
0
|
confess qq{Can't locate object method "$a" via "@{[ ref($self) ]}", "@{[ ref($fh)||'IO::Handle' ]}", or "@{[ ref($event) ]}"}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} else { |
111
|
0
|
|
|
|
|
0
|
my $event = ${*$self}{ie_event}; |
|
0
|
|
|
|
|
0
|
|
112
|
0
|
0
|
0
|
|
|
0
|
if ($event && $event->can($a)) { |
113
|
0
|
0
|
|
|
|
0
|
if (wantarray) { |
114
|
0
|
|
|
|
|
0
|
eval { @r = $event->$a(@_) }; |
|
0
|
|
|
|
|
0
|
|
115
|
|
|
|
|
|
|
} else { |
116
|
0
|
|
|
|
|
0
|
eval { $r = $event->$a(@_) }; |
|
0
|
|
|
|
|
0
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} else { |
119
|
0
|
|
|
|
|
0
|
confess qq{Can't locate object method "$a" via "@{[ ref($self) ]}" or "@{[ ref($event) ]}"}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
0
|
0
|
|
|
|
0
|
confess $@ if $@; |
123
|
0
|
0
|
|
|
|
0
|
return @r if wantarray; |
124
|
0
|
|
|
|
|
0
|
return $r; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
}{package IO::Event::Common; |
128
|
|
|
|
|
|
|
|
129
|
58
|
|
|
58
|
|
430
|
use strict; |
|
58
|
|
|
|
|
112
|
|
|
58
|
|
|
|
|
2037
|
|
130
|
58
|
|
|
58
|
|
307
|
use warnings; |
|
58
|
|
|
|
|
110
|
|
|
58
|
|
|
|
|
1759
|
|
131
|
58
|
|
|
58
|
|
65449
|
use Symbol; |
|
58
|
|
|
|
|
53097
|
|
|
58
|
|
|
|
|
4069
|
|
132
|
58
|
|
|
58
|
|
317
|
use Carp; |
|
58
|
|
|
|
|
129
|
|
|
58
|
|
|
|
|
4089
|
|
133
|
|
|
|
|
|
|
require IO::Handle; |
134
|
58
|
|
|
58
|
|
57704
|
use POSIX qw(BUFSIZ EAGAIN EBADF EINVAL ETIMEDOUT); |
|
58
|
|
|
|
|
605843
|
|
|
58
|
|
|
|
|
510
|
|
135
|
58
|
|
|
58
|
|
153653
|
use Socket; |
|
58
|
|
|
|
|
327784
|
|
|
58
|
|
|
|
|
42450
|
|
136
|
58
|
|
|
58
|
|
565
|
use Scalar::Util qw(weaken reftype); |
|
58
|
|
|
|
|
94
|
|
|
58
|
|
|
|
|
5294
|
|
137
|
58
|
|
|
58
|
|
131431
|
use Time::HiRes qw(time); |
|
58
|
|
|
|
|
155116
|
|
|
58
|
|
|
|
|
312
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
our $in_callback = 0; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my %fh_table; |
142
|
|
|
|
|
|
|
my %rxcache; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my @pending_callbacks; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub display_bits |
147
|
|
|
|
|
|
|
{ |
148
|
0
|
|
|
0
|
|
0
|
print STDERR unpack("b*", $_[0]); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub count_bits |
152
|
|
|
|
|
|
|
{ |
153
|
0
|
|
|
0
|
|
0
|
scalar(grep { $_ } split(//, unpack("b*", $_[0]))); |
|
0
|
|
|
|
|
0
|
|
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub display_want |
157
|
|
|
|
|
|
|
{ |
158
|
0
|
|
|
0
|
|
0
|
my ($name, $vec, %hash) = @_; |
159
|
0
|
|
|
|
|
0
|
my ($pkg, $file, $line) = caller; |
160
|
0
|
|
|
|
|
0
|
print STDERR "\n\nAT $file: $line\n"; |
161
|
0
|
|
|
|
|
0
|
print STDERR "$name\n"; |
162
|
0
|
|
|
|
|
0
|
for my $ioe (values %hash) { |
163
|
0
|
|
|
|
|
0
|
printf STDERR "%03d-", fileno(${*$ioe}{ie_fh}); |
|
0
|
|
|
|
|
0
|
|
164
|
|
|
|
|
|
|
# display_bits(${*$ioe}{ie_vec}); |
165
|
0
|
|
|
|
|
0
|
print STDERR "\n"; |
166
|
|
|
|
|
|
|
} |
167
|
0
|
|
|
|
|
0
|
print STDERR "----------"; |
168
|
0
|
|
|
|
|
0
|
display_bits($vec); |
169
|
0
|
|
|
|
|
0
|
printf STDERR " - %d\n", count_bits($vec); |
170
|
0
|
|
|
|
|
0
|
print STDERR scalar(keys(%hash)); |
171
|
0
|
|
|
|
|
0
|
print STDERR "\n"; |
172
|
0
|
|
|
|
|
0
|
exit 1; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
my $counter = 1; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub new |
178
|
|
|
|
|
|
|
{ |
179
|
543
|
|
|
543
|
|
5010
|
my ($pkg, $fh, $handler, $options) = @_; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# stolen from IO::Handle |
182
|
543
|
|
|
|
|
10736
|
my $self = bless gensym(), $pkg; |
183
|
|
|
|
|
|
|
|
184
|
543
|
100
|
|
|
|
48201
|
$handler = (caller(2))[0] |
185
|
|
|
|
|
|
|
unless $handler; |
186
|
|
|
|
|
|
|
|
187
|
543
|
50
|
|
|
|
8141
|
confess unless ref $fh; |
188
|
|
|
|
|
|
|
|
189
|
543
|
50
|
|
|
|
4822
|
unless (ref $options) { |
190
|
543
|
|
|
|
|
7241
|
$options = { |
191
|
|
|
|
|
|
|
description => $options, |
192
|
|
|
|
|
|
|
}; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# some bits stolen from IO::Socket |
196
|
543
|
|
|
|
|
2243
|
${*$self}{ie_fh} = $fh; |
|
543
|
|
|
|
|
12567
|
|
197
|
543
|
|
|
|
|
4089
|
${*$self}{ie_handler} = $handler; |
|
543
|
|
|
|
|
5439
|
|
198
|
543
|
|
|
|
|
2964
|
${*$self}{ie_ibuf} = ''; |
|
543
|
|
|
|
|
13165593
|
|
199
|
543
|
|
|
|
|
1929
|
${*$self}{ie_obuf} = ''; |
|
543
|
|
|
|
|
6412
|
|
200
|
543
|
|
|
|
|
9690
|
${*$self}{ie_obufsize} = BUFSIZ*4; |
|
543
|
|
|
|
|
2461
|
|
201
|
543
|
|
|
|
|
1782
|
${*$self}{ie_autoread} = 1; |
|
543
|
|
|
|
|
2722
|
|
202
|
543
|
|
|
|
|
4409
|
${*$self}{ie_pending} = {}; |
|
543
|
|
|
|
|
3500
|
|
203
|
543
|
|
66
|
|
|
9976
|
${*$self}{ie_desc} = $options->{description} || "wrapper for $fh"; |
|
543
|
|
|
|
|
7421
|
|
204
|
543
|
50
|
|
|
|
4288
|
${*$self}{ie_writeclosed} = EINVAL if $options->{read_only}; |
|
0
|
|
|
|
|
0
|
|
205
|
543
|
50
|
|
|
|
2831
|
${*$self}{ie_readclosed} = EINVAL if $options->{write_only}; |
|
0
|
|
|
|
|
0
|
|
206
|
|
|
|
|
|
|
|
207
|
543
|
|
|
|
|
9436
|
$self->ie_register(); |
208
|
543
|
|
|
|
|
3394
|
$fh->blocking(0); |
209
|
543
|
50
|
|
|
|
3874
|
print "New IO::Event: ${*$self}{ie_desc} - now nonblocking\n" if $debug; |
|
0
|
|
|
|
|
0
|
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# stolen from IO::Multiplex |
212
|
543
|
|
|
|
|
25459
|
tie(*$self, $pkg, $self); |
213
|
543
|
|
|
|
|
565759
|
return $self; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub reset |
217
|
|
|
|
|
|
|
{ |
218
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
219
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_writeclosed}; |
|
0
|
|
|
|
|
0
|
|
220
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_readclosed}; |
|
0
|
|
|
|
|
0
|
|
221
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_eofinvoked}; |
|
0
|
|
|
|
|
0
|
|
222
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_overflowinvoked}; |
|
0
|
|
|
|
|
0
|
|
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# mark as listener |
226
|
|
|
|
|
|
|
sub listener |
227
|
|
|
|
|
|
|
{ |
228
|
12
|
|
|
12
|
|
29
|
my ($self, $listener) = @_; |
229
|
12
|
50
|
|
|
|
43
|
$listener = 1 unless defined $listener; |
230
|
12
|
|
|
|
|
33
|
my $o = ${*$self}{ie_listener}; |
|
12
|
|
|
|
|
48
|
|
231
|
12
|
|
|
|
|
26
|
${*$self}{ie_listener} = $listener; |
|
12
|
|
|
|
|
78
|
|
232
|
12
|
|
|
|
|
44
|
return $o; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
# call out |
236
|
|
|
|
|
|
|
sub ie_invoke |
237
|
|
|
|
|
|
|
{ |
238
|
614
|
|
|
614
|
|
1698219
|
my ($self, $required, $method, @args) = @_; |
239
|
|
|
|
|
|
|
|
240
|
614
|
100
|
66
|
|
|
2397
|
if ($in_callback && ! ${*$self}->{ie_reentrant}) { |
|
57
|
|
|
|
|
330
|
|
241
|
|
|
|
|
|
|
# we'll do this later |
242
|
57
|
|
|
|
|
320
|
push(@pending_callbacks, [ $self, $required, $method, @args ]) |
243
|
57
|
50
|
|
|
|
62
|
unless exists ${*$self}{ie_pending}{$method}; |
244
|
57
|
|
|
|
|
87
|
${*$self}{ie_pending}{$method} = 1; # prevent double invocation. needed? |
|
57
|
|
|
|
|
169
|
|
245
|
57
|
50
|
|
|
|
132
|
print STDERR "Delaying invocation of $method on ${*$self}{ie_desc} because we're already in a callback\n" if $debug; |
|
0
|
|
|
|
|
0
|
|
246
|
57
|
|
|
|
|
125
|
return; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
557
|
|
|
|
|
1163
|
local($in_callback) = 1; |
250
|
|
|
|
|
|
|
|
251
|
557
|
|
|
|
|
2146
|
$self->ie_do_invoke($required, $method, @args); |
252
|
|
|
|
|
|
|
|
253
|
553
|
|
|
|
|
2155
|
while (@pending_callbacks) { |
254
|
57
|
|
|
|
|
12915
|
my ($ie, $req, $meth, @a) = @{shift @pending_callbacks}; |
|
57
|
|
|
|
|
145
|
|
255
|
57
|
|
|
|
|
113
|
delete ${*$ie}{ie_pending}{$meth}; |
|
57
|
|
|
|
|
176
|
|
256
|
57
|
50
|
|
|
|
145
|
print STDERR "Processing delayed invocation of $meth on ${*$ie}{ie_desc}\n" if $debug; |
|
0
|
|
|
|
|
0
|
|
257
|
57
|
|
|
|
|
130
|
$ie->ie_do_invoke($req, $meth, @a); |
258
|
|
|
|
|
|
|
} |
259
|
553
|
|
|
|
|
1640
|
return; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
sub ie_do_invoke |
263
|
|
|
|
|
|
|
{ |
264
|
614
|
|
|
614
|
|
1528
|
my ($self, $required, $method, @args) = @_; |
265
|
|
|
|
|
|
|
|
266
|
614
|
50
|
|
|
|
1763
|
print STDERR "invoking ${*$self}{ie_fileno} ${*$self}{ie_handler}->$method\n" |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
267
|
|
|
|
|
|
|
if $debug; |
268
|
|
|
|
|
|
|
|
269
|
614
|
50
|
66
|
|
|
2827
|
return if ! $required && ! ${*$self}{ie_handler}->can($method); |
|
199
|
|
|
|
|
1941
|
|
270
|
614
|
50
|
|
|
|
1865
|
if ($debug) { |
271
|
0
|
|
|
|
|
0
|
my ($pkg, $line, $func) = caller(); |
272
|
0
|
|
|
|
|
0
|
print "DISPATCHING $method on ${*$self}{ie_desc} from $func at line $line\n"; |
|
0
|
|
|
|
|
0
|
|
273
|
|
|
|
|
|
|
} |
274
|
614
|
|
|
|
|
1140
|
eval { |
275
|
614
|
|
|
|
|
764
|
${*$self}{ie_handler}->$method($self, @args); |
|
614
|
|
|
|
|
4170
|
|
276
|
|
|
|
|
|
|
}; |
277
|
|
|
|
|
|
|
|
278
|
610
|
50
|
|
|
|
30568
|
print STDERR "return from ${*$self}{ie_fileno} ${*$self}{ie_handler}->$method handler: $@\n" if $debug; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
279
|
|
|
|
|
|
|
|
280
|
610
|
50
|
|
|
|
2391
|
return unless $@; |
281
|
0
|
0
|
|
|
|
0
|
if (${*$self}{ie_handler}->can('ie_died')) { |
|
0
|
|
|
|
|
0
|
|
282
|
0
|
|
|
|
|
0
|
${*$self}{ie_handler}->ie_died($self, $method, $@); |
|
0
|
|
|
|
|
0
|
|
283
|
|
|
|
|
|
|
} else { |
284
|
0
|
|
|
|
|
0
|
confess $@; |
285
|
0
|
|
|
|
|
0
|
exit 1; |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
# |
291
|
|
|
|
|
|
|
# we use a single event handler so that the AUTOLOAD |
292
|
|
|
|
|
|
|
# function can try a single $event object when looking for |
293
|
|
|
|
|
|
|
# methods |
294
|
|
|
|
|
|
|
# |
295
|
|
|
|
|
|
|
sub ie_dispatch |
296
|
|
|
|
|
|
|
{ |
297
|
110
|
50
|
|
110
|
|
19573
|
print STDERR "D" if $sdebug; |
298
|
110
|
|
|
|
|
262
|
my ($self, $ievent) = @_; |
299
|
110
|
|
|
|
|
364
|
my $fh = ${*$self}{ie_fh}; |
|
110
|
|
|
|
|
969
|
|
300
|
110
|
|
|
|
|
689
|
my $got = $ievent->got; |
301
|
|
|
|
|
|
|
{ |
302
|
110
|
50
|
|
|
|
192
|
if ($got & Event::Watcher::R()) { |
|
110
|
|
|
|
|
316
|
|
303
|
110
|
100
|
|
|
|
675
|
last if $self->ie_dispatch_read($fh); |
304
|
|
|
|
|
|
|
} |
305
|
89
|
50
|
|
|
|
305
|
if ($got & Event::Watcher::W()) { |
306
|
0
|
0
|
|
|
|
0
|
last if $self->ie_dispatch_write($fh); |
307
|
|
|
|
|
|
|
} |
308
|
89
|
50
|
|
|
|
203
|
if ($got & Event::Watcher::E()) { |
309
|
0
|
|
|
|
|
0
|
$self->ie_dispatch_exception($fh); |
310
|
|
|
|
|
|
|
} |
311
|
89
|
50
|
|
|
|
22579946
|
if ($got & Event::Watcher::T()) { |
312
|
0
|
|
|
|
|
0
|
$self->ie_dispatch_timer(); |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
sub ie_dispatch_read |
319
|
|
|
|
|
|
|
{ |
320
|
425
|
|
|
425
|
|
1397
|
my ($self, $fh) = @_; |
321
|
425
|
50
|
|
|
|
1770
|
printf STDERR "R%d", $self->fileno if $sdebug; |
322
|
425
|
100
|
|
|
|
673
|
if (${*$self}{ie_listener}) { |
|
425
|
50
|
|
|
|
2323
|
|
|
323
|
|
|
|
|
1439
|
|
323
|
102
|
|
|
|
|
341
|
$self->ie_invoke(1, 'ie_connection'); |
324
|
|
|
|
|
|
|
} elsif (${*$self}{ie_autoread}) { |
325
|
323
|
|
|
|
|
2078
|
$self->ie_input(); |
326
|
|
|
|
|
|
|
} else { |
327
|
0
|
|
|
|
|
0
|
$self->ie_invoke(1, 'ie_read_ready', $fh); |
328
|
|
|
|
|
|
|
} |
329
|
421
|
100
|
66
|
|
|
898
|
return 1 if ${*$self}{ie_writeclosed} && ${*$self}{ie_readclosed}; |
|
421
|
|
|
|
|
1848
|
|
|
75
|
|
|
|
|
1353038
|
|
330
|
346
|
|
|
|
|
1317
|
return 0; |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
sub ie_dispatch_write |
334
|
|
|
|
|
|
|
{ |
335
|
0
|
|
|
0
|
|
0
|
my ($self, $fh) = @_; |
336
|
0
|
0
|
|
|
|
0
|
printf STDERR "W%d", $self->fileno if $sdebug; |
337
|
0
|
0
|
|
|
|
0
|
if (${*$self}{ie_connecting}) { |
|
0
|
|
|
|
|
0
|
|
338
|
0
|
|
|
|
|
0
|
$self->writeevents(0); |
339
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_connecting}; |
|
0
|
|
|
|
|
0
|
|
340
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_connect_timeout}; |
|
0
|
|
|
|
|
0
|
|
341
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_connected'); |
342
|
|
|
|
|
|
|
} else { |
343
|
0
|
|
|
|
|
0
|
my $obuf = \${*$self}{ie_obuf}; |
|
0
|
|
|
|
|
0
|
|
344
|
0
|
|
|
|
|
0
|
my $rv; |
345
|
0
|
0
|
|
|
|
0
|
if (length($$obuf)) { |
346
|
0
|
|
|
|
|
0
|
$rv = syswrite($fh, $$obuf); |
347
|
0
|
0
|
|
|
|
0
|
if (defined $rv) { |
|
|
0
|
|
|
|
|
|
348
|
0
|
|
|
|
|
0
|
substr($$obuf, 0, $rv) = ''; |
349
|
|
|
|
|
|
|
} elsif ($! == EAGAIN) { |
350
|
|
|
|
|
|
|
# this shouldn't happen, but |
351
|
|
|
|
|
|
|
# it's not that big a deal |
352
|
|
|
|
|
|
|
} else { |
353
|
|
|
|
|
|
|
# the file descriptor is toast |
354
|
0
|
|
|
|
|
0
|
${*$self}{ie_writeclosed} = $!; |
|
0
|
|
|
|
|
0
|
|
355
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_werror', $obuf); |
356
|
|
|
|
|
|
|
} |
357
|
|
|
|
|
|
|
} |
358
|
0
|
0
|
|
|
|
0
|
if (${*$self}{ie_closerequested}) { |
|
0
|
0
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
359
|
0
|
0
|
|
|
|
0
|
if (! length($$obuf)) { |
360
|
0
|
|
|
|
|
0
|
$self->ie_deregister(); |
361
|
0
|
|
|
|
|
0
|
${*$self}{ie_fh}->close(); |
|
0
|
|
|
|
|
0
|
|
362
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_closerequested}; |
|
0
|
|
|
|
|
0
|
|
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
} elsif (${*$self}{ie_shutdownrequested}) { |
365
|
0
|
0
|
|
|
|
0
|
if (! length($$obuf)) { |
366
|
0
|
|
|
|
|
0
|
shutdown(${*$self}{ie_fh}, 1); |
|
0
|
|
|
|
|
0
|
|
367
|
0
|
|
|
|
|
0
|
${*$self}{ie_writeclosed} = 1; |
|
0
|
|
|
|
|
0
|
|
368
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_shutdownrequested}; |
|
0
|
|
|
|
|
0
|
|
369
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_outputdone', $obuf, 0); |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
} else { |
372
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_output', $obuf, $rv); |
373
|
0
|
|
|
|
|
0
|
return 1 if ${*$self}{ie_writeclosed} |
|
0
|
|
|
|
|
0
|
|
374
|
0
|
0
|
0
|
|
|
0
|
&& ${*$self}{ie_readclosed}; |
375
|
0
|
0
|
|
|
|
0
|
if (! length($$obuf)) { |
376
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_outputdone', $obuf, 1); |
377
|
0
|
|
|
|
|
0
|
return 1 if ${*$self}{ie_writeclosed} |
|
0
|
|
|
|
|
0
|
|
378
|
0
|
0
|
0
|
|
|
0
|
&& ${*$self}{ie_readclosed}; |
379
|
0
|
0
|
|
|
|
0
|
if (! length($$obuf)) { |
380
|
0
|
|
|
|
|
0
|
$self->writeevents(0); |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
} |
383
|
0
|
0
|
|
|
|
0
|
if (length($$obuf) > ${*$self}{ie_obufsize}) { |
|
0
|
0
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
384
|
0
|
|
|
|
|
0
|
${*$self}{ie_overflowinvoked} = 1; |
|
0
|
|
|
|
|
0
|
|
385
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_outputoverflow', 1, $obuf); |
386
|
|
|
|
|
|
|
} elsif (${*$self}{ie_overflowinvoked}) { |
387
|
0
|
|
|
|
|
0
|
${*$self}{ie_overflowinvoked} = 0; |
|
0
|
|
|
|
|
0
|
|
388
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_outputoverflow', 0, $obuf); |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
|
} |
392
|
0
|
0
|
0
|
|
|
0
|
return 1 if ${*$self}{ie_writeclosed} && ${*$self}{ie_readclosed}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
393
|
0
|
|
|
|
|
0
|
return 0; |
394
|
|
|
|
|
|
|
} |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
sub ie_dispatch_exception |
397
|
|
|
|
|
|
|
{ |
398
|
0
|
|
|
0
|
|
0
|
my ($self, $fh) = @_; |
399
|
0
|
0
|
|
|
|
0
|
printf STDERR "E%d", fileno(${*$self}{ie_fh}) if $sdebug; |
|
0
|
|
|
|
|
0
|
|
400
|
0
|
0
|
0
|
|
|
0
|
if (${*$self}{ie_closerequested}) { |
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
401
|
0
|
|
|
|
|
0
|
$self->forceclose; |
402
|
0
|
|
|
|
|
0
|
} elsif (${*$self}{ie_writeclosed} && ${*$self}{ie_readclosed}) { |
403
|
0
|
|
|
|
|
0
|
$self->forceclose; |
404
|
|
|
|
|
|
|
} elsif ($fh->eof) { |
405
|
0
|
0
|
|
|
|
0
|
if (length(${*$self}{ie_ibuf})) { |
|
0
|
|
|
|
|
0
|
|
406
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_input', \${*$self}{ie_ibuf}); |
|
0
|
|
|
|
|
0
|
|
407
|
|
|
|
|
|
|
} |
408
|
0
|
0
|
|
|
|
0
|
if (${*$self}{ie_eofinvoked}++) { |
|
0
|
|
|
|
|
0
|
|
409
|
0
|
|
|
|
|
0
|
warn "EOF repeat"; |
410
|
|
|
|
|
|
|
} else { |
411
|
0
|
|
|
|
|
0
|
${*$self}{ie_closecalled} = 0; |
|
0
|
|
|
|
|
0
|
|
412
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_eof', \${*$self}{ie_ibuf}); |
|
0
|
|
|
|
|
0
|
|
413
|
0
|
0
|
|
|
|
0
|
unless (${*$self}{ie_closecalled}) { |
|
0
|
|
|
|
|
0
|
|
414
|
0
|
|
|
|
|
0
|
$self->close; |
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
} |
417
|
|
|
|
|
|
|
} else { |
418
|
|
|
|
|
|
|
# print STDERR "!?!"; |
419
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_exception'); |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
} |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
sub ie_dispatch_timer |
425
|
|
|
|
|
|
|
{ |
426
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
427
|
0
|
0
|
|
|
|
0
|
printf STDERR "T%d", fileno(${*$self}{ie_fh}) if $sdebug; |
|
0
|
|
|
|
|
0
|
|
428
|
0
|
0
|
0
|
|
|
0
|
if (${*$self}{ie_connecting} |
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
429
|
0
|
|
|
|
|
0
|
&& ${*$self}{ie_connect_timeout} |
430
|
|
|
|
|
|
|
&& time >= ${*$self}{ie_connect_timeout}) |
431
|
|
|
|
|
|
|
{ |
432
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_connect_timeout}; |
|
0
|
|
|
|
|
0
|
|
433
|
0
|
0
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_connect_failed', ETIMEDOUT) |
434
|
|
|
|
|
|
|
or $self->ie_invoke(0, 'ie_timer'); |
435
|
|
|
|
|
|
|
} else { |
436
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_timer'); |
437
|
|
|
|
|
|
|
} |
438
|
|
|
|
|
|
|
} |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
# same name as handler since we want to intercept invocations |
442
|
|
|
|
|
|
|
# when processing pending callbacks. Why? |
443
|
|
|
|
|
|
|
sub ie_input |
444
|
|
|
|
|
|
|
{ |
445
|
323
|
|
|
323
|
|
742
|
my $self = shift; |
446
|
323
|
|
|
|
|
510
|
my $ibuf = \${*$self}{ie_ibuf}; |
|
323
|
|
|
|
|
2903
|
|
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
# |
449
|
|
|
|
|
|
|
# We'll loop just to make sure we don't miss an event |
450
|
|
|
|
|
|
|
# |
451
|
323
|
|
|
|
|
719
|
for (;;) { |
452
|
566
|
|
|
|
|
1224
|
my $ol = length($$ibuf); |
453
|
566
|
|
|
|
|
922
|
my $rv = ${*$self}{ie_fh}->sysread($$ibuf, BUFSIZ, $ol); |
|
566
|
|
|
|
|
5036
|
|
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
# my $x = defined($rv) ? $rv : "$!"; # LOST EVENTS |
456
|
|
|
|
|
|
|
# print STDERR ""; # LOST EVENTS |
457
|
|
|
|
|
|
|
|
458
|
566
|
100
|
|
|
|
1124400
|
if ($rv) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
459
|
246
|
|
|
|
|
443
|
delete ${*$self}{ie_readclosed}; |
|
246
|
|
|
|
|
1023
|
|
460
|
|
|
|
|
|
|
} elsif (defined($rv)) { |
461
|
|
|
|
|
|
|
# must be 0 and closed! |
462
|
133
|
|
|
|
|
310
|
${*$self}{ie_readclosed} = 1; |
|
133
|
|
|
|
|
7180
|
|
463
|
133
|
|
|
|
|
438
|
last; |
464
|
|
|
|
|
|
|
} elsif ($! == EAGAIN) { |
465
|
|
|
|
|
|
|
# readclosed = 0? |
466
|
187
|
|
|
|
|
743
|
last; |
467
|
|
|
|
|
|
|
} else { |
468
|
|
|
|
|
|
|
# errors other than EAGAIN aren't recoverable |
469
|
0
|
|
|
|
|
0
|
${*$self}{ie_readclosed} = $!; |
|
0
|
|
|
|
|
0
|
|
470
|
0
|
|
|
|
|
0
|
last; |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
|
473
|
246
|
|
|
|
|
1180
|
$self->ie_invoke(1, 'ie_input', $ibuf); |
474
|
243
|
50
|
|
|
|
392
|
last if ${*$self}{ie_readclosed}; |
|
243
|
|
|
|
|
1298
|
|
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
|
477
|
320
|
100
|
|
|
|
502
|
if (${*$self}{ie_readclosed}) { |
|
320
|
|
|
|
|
1554
|
|
478
|
133
|
100
|
|
|
|
916
|
$self->ie_invoke(1, 'ie_input', $ibuf) |
479
|
|
|
|
|
|
|
if length($$ibuf); |
480
|
133
|
50
|
|
|
|
249
|
if (${*$self}{ie_connecting}) { |
|
133
|
|
|
|
|
596
|
|
481
|
0
|
|
|
|
|
0
|
${*$self}{ie_writeclosed} = $!; |
|
0
|
|
|
|
|
0
|
|
482
|
0
|
|
|
|
|
0
|
$self->writeevents(0); |
483
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_connecting}; |
|
0
|
|
|
|
|
0
|
|
484
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_connect_timeout}; |
|
0
|
|
|
|
|
0
|
|
485
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_connect_failed', $!); |
486
|
|
|
|
|
|
|
} else { |
487
|
133
|
|
|
|
|
1261
|
$self->ie_invoke(0, 'ie_eof', $ibuf) |
488
|
133
|
50
|
|
|
|
179
|
unless ${*$self}{ie_eofinvoked}++; |
489
|
|
|
|
|
|
|
} |
490
|
132
|
|
|
|
|
1277
|
$self->readevents(0); |
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
sub reentrant |
495
|
|
|
|
|
|
|
{ |
496
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
497
|
0
|
|
|
|
|
0
|
my $old = ${*$self}{ie_reentrant}; |
|
0
|
|
|
|
|
0
|
|
498
|
0
|
0
|
|
|
|
0
|
if (@_) { |
499
|
0
|
|
|
|
|
0
|
${*$self}{ie_reentrant} = $_[0]; |
|
0
|
|
|
|
|
0
|
|
500
|
|
|
|
|
|
|
} |
501
|
0
|
|
|
|
|
0
|
return $old; |
502
|
|
|
|
|
|
|
} |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
sub output_bufsize |
505
|
|
|
|
|
|
|
{ |
506
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
507
|
0
|
|
|
|
|
0
|
my $old = ${*$self}{ie_obufsize}; |
|
0
|
|
|
|
|
0
|
|
508
|
0
|
0
|
|
|
|
0
|
if (@_) { |
509
|
0
|
|
|
|
|
0
|
${*$self}{ie_obufsize} = $_[0]; |
|
0
|
|
|
|
|
0
|
|
510
|
0
|
0
|
|
|
|
0
|
if (length(${*$self}{ie_obuf}) > ${*$self}{ie_obufsize}) { |
|
0
|
0
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
511
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_outputoverflow', 1, ${*$self}{ie_obuf}); |
|
0
|
|
|
|
|
0
|
|
512
|
0
|
|
|
|
|
0
|
${*$self}{ie_overflowinvoked} = 1; |
|
0
|
|
|
|
|
0
|
|
513
|
|
|
|
|
|
|
} elsif (${*$self}{ie_overflowinvoked}) { |
514
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_outputoverflow', 0, ${*$self}{ie_obuf}); |
|
0
|
|
|
|
|
0
|
|
515
|
0
|
|
|
|
|
0
|
${*$self}{ie_overflowinvoked} = 0; |
|
0
|
|
|
|
|
0
|
|
516
|
|
|
|
|
|
|
} |
517
|
|
|
|
|
|
|
# while this should trigger callbacks, we don't want to assume |
518
|
|
|
|
|
|
|
# that our caller's code is re-enterant. |
519
|
|
|
|
|
|
|
} |
520
|
0
|
|
|
|
|
0
|
return $old; |
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
# get/set autoread |
524
|
|
|
|
|
|
|
sub autoread |
525
|
|
|
|
|
|
|
{ |
526
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
527
|
0
|
|
|
|
|
0
|
my $old = ${*$self}{ie_autoread}; |
|
0
|
|
|
|
|
0
|
|
528
|
0
|
0
|
|
|
|
0
|
if (@_) { |
529
|
0
|
|
|
|
|
0
|
${*$self}{ie_autoread} = $_[0]; |
|
0
|
|
|
|
|
0
|
|
530
|
0
|
0
|
|
|
|
0
|
if (${*$self}{ie_readclosed}) { |
|
0
|
|
|
|
|
0
|
|
531
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_readclosed}; |
|
0
|
|
|
|
|
0
|
|
532
|
0
|
|
|
|
|
0
|
$self->readevents(1); |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
} |
535
|
0
|
|
|
|
|
0
|
return $old; |
536
|
|
|
|
|
|
|
} |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
sub writeevents |
539
|
|
|
|
|
|
|
{ |
540
|
623
|
|
|
623
|
|
1599
|
my $self = shift; |
541
|
623
|
|
|
|
|
2153
|
my $old = ${*$self}{ie_want_write_events}; |
|
623
|
|
|
|
|
4757
|
|
542
|
623
|
50
|
|
|
|
8224
|
return !! $old unless @_; |
543
|
623
|
|
|
|
|
1788
|
my $new = !! shift; |
544
|
623
|
100
|
66
|
|
|
5134906
|
return $old if defined($old) && $old eq $new; |
545
|
172
|
|
|
|
|
326
|
${*$self}{ie_want_write_events} = $new; |
|
172
|
|
|
|
|
2038
|
|
546
|
172
|
|
|
|
|
2345
|
$self->set_write_polling($new); |
547
|
172
|
|
|
|
|
417
|
return $old; |
548
|
|
|
|
|
|
|
} |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
sub readevents |
551
|
|
|
|
|
|
|
{ |
552
|
755
|
|
|
755
|
|
2395
|
my $self = shift; |
553
|
755
|
|
|
|
|
1912
|
my $old = ${*$self}{ie_want_read_events}; |
|
755
|
|
|
|
|
4375
|
|
554
|
755
|
50
|
|
|
|
7882
|
return !! $old unless @_; |
555
|
755
|
|
|
|
|
3736
|
my $new = !! shift; |
556
|
|
|
|
|
|
|
# print STDERR ""; # LOST EVENTS |
557
|
755
|
100
|
100
|
|
|
8947822
|
return $old if defined($old) && $old eq $new; |
558
|
680
|
|
|
|
|
1707
|
${*$self}{ie_want_read_events} = $new; |
|
680
|
|
|
|
|
5976
|
|
559
|
680
|
|
|
|
|
8284
|
$self->set_read_polling($new); |
560
|
680
|
|
|
|
|
12597435
|
return $old; |
561
|
|
|
|
|
|
|
} |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
sub drain |
564
|
|
|
|
|
|
|
{ |
565
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
566
|
0
|
|
|
|
|
0
|
$self->writeevents(1); |
567
|
|
|
|
|
|
|
} |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
# register with Event |
570
|
|
|
|
|
|
|
sub ie_register |
571
|
|
|
|
|
|
|
{ |
572
|
543
|
|
|
543
|
|
1861
|
my ($self) = @_; |
573
|
543
|
|
|
|
|
1396
|
my $fh = ${*$self}{ie_fh}; |
|
543
|
|
|
|
|
3116
|
|
574
|
543
|
|
|
|
|
7148
|
$fh->blocking(0); |
575
|
543
|
|
|
|
|
10865
|
$fh->autoflush(1); |
576
|
|
|
|
|
|
|
|
577
|
543
|
|
|
|
|
134051
|
my $fileno = ${*$self}{ie_fileno} = $fh->fileno; |
|
543
|
|
|
|
|
11100
|
|
578
|
543
|
|
|
|
|
3385
|
return ($fh, $fileno); |
579
|
|
|
|
|
|
|
} |
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
# deregister with Event |
582
|
|
|
|
|
|
|
sub ie_deregister |
583
|
|
|
|
|
|
|
{ |
584
|
451
|
|
|
451
|
|
1823
|
my ($self) = @_; |
585
|
451
|
|
|
|
|
1416
|
my $fh = ${*$self}{ie_fh}; |
|
451
|
|
|
|
|
3082
|
|
586
|
451
|
|
|
|
|
25748
|
delete $fh_table{$fh}; |
587
|
451
|
|
|
|
|
14021
|
$self->readevents(0); |
588
|
451
|
|
|
|
|
5649
|
$self->writeevents(0); |
589
|
|
|
|
|
|
|
} |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
# the standard max() function |
592
|
|
|
|
|
|
|
sub ie_max |
593
|
|
|
|
|
|
|
{ |
594
|
0
|
|
|
0
|
|
0
|
my ($max, @stuff) = @_; |
595
|
0
|
|
|
|
|
0
|
for my $t (@stuff) { |
596
|
0
|
0
|
|
|
|
0
|
$max = $t if $t > $max; |
597
|
|
|
|
|
|
|
} |
598
|
0
|
|
|
|
|
0
|
return $max; |
599
|
|
|
|
|
|
|
} |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
# get the Filehandle |
602
|
|
|
|
|
|
|
sub filehandle |
603
|
|
|
|
|
|
|
{ |
604
|
12
|
|
|
12
|
|
96
|
my ($self) = @_; |
605
|
12
|
|
|
|
|
16
|
return ${*$self}{ie_fh}; |
|
12
|
|
|
|
|
44
|
|
606
|
|
|
|
|
|
|
} |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
# get the Event |
609
|
|
|
|
|
|
|
sub event |
610
|
|
|
|
|
|
|
{ |
611
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
612
|
0
|
|
|
|
|
0
|
return ${*$self}{ie_event}; |
|
0
|
|
|
|
|
0
|
|
613
|
|
|
|
|
|
|
} |
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
# set the handler |
616
|
|
|
|
|
|
|
sub handler |
617
|
|
|
|
|
|
|
{ |
618
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
619
|
0
|
|
|
|
|
0
|
my $old = ${*$self}{ie_handler}; |
|
0
|
|
|
|
|
0
|
|
620
|
0
|
0
|
|
|
|
0
|
${*$self}{ie_handler} = $_[0] |
|
0
|
|
|
|
|
0
|
|
621
|
|
|
|
|
|
|
if @_; |
622
|
0
|
|
|
|
|
0
|
return $old; |
623
|
|
|
|
|
|
|
} |
624
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
# is there enough? |
626
|
|
|
|
|
|
|
sub can_read |
627
|
|
|
|
|
|
|
{ |
628
|
0
|
|
|
0
|
|
0
|
my ($self, $length) = @_; |
629
|
0
|
|
|
|
|
0
|
my $l = length(${*$self}{ie_ibuf}); |
|
0
|
|
|
|
|
0
|
|
630
|
0
|
0
|
0
|
|
|
0
|
return $l if $l && $l >= $length; |
631
|
0
|
0
|
|
|
|
0
|
return "0 but true" if $length <= 0; |
632
|
0
|
|
|
|
|
0
|
return 0; |
633
|
|
|
|
|
|
|
} |
634
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
# reads N characters or returns undef if it can't |
636
|
|
|
|
|
|
|
sub getsome |
637
|
|
|
|
|
|
|
{ |
638
|
54
|
|
|
54
|
|
64
|
my ($self, $length) = @_; |
639
|
54
|
50
|
|
|
|
243
|
return undef unless ${*$self}{ie_autoread}; |
|
54
|
|
|
|
|
166
|
|
640
|
54
|
|
|
|
|
65
|
my $ibuf = \${*$self}{ie_ibuf}; |
|
54
|
|
|
|
|
102
|
|
641
|
54
|
50
|
|
|
|
153
|
$length = length($$ibuf) |
642
|
|
|
|
|
|
|
unless defined $length; |
643
|
54
|
|
|
|
|
80
|
my $tmp = substr($$ibuf, 0, $length); |
644
|
54
|
|
|
|
|
66
|
substr($$ibuf, 0, $length) = ''; |
645
|
54
|
50
|
66
|
|
|
111
|
return undef if ! length($tmp) && ! $self->eof2; |
646
|
51
|
|
|
|
|
148
|
return $tmp; |
647
|
|
|
|
|
|
|
} |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
# from base perl |
650
|
|
|
|
|
|
|
# will this work right for SOCK_DGRAM? |
651
|
|
|
|
|
|
|
sub connect |
652
|
|
|
|
|
|
|
{ |
653
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
654
|
0
|
|
|
|
|
0
|
my $fh = ${*$self}{ie_fh}; |
|
0
|
|
|
|
|
0
|
|
655
|
0
|
|
|
|
|
0
|
my $rv = $fh->connect(@_); |
656
|
0
|
|
|
|
|
0
|
$self->reset; |
657
|
0
|
|
|
|
|
0
|
$self->readevents(1); |
658
|
0
|
0
|
|
|
|
0
|
unless($fh->connected()) { |
659
|
0
|
|
|
|
|
0
|
${*$self}{ie_connecting} = 1; |
|
0
|
|
|
|
|
0
|
|
660
|
0
|
|
|
|
|
0
|
$self->writeevents(1); |
661
|
0
|
|
|
|
|
0
|
${*$self}{ie_connect_timeout} = time |
|
0
|
|
|
|
|
0
|
|
662
|
0
|
|
|
|
|
0
|
+ ${*$self}{ie_socket_timeout} |
663
|
0
|
0
|
|
|
|
0
|
if ${*$self}{ie_socket_timeout}; |
664
|
|
|
|
|
|
|
} |
665
|
0
|
|
|
|
|
0
|
return $rv; |
666
|
|
|
|
|
|
|
} |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
# from IO::Socket |
669
|
|
|
|
|
|
|
sub listen |
670
|
|
|
|
|
|
|
{ |
671
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
672
|
0
|
|
|
|
|
0
|
my $fh = ${*$self}{ie_fh}; |
|
0
|
|
|
|
|
0
|
|
673
|
0
|
|
|
|
|
0
|
my $rv = $fh->listen(); |
674
|
0
|
|
|
|
|
0
|
$self->listener(1); |
675
|
0
|
|
|
|
|
0
|
return $rv; |
676
|
|
|
|
|
|
|
} |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
# from IO::Socket |
679
|
|
|
|
|
|
|
sub accept |
680
|
|
|
|
|
|
|
{ |
681
|
102
|
|
|
102
|
|
2522
|
my ($self, $handler) = @_; |
682
|
102
|
|
|
|
|
154
|
my $fh = ${*$self}{ie_fh}; |
|
102
|
|
|
|
|
390
|
|
683
|
102
|
|
|
|
|
545
|
my $newfh = $fh->accept(); |
684
|
102
|
50
|
|
|
|
23550
|
return undef unless $newfh; |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
# it appears that sockdomain isn't set on accept()ed sockets |
687
|
102
|
|
|
|
|
536
|
my $sd = $fh->sockdomain; |
688
|
|
|
|
|
|
|
|
689
|
102
|
|
|
|
|
1163
|
my $desc; |
690
|
102
|
50
|
|
|
|
492
|
if ($sd == &AF_INET) { |
|
|
0
|
|
|
|
|
|
691
|
102
|
|
|
|
|
488
|
$desc = sprintf "Accepted socket from %s:%s to %s:%s", |
692
|
|
|
|
|
|
|
$newfh->peerhost, $newfh->peerport, |
693
|
|
|
|
|
|
|
$newfh->sockhost, $newfh->sockport; |
694
|
|
|
|
|
|
|
} elsif ($sd == &AF_UNIX) { |
695
|
|
|
|
|
|
|
# Unset peerpath crashes on FreeBSD 9 |
696
|
0
|
|
|
|
|
0
|
my $pp = eval { $newfh->peerpath }; |
|
0
|
|
|
|
|
0
|
|
697
|
0
|
0
|
|
|
|
0
|
if ($pp) { |
698
|
0
|
|
|
|
|
0
|
$desc = sprintf "Accepted socket from %s to %s", |
699
|
|
|
|
|
|
|
$pp, $newfh->hostpath; |
700
|
|
|
|
|
|
|
} else { |
701
|
0
|
|
|
|
|
0
|
$desc = sprintf "Accepted socket from to %s", |
702
|
|
|
|
|
|
|
$newfh->hostpath; |
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
} else { |
705
|
0
|
|
|
|
|
0
|
$desc = "Accept for ${*$self}{ie_desc}"; |
|
0
|
|
|
|
|
0
|
|
706
|
|
|
|
|
|
|
} |
707
|
102
|
100
|
|
|
|
13383
|
$handler = ${*$self}{ie_handler} |
|
60
|
|
|
|
|
174
|
|
708
|
|
|
|
|
|
|
unless defined $handler; |
709
|
102
|
|
|
|
|
817
|
my $new = IO::Event->new($newfh, $handler, $desc); |
710
|
102
|
|
|
|
|
282
|
${*$new}{ie_obufsize} = ${*$self}{ie_obufsize}; |
|
102
|
|
|
|
|
441
|
|
|
102
|
|
|
|
|
579
|
|
711
|
102
|
|
|
|
|
255
|
${*$new}{ie_reentrant} = ${*$self}{ie_reentrant}; |
|
102
|
|
|
|
|
604
|
|
|
102
|
|
|
|
|
550
|
|
712
|
102
|
|
|
|
|
442
|
return $new; |
713
|
|
|
|
|
|
|
} |
714
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
# not the same as IO::Handle |
716
|
|
|
|
|
|
|
sub input_record_separator |
717
|
|
|
|
|
|
|
{ |
718
|
42
|
|
|
42
|
|
849
|
my $self = shift; |
719
|
42
|
|
|
|
|
66
|
my $old = ${*$self}{ie_irs}; |
|
42
|
|
|
|
|
127
|
|
720
|
42
|
50
|
|
|
|
142
|
${*$self}{ie_irs} = $_[0] |
|
42
|
|
|
|
|
141
|
|
721
|
|
|
|
|
|
|
if @_; |
722
|
42
|
50
|
|
|
|
163
|
if ($debug) { |
723
|
0
|
|
|
|
|
0
|
my $fn = $self->fileno; |
724
|
0
|
|
|
|
|
0
|
my $x = ${*$self}{ie_irs}; |
|
0
|
|
|
|
|
0
|
|
725
|
0
|
|
|
|
|
0
|
$x =~ s/\n/\\n/g; |
726
|
0
|
|
|
|
|
0
|
print "input_record_separator($fn) = '$x'\n"; |
727
|
|
|
|
|
|
|
} |
728
|
42
|
|
|
|
|
134
|
return $old; |
729
|
|
|
|
|
|
|
} |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
# 0 = read |
732
|
|
|
|
|
|
|
# 1 = write |
733
|
|
|
|
|
|
|
# 2 = both |
734
|
|
|
|
|
|
|
sub shutdown |
735
|
|
|
|
|
|
|
{ |
736
|
0
|
|
|
0
|
|
0
|
my ($self, $what) = @_; |
737
|
0
|
|
|
|
|
0
|
my $r; |
738
|
0
|
0
|
0
|
|
|
0
|
if ($what == 1 || $what == 2) { |
|
|
0
|
|
|
|
|
|
739
|
0
|
0
|
|
|
|
0
|
if (length(${*$self}{ie_obuf})) { |
|
0
|
|
|
|
|
0
|
|
740
|
0
|
|
|
|
|
0
|
${*$self}{ie_shutdownrequested} = $what; |
|
0
|
|
|
|
|
0
|
|
741
|
0
|
0
|
|
|
|
0
|
if ($what == 2) { |
742
|
0
|
|
|
|
|
0
|
$r = shutdown(${*$self}{ie_fh}, 0) |
|
0
|
|
|
|
|
0
|
|
743
|
|
|
|
|
|
|
} |
744
|
|
|
|
|
|
|
} else { |
745
|
0
|
|
|
|
|
0
|
$r = shutdown(${*$self}{ie_fh}, $what); |
|
0
|
|
|
|
|
0
|
|
746
|
0
|
|
|
|
|
0
|
${*$self}{ie_writeclosed} = 1; |
|
0
|
|
|
|
|
0
|
|
747
|
|
|
|
|
|
|
} |
748
|
|
|
|
|
|
|
} elsif ($what == 0) { |
749
|
0
|
|
|
|
|
0
|
$r = shutdown(${*$self}{ie_fh}, 0); |
|
0
|
|
|
|
|
0
|
|
750
|
|
|
|
|
|
|
} else { |
751
|
0
|
|
|
|
|
0
|
die; |
752
|
|
|
|
|
|
|
} |
753
|
0
|
0
|
0
|
|
|
0
|
if ($what == 0 || $what == 2) { |
754
|
0
|
|
|
|
|
0
|
${*$self}{ie_readclosed} = 1; |
|
0
|
|
|
|
|
0
|
|
755
|
|
|
|
|
|
|
} |
756
|
0
|
0
|
|
|
|
0
|
return 1 unless defined($r); |
757
|
0
|
|
|
|
|
0
|
return $r; |
758
|
|
|
|
|
|
|
} |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
# from IO::Handle |
761
|
|
|
|
|
|
|
sub close |
762
|
|
|
|
|
|
|
{ |
763
|
451
|
|
|
451
|
|
11213397
|
my ($self) = @_; |
764
|
451
|
|
|
|
|
3479
|
my $obuf = \${*$self}{ie_obuf}; |
|
451
|
|
|
|
|
9918
|
|
765
|
451
|
|
|
|
|
13596305
|
${*$self}{ie_closecalled} = 1; |
|
451
|
|
|
|
|
8123
|
|
766
|
451
|
50
|
|
|
|
5507
|
if (length($$obuf)) { |
767
|
0
|
|
|
|
|
0
|
${*$self}{ie_closerequested} = 1; |
|
0
|
|
|
|
|
0
|
|
768
|
0
|
|
|
|
|
0
|
${*$self}{ie_writeclosed} = 1; |
|
0
|
|
|
|
|
0
|
|
769
|
0
|
|
|
|
|
0
|
${*$self}{ie_readclosed} = 1; |
|
0
|
|
|
|
|
0
|
|
770
|
|
|
|
|
|
|
} else { |
771
|
451
|
|
|
|
|
9877
|
return $self->forceclose; |
772
|
|
|
|
|
|
|
} |
773
|
|
|
|
|
|
|
} |
774
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
sub forceclose |
776
|
|
|
|
|
|
|
{ |
777
|
451
|
|
|
451
|
|
2384
|
my ($self) = @_; |
778
|
451
|
|
|
|
|
5578
|
$self->ie_deregister(); |
779
|
451
|
|
|
|
|
1139
|
my $ret = ${*$self}{ie_fh}->close(); |
|
451
|
|
|
|
|
1845878
|
|
780
|
451
|
|
|
|
|
41301
|
${*$self}{ie_writeclosed} = 1; |
|
451
|
|
|
|
|
2318
|
|
781
|
451
|
|
|
|
|
1085
|
${*$self}{ie_readclosed} = 1; |
|
451
|
|
|
|
|
1931
|
|
782
|
451
|
|
|
|
|
1329
|
${*$self}{ie_totallyclosed} = 1; |
|
451
|
|
|
|
|
2083
|
|
783
|
451
|
50
|
|
|
|
1971
|
print STDERR "forceclose(${*$self}{ie_desc})\n" if $debug; |
|
0
|
|
|
|
|
0
|
|
784
|
451
|
|
|
|
|
1872
|
return $ret; |
785
|
|
|
|
|
|
|
} |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
# from IO::Handle |
788
|
|
|
|
|
|
|
sub open |
789
|
|
|
|
|
|
|
{ |
790
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
791
|
0
|
|
|
|
|
0
|
my $fh = ${*$self}{ie_fh}; |
|
0
|
|
|
|
|
0
|
|
792
|
0
|
|
|
|
|
0
|
$self->ie_deregister(); |
793
|
0
|
0
|
|
|
|
0
|
$self->close() |
794
|
|
|
|
|
|
|
if $fh->opened; |
795
|
0
|
|
|
|
|
0
|
$self->reset; |
796
|
0
|
|
|
|
|
0
|
my $r; |
797
|
0
|
0
|
|
|
|
0
|
if (@_ == 1) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
798
|
0
|
|
|
|
|
0
|
$r = CORE::open($fh, $_[0]); |
799
|
|
|
|
|
|
|
} elsif (@_ == 2) { |
800
|
0
|
|
|
|
|
0
|
$r = CORE::open($fh, $_[0], $_[1]); |
801
|
|
|
|
|
|
|
} elsif (@_ == 3) { |
802
|
0
|
|
|
|
|
0
|
$r = CORE::open($fh, $_[0], $_[1], $_[4]); |
803
|
|
|
|
|
|
|
} elsif (@_ > 3) { |
804
|
0
|
|
|
|
|
0
|
$r = CORE::open($fh, $_[0], $_[1], $_[4], @_); |
805
|
|
|
|
|
|
|
} else { |
806
|
0
|
|
|
|
|
0
|
confess("open w/o enoug args"); |
807
|
|
|
|
|
|
|
} |
808
|
0
|
0
|
|
|
|
0
|
return undef unless defined $r; |
809
|
0
|
|
|
|
|
0
|
$self->ie_register(); |
810
|
0
|
|
|
|
|
0
|
return $r; |
811
|
|
|
|
|
|
|
} |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
# from IO::Handle VAR LENGTH [OFFSET] |
815
|
|
|
|
|
|
|
# |
816
|
|
|
|
|
|
|
# this returns nothing unless there is enough to fill |
817
|
|
|
|
|
|
|
# the request or it's at eof |
818
|
|
|
|
|
|
|
# |
819
|
|
|
|
|
|
|
sub sysread |
820
|
|
|
|
|
|
|
{ |
821
|
90
|
|
|
90
|
|
825
|
my $self = shift; |
822
|
|
|
|
|
|
|
|
823
|
90
|
50
|
|
|
|
96
|
unless (${*$self}{ie_autoread}) { |
|
90
|
|
|
|
|
304
|
|
824
|
0
|
|
|
|
|
0
|
my $buf = shift; |
825
|
0
|
|
|
|
|
0
|
my $length = shift; |
826
|
0
|
|
|
|
|
0
|
my $rv = ${*$self}{ie_fh}->sysread($buf, $length, @_); |
|
0
|
|
|
|
|
0
|
|
827
|
|
|
|
|
|
|
|
828
|
0
|
0
|
|
|
|
0
|
if ($rv) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
829
|
0
|
|
|
|
|
0
|
delete ${*$self}{ie_readclosed}; |
|
0
|
|
|
|
|
0
|
|
830
|
|
|
|
|
|
|
} elsif (defined($rv)) { |
831
|
|
|
|
|
|
|
# must be 0 and closed! |
832
|
0
|
|
|
|
|
0
|
${*$self}{ie_readclosed} = 1; |
|
0
|
|
|
|
|
0
|
|
833
|
|
|
|
|
|
|
} elsif ($! == EAGAIN) { |
834
|
|
|
|
|
|
|
# nothing there |
835
|
|
|
|
|
|
|
} else { |
836
|
|
|
|
|
|
|
# errors other than EAGAIN aren't recoverable |
837
|
0
|
|
|
|
|
0
|
${*$self}{ie_readclosed} = $!; |
|
0
|
|
|
|
|
0
|
|
838
|
|
|
|
|
|
|
} |
839
|
0
|
|
|
|
|
0
|
return $rv; |
840
|
|
|
|
|
|
|
} |
841
|
|
|
|
|
|
|
|
842
|
90
|
|
|
|
|
113
|
my $ibuf = \${*$self}{ie_ibuf}; |
|
90
|
|
|
|
|
173
|
|
843
|
90
|
|
|
|
|
208
|
my $length = length($$ibuf); |
844
|
|
|
|
|
|
|
|
845
|
90
|
100
|
100
|
|
|
272
|
return undef unless $length >= $_[1] || $self->eof2; |
846
|
|
|
|
|
|
|
|
847
|
78
|
100
|
|
|
|
322
|
(defined $_[2] ? |
848
|
|
|
|
|
|
|
substr ($_[0], $_[2], length($_[0])) |
849
|
|
|
|
|
|
|
: $_[0]) |
850
|
|
|
|
|
|
|
= substr($$ibuf, 0, $_[1]); |
851
|
|
|
|
|
|
|
|
852
|
78
|
|
|
|
|
140
|
substr($$ibuf, 0, $_[1]) = ''; |
853
|
78
|
|
|
|
|
204
|
return ($length-length($$ibuf)); |
854
|
|
|
|
|
|
|
} |
855
|
|
|
|
|
|
|
|
856
|
|
|
|
|
|
|
# from IO::Handle |
857
|
|
|
|
|
|
|
sub syswrite |
858
|
|
|
|
|
|
|
{ |
859
|
0
|
|
|
0
|
|
0
|
my ($self, $data, $length, $offset) = @_; |
860
|
0
|
0
|
0
|
|
|
0
|
if (defined $offset or defined $length) { |
861
|
0
|
|
|
|
|
0
|
return $self->print(substr($data, $offset, $length)); |
862
|
|
|
|
|
|
|
} else { |
863
|
0
|
|
|
|
|
0
|
return $self->print($data); |
864
|
|
|
|
|
|
|
} |
865
|
|
|
|
|
|
|
} |
866
|
|
|
|
|
|
|
|
867
|
|
|
|
|
|
|
# like Data::LineBuffer |
868
|
|
|
|
|
|
|
sub get |
869
|
|
|
|
|
|
|
{ |
870
|
33
|
|
|
33
|
|
5530
|
my $self = shift; |
871
|
33
|
50
|
|
|
|
194
|
return undef unless ${*$self}{ie_autoread}; |
|
33
|
|
|
|
|
134
|
|
872
|
33
|
|
|
|
|
48
|
my $ibuf = \${*$self}{ie_ibuf}; |
|
33
|
|
|
|
|
141
|
|
873
|
33
|
|
|
|
|
63
|
my $irs = "\n"; |
874
|
33
|
|
|
|
|
70
|
my $index = index($$ibuf, $irs); |
875
|
33
|
100
|
|
|
|
87
|
if ($index < 0) { |
876
|
15
|
100
|
|
|
|
76
|
return undef unless $self->eof2; |
877
|
6
|
|
|
|
|
17
|
my $l = $$ibuf; |
878
|
6
|
|
|
|
|
11
|
$$ibuf = ''; |
879
|
6
|
100
|
|
|
|
25
|
return undef unless length($l); |
880
|
3
|
|
|
|
|
12
|
return $l; |
881
|
|
|
|
|
|
|
} |
882
|
18
|
|
|
|
|
151
|
my $line = substr($$ibuf, 0, $index - length($irs) + 1); |
883
|
18
|
|
|
|
|
51
|
substr($$ibuf, 0, $index + 1) = ''; |
884
|
18
|
|
|
|
|
73
|
return $line; |
885
|
|
|
|
|
|
|
} |
886
|
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
# like Data::LineBuffer |
888
|
|
|
|
|
|
|
# input_record_separator is always "\n". |
889
|
|
|
|
|
|
|
sub unget |
890
|
|
|
|
|
|
|
{ |
891
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
892
|
0
|
|
|
|
|
0
|
my $irs = "\n"; |
893
|
58
|
|
|
58
|
|
355002
|
no warnings; |
|
58
|
|
|
|
|
298
|
|
|
58
|
|
|
|
|
19208
|
|
894
|
0
|
|
|
|
|
0
|
substr(${*$self}{ie_ibuf}, 0, 0) |
|
0
|
|
|
|
|
0
|
|
895
|
|
|
|
|
|
|
= join($irs, @_, undef); |
896
|
|
|
|
|
|
|
} |
897
|
|
|
|
|
|
|
|
898
|
|
|
|
|
|
|
# from IO::Handle |
899
|
|
|
|
|
|
|
sub getline |
900
|
|
|
|
|
|
|
{ |
901
|
805
|
|
|
805
|
|
2362
|
my $self = shift; |
902
|
805
|
50
|
|
|
|
1256
|
return undef unless ${*$self}{ie_autoread}; |
|
805
|
|
|
|
|
3497
|
|
903
|
805
|
|
|
|
|
1523
|
my $ibuf = \${*$self}{ie_ibuf}; |
|
805
|
|
|
|
|
1934
|
|
904
|
805
|
|
|
|
|
1284
|
my $fh = ${*$self}{ie_fh}; |
|
805
|
|
|
|
|
1673
|
|
905
|
805
|
100
|
|
|
|
1058
|
my $irs = exists ${*$self}{ie_irs} ? ${*$self}{ie_irs} : $/; |
|
805
|
|
|
|
|
2821
|
|
|
153
|
|
|
|
|
404
|
|
906
|
805
|
|
|
|
|
1295
|
my $line; |
907
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
|
909
|
|
|
|
|
|
|
# perl's handling if input record separators is |
910
|
|
|
|
|
|
|
# not completely simple. |
911
|
805
|
50
|
|
|
|
1783
|
$irs = $$irs if ref $irs; |
912
|
805
|
|
|
|
|
905
|
my $index; |
913
|
805
|
100
|
66
|
|
|
5376
|
if ($irs =~ /^\d/ && int($irs)) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
914
|
15
|
100
|
66
|
|
|
76
|
if ($irs > 0 && length($$ibuf) >= $irs) { |
|
|
50
|
|
|
|
|
|
915
|
12
|
|
|
|
|
24
|
$line = substr($$ibuf, 0, $irs); |
916
|
|
|
|
|
|
|
} elsif ($self->eof2) { |
917
|
0
|
|
|
|
|
0
|
$line = $$ibuf; |
918
|
|
|
|
|
|
|
} |
919
|
|
|
|
|
|
|
} elsif (! defined $irs) { |
920
|
0
|
0
|
|
|
|
0
|
if ($self->eof2) { |
921
|
0
|
|
|
|
|
0
|
$line = $$ibuf; |
922
|
|
|
|
|
|
|
} |
923
|
|
|
|
|
|
|
} elsif ($irs eq '') { |
924
|
|
|
|
|
|
|
# paragraph mode |
925
|
138
|
|
|
|
|
407
|
$$ibuf =~ s/^\n+//; |
926
|
138
|
|
|
|
|
449
|
$irs = "\n\n"; |
927
|
138
|
|
|
|
|
346
|
$index = index($$ibuf, "\n\n"); |
928
|
|
|
|
|
|
|
} else { |
929
|
|
|
|
|
|
|
# multi-character (or just \n) |
930
|
652
|
|
|
|
|
1304
|
$index = index($$ibuf, $irs); |
931
|
|
|
|
|
|
|
} |
932
|
805
|
100
|
|
|
|
1733
|
if (defined $index) { |
933
|
790
|
100
|
|
|
|
3149
|
$line = $index > -1 |
|
|
100
|
|
|
|
|
|
934
|
|
|
|
|
|
|
? substr($$ibuf, 0, $index+length($irs)) |
935
|
|
|
|
|
|
|
: ($self->eof2 ? $$ibuf : undef); |
936
|
|
|
|
|
|
|
} |
937
|
805
|
50
|
|
|
|
2035
|
if ($debug) { |
938
|
58
|
|
|
58
|
|
324
|
no warnings; |
|
58
|
|
|
|
|
100
|
|
|
58
|
|
|
|
|
97168
|
|
939
|
0
|
|
|
|
|
0
|
my $x = $$ibuf; |
940
|
0
|
|
|
|
|
0
|
substr($x, 0, length($line)) = ''; |
941
|
0
|
|
|
|
|
0
|
$x =~ s/\n/\\n/g; |
942
|
0
|
|
|
|
|
0
|
my $y = $irs; |
943
|
0
|
|
|
|
|
0
|
$y =~ s/\n/\\n/g; |
944
|
0
|
0
|
|
|
|
0
|
print "looked for '$y', returning undef, keeping '$x'\n" unless defined $line; |
945
|
0
|
|
|
|
|
0
|
my $z = $line; |
946
|
0
|
|
|
|
|
0
|
$z =~ s/\n/\\n/g; |
947
|
0
|
0
|
|
|
|
0
|
print "looked for '$y', returning '$z', keeping '$x'\n" if defined $line; |
948
|
|
|
|
|
|
|
} |
949
|
805
|
100
|
100
|
|
|
4720
|
return undef unless defined($line) && length($line); |
950
|
623
|
|
|
|
|
1269
|
substr($$ibuf, 0, length($line)) = ''; |
951
|
623
|
|
|
|
|
3980
|
return $line; |
952
|
|
|
|
|
|
|
} |
953
|
|
|
|
|
|
|
|
954
|
|
|
|
|
|
|
# is the following a good idea? |
955
|
|
|
|
|
|
|
#sub tell |
956
|
|
|
|
|
|
|
#{ |
957
|
|
|
|
|
|
|
# my ($self) = @_; |
958
|
|
|
|
|
|
|
# return ${*$self}{ie_fh}->tell() + length(${*$self}{ie_obuf}); |
959
|
|
|
|
|
|
|
#} |
960
|
|
|
|
|
|
|
|
961
|
|
|
|
|
|
|
# from IO::Handle |
962
|
|
|
|
|
|
|
sub getlines |
963
|
|
|
|
|
|
|
{ |
964
|
113
|
|
|
113
|
|
196
|
my $self = shift; |
965
|
113
|
50
|
|
|
|
162
|
return undef unless ${*$self}{ie_autoread}; |
|
113
|
|
|
|
|
485
|
|
966
|
113
|
|
|
|
|
177
|
my $ibuf = \${*$self}{ie_ibuf}; |
|
113
|
|
|
|
|
283
|
|
967
|
|
|
|
|
|
|
#my $ol = length($$ibuf); |
968
|
113
|
100
|
|
|
|
180
|
my $irs = exists ${*$self}{ie_irs} ? ${*$self}{ie_irs} : $/; |
|
113
|
|
|
|
|
379
|
|
|
101
|
|
|
|
|
466
|
|
969
|
113
|
|
|
|
|
249
|
my @lines; |
970
|
113
|
50
|
|
|
|
273
|
if ($debug) { |
971
|
0
|
|
|
|
|
0
|
my $x = $irs; |
972
|
0
|
|
|
|
|
0
|
$x =~ s/\n/\\n/g; |
973
|
0
|
|
|
|
|
0
|
my $fn = $self->fileno; |
974
|
0
|
|
|
|
|
0
|
print "getlines($fn, '$x')\n"; |
975
|
|
|
|
|
|
|
} |
976
|
113
|
100
|
66
|
|
|
802
|
if ($irs =~ /^\d/ && int($irs)) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
977
|
3
|
50
|
|
|
|
20
|
if ($irs > 0) { |
978
|
3
|
|
|
|
|
54
|
@lines = unpack("(a$irs)*", $$ibuf); |
979
|
3
|
|
|
|
|
8
|
$$ibuf = ''; |
980
|
3
|
50
|
33
|
|
|
19
|
$$ibuf = pop(@lines) |
981
|
|
|
|
|
|
|
if length($lines[$#lines]) != $irs && ! $self->eof2; |
982
|
|
|
|
|
|
|
} else { |
983
|
0
|
0
|
|
|
|
0
|
return undef unless $self->eof2; |
984
|
0
|
|
|
|
|
0
|
@lines = $$ibuf; |
985
|
0
|
|
|
|
|
0
|
$$ibuf = ''; |
986
|
|
|
|
|
|
|
} |
987
|
|
|
|
|
|
|
} elsif (! defined $irs) { |
988
|
0
|
0
|
|
|
|
0
|
return undef unless $self->eof2; |
989
|
0
|
|
|
|
|
0
|
@lines = $$ibuf; |
990
|
0
|
|
|
|
|
0
|
$$ibuf = ''; |
991
|
|
|
|
|
|
|
} elsif ($irs eq '') { |
992
|
|
|
|
|
|
|
# paragraphish mode. |
993
|
92
|
|
|
|
|
674
|
$$ibuf =~ s/^\n+//; |
994
|
92
|
|
|
|
|
923
|
@lines = grep($_ ne '', split(/(.*?\n\n)\n*/s, $$ibuf)); |
995
|
92
|
|
|
|
|
410
|
$$ibuf = ''; |
996
|
92
|
100
|
100
|
|
|
1020
|
$$ibuf = pop(@lines) |
|
|
|
100
|
|
|
|
|
997
|
|
|
|
|
|
|
if @lines && substr($lines[$#lines], -2) ne "\n\n" && ! $self->eof2; |
998
|
92
|
50
|
|
|
|
375
|
if ($debug) { |
999
|
0
|
|
|
|
|
0
|
my $x = join('|', @lines); |
1000
|
0
|
|
|
|
|
0
|
$x =~ s/\n/\\n/g; |
1001
|
0
|
|
|
|
|
0
|
my $y = $$ibuf; |
1002
|
0
|
|
|
|
|
0
|
$y =~ s/\n/\\n/g; |
1003
|
0
|
|
|
|
|
0
|
print "getlines returns '$x' but holds onto '$y'\n"; |
1004
|
|
|
|
|
|
|
} |
1005
|
|
|
|
|
|
|
} else { |
1006
|
|
|
|
|
|
|
# multicharacter |
1007
|
18
|
100
|
|
|
|
205
|
$rxcache{$irs} = qr/(.*?\Q$irs\E)/s |
1008
|
|
|
|
|
|
|
unless exists $rxcache{$irs}; |
1009
|
18
|
|
|
|
|
31
|
my $irsrx = $rxcache{$irs}; |
1010
|
18
|
|
|
|
|
222
|
@lines = grep($_ ne '', split(/$rxcache{$irs}/, $$ibuf)); |
1011
|
|
|
|
|
|
|
return undef |
1012
|
18
|
50
|
|
|
|
52
|
unless @lines; |
1013
|
18
|
|
|
|
|
30
|
$$ibuf = ''; |
1014
|
18
|
100
|
100
|
|
|
102
|
$$ibuf = pop(@lines) |
1015
|
|
|
|
|
|
|
if substr($lines[$#lines], 0-length($irs)) ne $irs && ! $self->eof2; |
1016
|
|
|
|
|
|
|
} |
1017
|
113
|
|
|
|
|
577
|
return @lines; |
1018
|
|
|
|
|
|
|
} |
1019
|
|
|
|
|
|
|
|
1020
|
|
|
|
|
|
|
# from IO::Handle |
1021
|
|
|
|
|
|
|
sub ungetc |
1022
|
|
|
|
|
|
|
{ |
1023
|
0
|
|
|
0
|
|
0
|
my ($self, $ord) = @_; |
1024
|
0
|
|
|
|
|
0
|
my $ibuf = \${*$self}{ie_ibuf}; |
|
0
|
|
|
|
|
0
|
|
1025
|
0
|
|
|
|
|
0
|
substr($$ibuf, 0, 0) = chr($ord); |
1026
|
|
|
|
|
|
|
} |
1027
|
|
|
|
|
|
|
|
1028
|
|
|
|
|
|
|
# from FileHandle::Unget & original |
1029
|
|
|
|
|
|
|
sub ungets |
1030
|
|
|
|
|
|
|
{ |
1031
|
12
|
|
|
12
|
|
81
|
my $self = shift; |
1032
|
12
|
|
|
|
|
24
|
substr(${*$self}{ie_ibuf}, 0, 0) |
|
12
|
|
|
|
|
53
|
|
1033
|
|
|
|
|
|
|
= join('', @_); |
1034
|
|
|
|
|
|
|
} |
1035
|
|
|
|
|
|
|
|
1036
|
|
|
|
|
|
|
*xungetc = \&ungets; |
1037
|
|
|
|
|
|
|
*ungetline = \&ungets; |
1038
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
# from IO::Handle |
1040
|
|
|
|
|
|
|
sub getc |
1041
|
|
|
|
|
|
|
{ |
1042
|
54
|
|
|
54
|
|
344
|
my ($self) = @_; |
1043
|
54
|
|
|
|
|
131
|
$self->getsome(1); |
1044
|
|
|
|
|
|
|
} |
1045
|
|
|
|
|
|
|
|
1046
|
|
|
|
|
|
|
# from IO::Handle |
1047
|
|
|
|
|
|
|
sub print |
1048
|
|
|
|
|
|
|
{ |
1049
|
102
|
|
|
102
|
|
14839
|
my ($self, @data) = @_; |
1050
|
102
|
|
|
|
|
575
|
$! = ${*$self}{ie_writeclosed} && return undef |
1051
|
102
|
50
|
0
|
|
|
177
|
if ${*$self}{ie_writeclosed}; |
1052
|
102
|
|
|
|
|
465
|
my $ol; |
1053
|
|
|
|
|
|
|
my $rv; |
1054
|
0
|
|
|
|
|
0
|
my $er; |
1055
|
102
|
|
|
|
|
137
|
my $obuf = \${*$self}{ie_obuf}; |
|
102
|
|
|
|
|
352
|
|
1056
|
102
|
50
|
|
|
|
352
|
if ($ol = length($$obuf)) { |
1057
|
0
|
|
|
|
|
0
|
$$obuf .= join('', @data); |
1058
|
0
|
|
|
|
|
0
|
$rv = length($$obuf) - $ol; |
1059
|
|
|
|
|
|
|
} else { |
1060
|
102
|
|
|
|
|
133
|
my $fh = ${*$self}{ie_fh}; |
|
102
|
|
|
|
|
437
|
|
1061
|
102
|
|
|
|
|
309
|
my $data = join('', @data); |
1062
|
102
|
|
|
|
|
12312
|
$rv = CORE::syswrite($fh, $data); |
1063
|
102
|
50
|
33
|
|
|
1066
|
if (defined($rv) && $rv < length($data)) { |
|
|
50
|
33
|
|
|
|
|
1064
|
0
|
|
|
|
|
0
|
$$obuf = substr($data, $rv, length($data)-$rv); |
1065
|
0
|
|
|
|
|
0
|
$self->writeevents(1); |
1066
|
0
|
|
|
|
|
0
|
$rv = 1; |
1067
|
|
|
|
|
|
|
} elsif ((! defined $rv) && $! == EAGAIN) { |
1068
|
0
|
|
|
|
|
0
|
$$obuf = $data; |
1069
|
0
|
|
|
|
|
0
|
$self->writeevents(1); |
1070
|
0
|
|
|
|
|
0
|
$rv = 1; |
1071
|
|
|
|
|
|
|
} else { |
1072
|
102
|
|
|
|
|
558
|
$er = 0+$!; |
1073
|
|
|
|
|
|
|
} |
1074
|
|
|
|
|
|
|
} |
1075
|
102
|
50
|
|
|
|
226
|
if (length($$obuf) > ${*$self}{ie_obufsize}) { |
|
102
|
50
|
|
|
|
461
|
|
|
102
|
|
|
|
|
415
|
|
1076
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_outputoverflow', 1, $obuf); |
1077
|
0
|
|
|
|
|
0
|
${*$self}{ie_overflowinvoked} = 1; |
|
0
|
|
|
|
|
0
|
|
1078
|
|
|
|
|
|
|
} elsif (${*$self}{ie_overflowinvoked}) { |
1079
|
0
|
|
|
|
|
0
|
$self->ie_invoke(0, 'ie_outputoverflow', 0, $obuf); |
1080
|
0
|
|
|
|
|
0
|
${*$self}{ie_overflowinvoked} = 0; |
|
0
|
|
|
|
|
0
|
|
1081
|
|
|
|
|
|
|
} |
1082
|
102
|
|
|
|
|
517
|
$! = $er; |
1083
|
102
|
|
|
|
|
458
|
return $rv; |
1084
|
|
|
|
|
|
|
} |
1085
|
|
|
|
|
|
|
|
1086
|
|
|
|
|
|
|
# from IO::Handle |
1087
|
|
|
|
|
|
|
sub eof |
1088
|
|
|
|
|
|
|
{ |
1089
|
36
|
|
|
36
|
|
1223
|
my ($self) = @_; |
1090
|
36
|
50
|
|
|
|
48
|
return 0 if length(${*$self}{ie_ibuf}); |
|
36
|
|
|
|
|
175
|
|
1091
|
0
|
0
|
|
|
|
0
|
return 1 if ${*$self}{ie_readclosed}; |
|
0
|
|
|
|
|
0
|
|
1092
|
0
|
|
|
|
|
0
|
return 0; |
1093
|
|
|
|
|
|
|
# return ${*$self}{ie_fh}->eof; |
1094
|
|
|
|
|
|
|
} |
1095
|
|
|
|
|
|
|
|
1096
|
|
|
|
|
|
|
# internal use only. |
1097
|
|
|
|
|
|
|
# just like eof, but we assume the input buffer is empty |
1098
|
|
|
|
|
|
|
sub eof2 |
1099
|
|
|
|
|
|
|
{ |
1100
|
340
|
|
|
340
|
|
826
|
my ($self) = @_; |
1101
|
340
|
50
|
|
|
|
1334
|
if ($debug) { |
1102
|
0
|
|
|
|
|
0
|
my $fn = $self->fileno; |
1103
|
0
|
|
|
|
|
0
|
print "eof2($fn)..."; |
1104
|
0
|
0
|
|
|
|
0
|
print " readclosed" if ${*$self}{ie_readclosed}; |
|
0
|
|
|
|
|
0
|
|
1105
|
|
|
|
|
|
|
#print " EOF" if ${*$self}{ie_fh}->eof; |
1106
|
0
|
|
|
|
|
0
|
my $x = 0; |
1107
|
0
|
0
|
|
|
|
0
|
$x = 1 if ${*$self}{ie_readclosed}; |
|
0
|
|
|
|
|
0
|
|
1108
|
|
|
|
|
|
|
# $x = ${*$self}{ie_fh}->eof unless defined $x; |
1109
|
0
|
|
|
|
|
0
|
print " =$x\n"; |
1110
|
|
|
|
|
|
|
} |
1111
|
340
|
100
|
|
|
|
973
|
return 1 if ${*$self}{ie_readclosed}; |
|
340
|
|
|
|
|
2178
|
|
1112
|
228
|
|
|
|
|
1225
|
return 0; |
1113
|
|
|
|
|
|
|
# return ${*$self}{ie_fh}->eof; |
1114
|
|
|
|
|
|
|
} |
1115
|
|
|
|
|
|
|
|
1116
|
|
|
|
|
|
|
sub fileno |
1117
|
|
|
|
|
|
|
{ |
1118
|
58
|
|
|
58
|
|
76
|
my $self = shift; |
1119
|
58
|
100
|
33
|
|
|
704
|
return undef unless $self && ref($self) && reftype($self) eq 'GLOB'; |
|
|
|
66
|
|
|
|
|
1120
|
57
|
|
|
|
|
391
|
return ${*$self}{ie_fileno} |
|
57
|
|
|
|
|
219
|
|
1121
|
57
|
50
|
|
|
|
74
|
if defined ${*$self}{ie_fileno}; |
1122
|
0
|
0
|
0
|
|
|
0
|
return undef unless ${*$self}{ie_fh} && reftype(${*$self}{ie_fh}) eq 'GLOB'; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
1123
|
0
|
|
|
|
|
0
|
return ${*$self}{ie_fh}->fileno(); |
|
0
|
|
|
|
|
0
|
|
1124
|
|
|
|
|
|
|
} |
1125
|
|
|
|
|
|
|
|
1126
|
|
|
|
|
|
|
sub DESTROY |
1127
|
|
|
|
|
|
|
{ |
1128
|
58
|
|
|
58
|
|
536
|
my $self = shift; |
1129
|
58
|
|
|
|
|
187
|
my $no = $self->fileno; |
1130
|
58
|
100
|
|
|
|
154
|
$no = '?' unless defined $no; |
1131
|
58
|
50
|
|
|
|
136
|
print "DESTROY $no...\n" if $debug; |
1132
|
58
|
100
|
33
|
|
|
703
|
return undef unless $self && ref($self) && reftype($self) eq 'GLOB'; |
|
|
|
66
|
|
|
|
|
1133
|
0
|
|
|
|
|
0
|
${*$self}{ie_event}->cancel |
|
57
|
|
|
|
|
736
|
|
1134
|
57
|
50
|
|
|
|
68
|
if ${*$self}{ie_event}; |
1135
|
|
|
|
|
|
|
} |
1136
|
|
|
|
|
|
|
|
1137
|
|
|
|
|
|
|
|
1138
|
|
|
|
|
|
|
sub TIEHANDLE |
1139
|
|
|
|
|
|
|
{ |
1140
|
543
|
|
|
543
|
|
3176
|
my ($pkg, $self) = @_; |
1141
|
543
|
|
|
|
|
4470
|
return $self; |
1142
|
|
|
|
|
|
|
} |
1143
|
|
|
|
|
|
|
|
1144
|
|
|
|
|
|
|
sub PRINTF |
1145
|
|
|
|
|
|
|
{ |
1146
|
3
|
|
|
3
|
|
395
|
my $self = shift; |
1147
|
3
|
|
|
|
|
21
|
$self->print(sprintf(shift, @_)); |
1148
|
|
|
|
|
|
|
} |
1149
|
|
|
|
|
|
|
|
1150
|
|
|
|
|
|
|
sub READLINE |
1151
|
|
|
|
|
|
|
{ |
1152
|
909
|
|
|
909
|
|
19312295
|
my $self = shift; |
1153
|
909
|
100
|
|
|
|
3979
|
wantarray ? $self->getlines : $self->getline; |
1154
|
|
|
|
|
|
|
} |
1155
|
|
|
|
|
|
|
|
1156
|
|
|
|
|
|
|
sub ie_desc |
1157
|
|
|
|
|
|
|
{ |
1158
|
0
|
|
|
0
|
|
0
|
my ($self, $new) = @_; |
1159
|
0
|
|
0
|
|
|
0
|
my $r = ${*$self}{ie_desc} || "no description"; |
1160
|
0
|
0
|
|
|
|
0
|
${*$self}{ie_desc} = $new if defined $new; |
|
0
|
|
|
|
|
0
|
|
1161
|
0
|
|
|
|
|
0
|
return $r; |
1162
|
|
|
|
|
|
|
} |
1163
|
|
|
|
|
|
|
|
1164
|
58
|
|
|
58
|
|
336
|
no warnings; |
|
58
|
|
|
|
|
120
|
|
|
58
|
|
|
|
|
10029
|
|
1165
|
|
|
|
|
|
|
|
1166
|
|
|
|
|
|
|
*PRINT = \&print; |
1167
|
|
|
|
|
|
|
|
1168
|
|
|
|
|
|
|
*READ = \&sysread; |
1169
|
|
|
|
|
|
|
|
1170
|
|
|
|
|
|
|
# from IO::Handle |
1171
|
|
|
|
|
|
|
*read = \&sysread; |
1172
|
|
|
|
|
|
|
|
1173
|
|
|
|
|
|
|
*WRITE = \&syswrite; |
1174
|
|
|
|
|
|
|
|
1175
|
|
|
|
|
|
|
*CLOSE = \&close; |
1176
|
|
|
|
|
|
|
|
1177
|
|
|
|
|
|
|
*EOF = \&eof; |
1178
|
|
|
|
|
|
|
|
1179
|
|
|
|
|
|
|
*TELL = \&tell; |
1180
|
|
|
|
|
|
|
|
1181
|
|
|
|
|
|
|
*FILENO = \&fileno; |
1182
|
|
|
|
|
|
|
|
1183
|
|
|
|
|
|
|
*SEEK = \&seek; |
1184
|
|
|
|
|
|
|
|
1185
|
|
|
|
|
|
|
*BINMODE = \&binmode; |
1186
|
|
|
|
|
|
|
|
1187
|
|
|
|
|
|
|
*OPEN = \&open; |
1188
|
|
|
|
|
|
|
|
1189
|
|
|
|
|
|
|
*GETC = \&getc; |
1190
|
|
|
|
|
|
|
|
1191
|
58
|
|
|
58
|
|
332
|
use warnings; |
|
58
|
|
|
|
|
84
|
|
|
58
|
|
|
|
|
2683
|
|
1192
|
|
|
|
|
|
|
|
1193
|
|
|
|
|
|
|
}{package IO::Event::Socket::INET; |
1194
|
|
|
|
|
|
|
|
1195
|
|
|
|
|
|
|
# XXX version 1.26 required for IO::Socket::INET |
1196
|
|
|
|
|
|
|
|
1197
|
58
|
|
|
58
|
|
363
|
use strict; |
|
58
|
|
|
|
|
111
|
|
|
58
|
|
|
|
|
2185
|
|
1198
|
58
|
|
|
58
|
|
287
|
use warnings; |
|
58
|
|
|
|
|
134
|
|
|
58
|
|
|
|
|
1720
|
|
1199
|
58
|
|
|
58
|
|
57145
|
use List::MoreUtils qw(any); |
|
58
|
|
|
|
|
70279
|
|
|
58
|
|
|
|
|
28659
|
|
1200
|
|
|
|
|
|
|
|
1201
|
|
|
|
|
|
|
our @ISA = qw(IO::Event); |
1202
|
|
|
|
|
|
|
|
1203
|
|
|
|
|
|
|
sub new |
1204
|
|
|
|
|
|
|
{ |
1205
|
78
|
|
|
78
|
|
1481000
|
my ($pkg, $a, $b, %sock) = @_; |
1206
|
|
|
|
|
|
|
|
1207
|
|
|
|
|
|
|
# emulate behavior in the IO::Socket::INET API |
1208
|
78
|
50
|
33
|
|
|
774
|
if (! %sock && ! $b) { |
1209
|
0
|
|
|
|
|
0
|
$sock{PeerAddr} = $a; |
1210
|
|
|
|
|
|
|
} else { |
1211
|
78
|
|
|
|
|
248
|
$sock{$a} = $b; |
1212
|
|
|
|
|
|
|
} |
1213
|
|
|
|
|
|
|
|
1214
|
78
|
|
33
|
|
|
469
|
my $handler = $sock{Handler} || (caller)[0]; |
1215
|
78
|
|
|
|
|
445
|
delete $sock{Handler}; |
1216
|
|
|
|
|
|
|
|
1217
|
78
|
|
|
|
|
137
|
my $timeout; |
1218
|
78
|
50
|
|
|
|
380
|
if ($sock{Timeout}) { |
1219
|
0
|
|
|
|
|
0
|
$timeout = $sock{Timeout}; |
1220
|
0
|
|
|
|
|
0
|
delete $sock{Timeout}; |
1221
|
|
|
|
|
|
|
} |
1222
|
|
|
|
|
|
|
|
1223
|
78
|
|
|
|
|
185
|
$sock{Blocking} = 0; |
1224
|
|
|
|
|
|
|
|
1225
|
78
|
|
|
|
|
496
|
my (%ds) = %sock; |
1226
|
|
|
|
|
|
|
|
1227
|
78
|
|
|
|
|
205
|
delete $sock{Description}; |
1228
|
|
|
|
|
|
|
|
1229
|
78
|
|
|
|
|
1472
|
require IO::Socket::INET; |
1230
|
78
|
|
|
|
|
832
|
my $fh = new IO::Socket::INET(%sock); |
1231
|
78
|
50
|
|
|
|
36174
|
return undef unless defined $fh; |
1232
|
|
|
|
|
|
|
|
1233
|
78
|
|
|
159
|
|
1056
|
my $peer = any { /Peer/ } keys %sock; |
|
159
|
|
|
|
|
599
|
|
1234
|
78
|
100
|
|
|
|
413
|
if ($peer) { |
1235
|
66
|
50
|
|
|
|
353
|
$ds{LocalPort} = $fh->sockport |
1236
|
|
|
|
|
|
|
unless defined $ds{LocalPort}; |
1237
|
66
|
50
|
|
|
|
2382
|
$ds{LocalHost} = $fh->sockhost |
1238
|
|
|
|
|
|
|
unless defined $ds{LocalHost}; |
1239
|
|
|
|
|
|
|
} |
1240
|
|
|
|
|
|
|
|
1241
|
|
|
|
|
|
|
my $desc = $ds{Description} |
1242
|
|
|
|
|
|
|
|| join(" ", |
1243
|
|
|
|
|
|
|
map { |
1244
|
78
|
|
66
|
|
|
2243
|
defined $ds{$_} |
1245
|
|
|
|
|
|
|
? "$_=$ds{$_}" |
1246
|
|
|
|
|
|
|
: $_ |
1247
|
|
|
|
|
|
|
} sort keys %ds); |
1248
|
|
|
|
|
|
|
|
1249
|
78
|
50
|
|
|
|
219
|
return undef unless $fh; |
1250
|
78
|
|
|
|
|
632
|
my $self = $pkg->SUPER::new($fh, $handler, $desc); |
1251
|
78
|
|
|
|
|
445
|
bless $self, $pkg; |
1252
|
78
|
100
|
|
|
|
395
|
$self->listener(1) |
1253
|
|
|
|
|
|
|
if $sock{Listen}; |
1254
|
78
|
|
|
|
|
255
|
$fh->blocking(0); # XXX may be redundant |
1255
|
78
|
100
|
|
|
|
789
|
if ($peer) { |
1256
|
66
|
50
|
|
|
|
328
|
if ($fh->connected()) { |
1257
|
66
|
|
|
|
|
5529
|
$self->ie_invoke(0, 'ie_connected'); |
1258
|
|
|
|
|
|
|
} else { |
1259
|
0
|
|
|
|
|
0
|
${*$self}{ie_connecting} = 1; |
|
0
|
|
|
|
|
0
|
|
1260
|
0
|
|
|
|
|
0
|
$self->writeevents(1); |
1261
|
0
|
0
|
|
|
|
0
|
${*$self}{ie_connect_timeout} = $timeout + time |
|
0
|
|
|
|
|
0
|
|
1262
|
|
|
|
|
|
|
if $timeout; |
1263
|
|
|
|
|
|
|
} |
1264
|
|
|
|
|
|
|
} |
1265
|
78
|
50
|
|
|
|
225
|
${*$self}{ie_socket_timeout} = $timeout |
|
0
|
|
|
|
|
0
|
|
1266
|
|
|
|
|
|
|
if $timeout; |
1267
|
|
|
|
|
|
|
|
1268
|
78
|
|
|
|
|
456
|
return $self; |
1269
|
|
|
|
|
|
|
} |
1270
|
|
|
|
|
|
|
|
1271
|
|
|
|
|
|
|
}{ |
1272
|
|
|
|
|
|
|
package IO::Event::Socket::UNIX; |
1273
|
|
|
|
|
|
|
|
1274
|
58
|
|
|
58
|
|
336
|
use strict; |
|
58
|
|
|
|
|
128
|
|
|
58
|
|
|
|
|
1911
|
|
1275
|
58
|
|
|
58
|
|
271
|
use warnings; |
|
58
|
|
|
|
|
80
|
|
|
58
|
|
|
|
|
18736
|
|
1276
|
|
|
|
|
|
|
|
1277
|
|
|
|
|
|
|
our @ISA = qw(IO::Event); |
1278
|
|
|
|
|
|
|
|
1279
|
|
|
|
|
|
|
sub new |
1280
|
|
|
|
|
|
|
{ |
1281
|
0
|
|
|
0
|
|
|
my ($pkg, $a, $b, %sock) = @_; |
1282
|
|
|
|
|
|
|
|
1283
|
|
|
|
|
|
|
# emulate behavior in the IO::Socket::INET API |
1284
|
0
|
0
|
0
|
|
|
|
if (! %sock && ! $b) { |
1285
|
0
|
|
|
|
|
|
$sock{Peer} = $a; |
1286
|
|
|
|
|
|
|
} else { |
1287
|
0
|
|
|
|
|
|
$sock{$a} = $b; |
1288
|
|
|
|
|
|
|
} |
1289
|
|
|
|
|
|
|
|
1290
|
0
|
|
0
|
|
|
|
my $handler = $sock{Handler} || (caller)[0]; |
1291
|
0
|
|
|
|
|
|
delete $sock{Handler}; |
1292
|
|
|
|
|
|
|
|
1293
|
|
|
|
|
|
|
my $desc = $sock{Description} |
1294
|
0
|
|
0
|
|
|
|
|| join(" ", map { "$_=$sock{$_}" } sort keys %sock); |
1295
|
0
|
|
|
|
|
|
delete $sock{Description}; |
1296
|
|
|
|
|
|
|
|
1297
|
0
|
|
|
|
|
|
require IO::Socket::UNIX; |
1298
|
0
|
|
|
|
|
|
my $fh = new IO::Socket::UNIX(%sock); |
1299
|
|
|
|
|
|
|
|
1300
|
0
|
0
|
|
|
|
|
return undef unless $fh; |
1301
|
0
|
|
|
|
|
|
my $self = $pkg->SUPER::new($fh, $handler, $desc); |
1302
|
0
|
|
|
|
|
|
bless $self, $pkg; |
1303
|
0
|
0
|
|
|
|
|
$self->listener(1) |
1304
|
|
|
|
|
|
|
if $sock{Listen}; |
1305
|
0
|
|
|
|
|
|
$fh->blocking(0); |
1306
|
0
|
0
|
|
|
|
|
if ($sock{Peer}) { |
1307
|
0
|
0
|
|
|
|
|
if ($fh->connected()) { |
1308
|
0
|
|
|
|
|
|
$self->ie_invoke(0, 'ie_connected'); |
1309
|
|
|
|
|
|
|
} else { |
1310
|
0
|
|
|
|
|
|
${*$self}{ie_connecting} = 1; |
|
0
|
|
|
|
|
|
|
1311
|
0
|
|
|
|
|
|
$self->writeevents(1); |
1312
|
|
|
|
|
|
|
} |
1313
|
|
|
|
|
|
|
} |
1314
|
|
|
|
|
|
|
|
1315
|
0
|
|
|
|
|
|
return $self; |
1316
|
|
|
|
|
|
|
} |
1317
|
|
|
|
|
|
|
|
1318
|
|
|
|
|
|
|
}#end package |
1319
|
|
|
|
|
|
|
1; |
1320
|
|
|
|
|
|
|
|