File Coverage

blib/lib/Protocol/TLS/Connection.pm
Criterion Covered Total %
statement 26 26 100.0
branch 3 4 75.0
condition n/a
subroutine 7 7 100.0
pod 0 4 0.0
total 36 41 87.8


line stmt bran cond sub pod time code
1             package Protocol::TLS::Connection;
2 2     2   13 use strict;
  2         4  
  2         62  
3 2     2   10 use warnings;
  2         5  
  2         63  
4 2     2   12 use Protocol::TLS::Trace qw(tracer bin2hex);
  2         3  
  2         646  
5              
6             sub new {
7 4     4 0 9 my ( $class, $ctx ) = @_;
8 4         61 bless {
9             input => '',
10             ctx => $ctx,
11             }, $class;
12             }
13              
14             sub next_record {
15 34     34 0 2061 my $self = shift;
16 34         150 my $record = $self->{ctx}->dequeue;
17 34 100       132 tracer->debug( sprintf "send one record of %i bytes to wire\n",
18             length($record) )
19             if $record;
20 34         114 return $record;
21             }
22              
23             sub feed {
24 15     15 0 184996 my ( $self, $chunk ) = @_;
25 15         88 $self->{input} .= $chunk;
26 15         34 my $offset = 0;
27 15         34 my $len;
28 15         41 my $ctx = $self->{ctx};
29 15         80 tracer->debug( "got " . length($chunk) . " bytes on a wire\n" );
30 15         131 while ( $len = $ctx->record_decode( \$self->{input}, $offset ) ) {
31 20         73 tracer->debug("decoded record at $offset, length $len\n");
32 20         105 $offset += $len;
33             }
34 15 50       146 substr( $self->{input}, 0, $offset ) = '' if $offset;
35             }
36              
37             sub shutdown {
38 14     14 0 174 shift->{ctx}->shutdown;
39             }
40              
41             1