line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::PocketIO::Client::Transport::WebSocket; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
30
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
299
|
|
4
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
295
|
|
5
|
5
|
|
|
5
|
|
27
|
use Carp (); |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
75
|
|
6
|
5
|
|
|
5
|
|
24
|
use AnyEvent; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
141
|
|
7
|
5
|
|
|
5
|
|
24
|
use AnyEvent::Handle; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
121
|
|
8
|
5
|
|
|
5
|
|
27
|
use Protocol::WebSocket::Frame; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
254
|
|
9
|
5
|
|
|
5
|
|
5013
|
use Protocol::WebSocket::Handshake::Client; |
|
5
|
|
|
|
|
5977
|
|
|
5
|
|
|
|
|
143
|
|
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
31
|
use base 'AnyEvent::PocketIO::Client'; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
3826
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
7
|
|
|
7
|
1
|
16
|
my $class = shift; |
17
|
7
|
|
|
|
|
211
|
bless { @_ }, $class; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
0
|
0
|
sub id { 'websocket'; } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub open { |
24
|
7
|
|
|
7
|
1
|
29
|
my ( $self, $client, $fh, $host, $port, $sid, $cb ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
|
|
86
|
my $hs = Protocol::WebSocket::Handshake::Client->new(url => |
27
|
|
|
|
|
|
|
"ws://$host:$port/socket.io/1/websocket/$sid"); |
28
|
7
|
|
|
|
|
3047
|
my $frame = Protocol::WebSocket::Frame->new( version => $hs->version ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$client->handle->write( $hs->to_string => sub { |
31
|
7
|
|
|
7
|
|
3009
|
my ( $handle ) = shift; |
32
|
7
|
|
|
|
|
39
|
my $conn = $client->conn; |
33
|
|
|
|
|
|
|
|
34
|
7
|
|
|
|
|
34
|
my $close_cb = sub { $handle->close; }; |
|
0
|
|
|
|
|
0
|
|
35
|
|
|
|
|
|
|
|
36
|
7
|
|
|
|
|
64
|
$handle->on_eof( $close_cb ); |
37
|
7
|
|
|
|
|
168
|
$handle->on_error( $close_cb ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$handle->on_heartbeat( sub { |
40
|
0
|
|
|
|
|
0
|
$conn->send_heartbeat; |
41
|
0
|
|
|
|
|
0
|
$client->on('heartbeat')->(); |
42
|
7
|
|
|
|
|
4379
|
} ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$handle->on_read( sub { |
45
|
16
|
100
|
|
|
|
55123
|
unless ( $client->is_opened ) { |
46
|
6
|
|
|
|
|
42
|
$client->opened; |
47
|
6
|
100
|
|
|
|
62
|
$client->_run_open_cb( $cb ) if $cb; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
16
|
100
|
|
|
|
196
|
unless ($hs->is_done) { |
51
|
6
|
|
|
|
|
530
|
$hs->parse( $_[1] ); |
52
|
6
|
|
|
|
|
2610
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
10
|
|
|
|
|
254
|
$frame->append( $_[1] ); |
55
|
|
|
|
|
|
|
|
56
|
10
|
|
|
|
|
168
|
while ( my $message = $frame->next_bytes ) { |
57
|
11
|
|
|
|
|
2699
|
$conn->parse_message( $message ); |
58
|
|
|
|
|
|
|
} |
59
|
7
|
|
|
|
|
428
|
} ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$conn->on( |
62
|
|
|
|
|
|
|
close => sub { |
63
|
4
|
|
|
|
|
583
|
$handle->close; |
64
|
4
|
|
|
|
|
715
|
$client->on('close')->(); |
65
|
|
|
|
|
|
|
} |
66
|
7
|
|
|
|
|
304
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$conn->on( |
69
|
|
|
|
|
|
|
write => sub { |
70
|
11
|
|
|
|
|
5521
|
my $bytes = $self->_build_frame( |
71
|
|
|
|
|
|
|
buffer => $_[1], version => $hs->version, |
72
|
|
|
|
|
|
|
); |
73
|
11
|
|
|
|
|
1036
|
$handle->write( $bytes ); |
74
|
|
|
|
|
|
|
}, |
75
|
7
|
|
|
|
|
104
|
); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$conn->socket->on('message' => sub { |
78
|
5
|
|
|
|
|
1295
|
$client->on('message')->( $conn->socket, $_[1] ); |
79
|
7
|
|
|
|
|
101
|
}); |
80
|
|
|
|
|
|
|
|
81
|
7
|
|
|
|
|
827
|
}); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _build_frame { |
86
|
11
|
|
|
11
|
|
224
|
my $self = shift; |
87
|
11
|
|
|
|
|
90
|
return Protocol::WebSocket::Frame->new( @_ )->to_bytes; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|