line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PocketIO::Test; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
163524
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
132
|
|
4
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
98
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
8918
|
use AnyEvent; |
|
4
|
|
|
|
|
80168
|
|
|
4
|
|
|
|
|
144
|
|
7
|
4
|
|
|
4
|
|
5215
|
use AnyEvent::Socket; |
|
4
|
|
|
|
|
223577
|
|
|
4
|
|
|
|
|
672
|
|
8
|
4
|
|
|
4
|
|
5376
|
use Test::TCP; |
|
4
|
|
|
|
|
554826
|
|
|
4
|
|
|
|
|
286
|
|
9
|
4
|
|
|
4
|
|
14334
|
use Plack::Loader; |
|
4
|
|
|
|
|
35663
|
|
|
4
|
|
|
|
|
213
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
46
|
use parent qw(Exporter); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
39
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw(test_pocketio http_get_session_id); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub test_pocketio { |
15
|
4
|
|
|
4
|
1
|
792
|
my ($app, $client) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
test_tcp( |
18
|
|
|
|
|
|
|
client => $client, |
19
|
|
|
|
|
|
|
server => sub { |
20
|
0
|
|
|
0
|
|
0
|
my $port = shift; |
21
|
0
|
|
|
|
|
0
|
my $server = Plack::Loader->load( |
22
|
|
|
|
|
|
|
'Twiggy', |
23
|
|
|
|
|
|
|
port => $port, |
24
|
|
|
|
|
|
|
host => ('127.0.0.1') |
25
|
|
|
|
|
|
|
); |
26
|
0
|
|
|
|
|
0
|
$server->run($app); |
27
|
|
|
|
|
|
|
}, |
28
|
4
|
|
|
|
|
46
|
); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub http_get_session_id { |
32
|
4
|
|
|
4
|
1
|
500221
|
my $server = shift; |
33
|
4
|
|
|
|
|
30
|
my $port = shift; |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
130
|
my $cv = AnyEvent->condvar; |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
7309
|
my $session_id; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
90
|
$cv->begin; |
40
|
|
|
|
|
|
|
tcp_connect $server, $port, sub { |
41
|
4
|
50
|
|
4
|
|
1926
|
my ($fh) = @_ or return $cv->send; |
42
|
|
|
|
|
|
|
|
43
|
4
|
|
|
|
|
213
|
syswrite $fh, <<"EOF"; |
44
|
|
|
|
|
|
|
GET /socket.io/1/ HTTP/1.1 |
45
|
|
|
|
|
|
|
Host: $server:$port |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
EOF |
48
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
24
|
my $buffer = ''; |
50
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
12
|
my $read_watcher; |
52
|
|
|
|
|
|
|
$read_watcher = AnyEvent->io( |
53
|
|
|
|
|
|
|
fh => $fh, |
54
|
|
|
|
|
|
|
poll => "r", |
55
|
|
|
|
|
|
|
cb => sub { |
56
|
8
|
|
|
|
|
25995
|
my $len = sysread $fh, my $chunk, 1024, 0; |
57
|
|
|
|
|
|
|
|
58
|
8
|
|
|
|
|
43
|
$buffer .= $chunk; |
59
|
|
|
|
|
|
|
|
60
|
8
|
100
|
|
|
|
54
|
if ($len <= 0) { |
61
|
4
|
|
|
|
|
78
|
($session_id) = $buffer =~ m/\r?\n(\d+):/; |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
32
|
undef $read_watcher; |
64
|
4
|
|
|
|
|
33
|
return $cv->end; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
4
|
|
|
|
|
125
|
); |
68
|
4
|
|
|
|
|
695
|
}; |
69
|
|
|
|
|
|
|
|
70
|
4
|
|
|
|
|
3720
|
$cv->wait; |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
912
|
return $session_id; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
__END__ |