line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PocketIO::Handle; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
37
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
239
|
|
4
|
6
|
|
|
6
|
|
37
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
168
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
8464
|
use AnyEvent::Handle; |
|
6
|
|
|
|
|
109978
|
|
|
6
|
|
|
|
|
308
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
77
|
use constant DEBUG => $ENV{POCKETIO_HANDLE_DEBUG}; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
7738
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
12
|
0
|
|
|
|
|
|
my (%params) = @_; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
my $fh = delete $params{fh}; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $self = {handle => AnyEvent::Handle->new(fh => $fh), %params}; |
17
|
0
|
|
|
|
|
|
bless $self, $class; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
0
|
|
|
|
$self->{heartbeat_timeout} ||= 10; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$fh->autoflush; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$self->{handle}->no_delay(1); |
24
|
0
|
|
|
0
|
|
|
$self->{handle}->on_eof(sub { warn "Unhandled handle eof" }); |
|
0
|
|
|
|
|
|
|
25
|
0
|
|
|
0
|
|
|
$self->{handle}->on_error(sub { warn "Unhandled handle error: $_[2]" }); |
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# This is needed for the correct EOF handling |
28
|
0
|
|
|
0
|
|
|
$self->{handle}->on_read(sub { }); |
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return $self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
1
|
|
sub fh { $_[0]->{handle}->fh } |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub on_heartbeat { |
36
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
37
|
0
|
|
|
|
|
|
my ($cb) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$self->{handle}->wtimeout($self->{heartbeat_timeout}); |
40
|
0
|
|
|
|
|
|
$self->{handle}->on_wtimeout($cb); |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub on_read { |
46
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
47
|
0
|
|
|
|
|
|
my ($cb) = @_; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$self->{handle}->on_read( |
50
|
|
|
|
|
|
|
sub { |
51
|
0
|
|
|
0
|
|
|
my $handle = shift; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$handle->push_read( |
54
|
|
|
|
|
|
|
sub { |
55
|
0
|
|
|
|
|
|
$cb->($self, $_[0]->rbuf); |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub on_eof { |
65
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
66
|
0
|
|
|
|
|
|
my ($cb) = @_; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$self->{handle}->on_eof( |
69
|
|
|
|
|
|
|
sub { |
70
|
0
|
|
|
0
|
|
|
$cb->($self); |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return $self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub on_error { |
78
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
79
|
0
|
|
|
|
|
|
my ($cb) = @_; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->{handle}->on_error( |
82
|
|
|
|
|
|
|
sub { |
83
|
0
|
|
|
0
|
|
|
$cb->($self); |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $self; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub write { |
91
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
92
|
0
|
|
|
|
|
|
my ($chunk, $cb) = @_; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $handle = $self->{handle}; |
95
|
0
|
0
|
0
|
|
|
|
return $self unless $handle && $handle->fh; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$handle->push_write($chunk); |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
if ($cb) { |
100
|
|
|
|
|
|
|
$handle->on_drain( |
101
|
|
|
|
|
|
|
sub { |
102
|
0
|
|
|
0
|
|
|
my $handle = shift; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$handle->on_drain(undef); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$cb->($self); |
107
|
|
|
|
|
|
|
} |
108
|
0
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $self; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub close { |
115
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $handle = delete $self->{handle}; |
118
|
0
|
0
|
|
|
|
|
return $self unless $handle; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$handle->wtimeout(0); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$handle->on_drain; |
123
|
0
|
|
|
|
|
|
$handle->on_error; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$handle->on_drain( |
126
|
|
|
|
|
|
|
sub { |
127
|
0
|
0
|
|
0
|
|
|
if ($_[0]->fh) { |
128
|
0
|
|
|
|
|
|
shutdown $_[0]->fh, 1; |
129
|
0
|
|
|
|
|
|
close $handle->fh; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
$_[0]->destroy; |
133
|
0
|
|
|
|
|
|
undef $handle; |
134
|
|
|
|
|
|
|
} |
135
|
0
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return $self; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
141
|
|
|
|
|
|
|
__END__ |