line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::HTTP2::Client::Connection::AnyEvent; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=encoding utf-8 |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Net::HTTP2::Client::Connection::AnyEvent |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $cv = AnyEvent->condvar(); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $h2 = Net::HTTP2::Client::Connection::AnyEvent->new("perl.org"); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$h2->request("GET", "/")->then( |
19
|
|
|
|
|
|
|
sub ($resp) { |
20
|
|
|
|
|
|
|
print $resp->content(); |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
)->finally($cv); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$cv->recv(); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This class extends L to work with L. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
It requires that L support ALPN. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
4
|
use parent 'Net::HTTP2::Client::Connection'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
484
|
use AnyEvent::TLS (); |
|
1
|
|
|
|
|
17692
|
|
|
1
|
|
|
|
|
19
|
|
39
|
1
|
|
|
1
|
|
529
|
use AnyEvent::Handle (); |
|
1
|
|
|
|
|
5770
|
|
|
1
|
|
|
|
|
32
|
|
40
|
1
|
|
|
1
|
|
5
|
use Net::SSLeay (); |
|
1
|
|
|
|
|
23
|
|
|
1
|
|
|
|
|
18
|
|
41
|
1
|
|
|
1
|
|
4
|
use Scalar::Util (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
221
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# perl -I ../p5-X-Tiny/lib -MData::Dumper -MAnyEvent -I ../p5-IO-SigGuard/lib -I ../p5-Promise-ES6/lib -Ilib -MNet::HTTP2::Client::Connection::AnyEvent -e'my $h2 = Net::HTTP2::Client::Connection::AnyEvent->new("google.com"); my $cv = AnyEvent->condvar(); $h2->request("GET", "/")->then( sub { print Dumper shift } )->finally($cv); $cv->recv();' |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _start_io_if_needed { |
46
|
2
|
|
|
2
|
|
5
|
my ($self, $host, $port, $h2) = @_; |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
33
|
|
|
7
|
$self->{'ae_handle'} ||= do { |
49
|
2
|
|
|
|
|
2
|
my @tls_opts; |
50
|
|
|
|
|
|
|
|
51
|
2
|
50
|
|
|
|
5
|
if ($self->{'tls_verify_yn'}) { |
52
|
0
|
|
|
|
|
0
|
push @tls_opts, ( |
53
|
|
|
|
|
|
|
verify => 1, |
54
|
|
|
|
|
|
|
verify_peername => 'https', |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
12
|
my $tls = AnyEvent::TLS->new(@tls_opts); |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
2630
|
Net::SSLeay::CTX_set_alpn_protos($tls->ctx(), $self->_ALPN_PROTOS()); |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
23
|
my $weak_self = $self; |
63
|
2
|
|
|
|
|
8
|
Scalar::Util::weaken($weak_self); |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
2
|
my $read_chunk; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
AnyEvent::Handle->new( |
68
|
|
|
|
|
|
|
connect => [$host, $port], |
69
|
|
|
|
|
|
|
tls => 'connect', |
70
|
|
|
|
|
|
|
tls_ctx => $tls, |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
on_error => sub { |
73
|
0
|
|
|
0
|
|
0
|
my ($handle, $fatal, $msg) = @_; |
74
|
0
|
|
|
|
|
0
|
$weak_self->_on_stream_error($msg); |
75
|
0
|
|
|
|
|
0
|
$handle->destroy(); |
76
|
|
|
|
|
|
|
}, |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
on_eof => sub { |
79
|
0
|
0
|
|
0
|
|
0
|
$weak_self->_on_stream_close() if $weak_self; |
80
|
0
|
|
|
|
|
0
|
shift()->destroy(); |
81
|
|
|
|
|
|
|
}, |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
on_read => sub { |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# NB: This doesn’t empty out rbuf in pre-5.16 perls: |
86
|
|
|
|
|
|
|
# substr( $_[0]->rbuf, 0, length($_[0]->rbuf), q<> ) |
87
|
48
|
|
|
48
|
|
231009
|
$read_chunk = $_[0]->rbuf(); |
88
|
48
|
|
|
|
|
169
|
$_[0]->rbuf() = q<>; |
89
|
|
|
|
|
|
|
|
90
|
48
|
|
|
|
|
218
|
$h2->feed($read_chunk); |
91
|
|
|
|
|
|
|
}, |
92
|
2
|
|
|
|
|
22
|
); |
93
|
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _write_frame { |
97
|
12
|
|
|
12
|
|
26
|
$_[0]{'ae_handle'}->push_write($_[1]); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |