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   10 use strict;
  2         3  
  2         78  
3 2     2   12 use warnings;
  2         4  
  2         65  
4 2     2   10 use Protocol::TLS::Trace qw(tracer bin2hex);
  2         4  
  2         622  
5              
6             sub new {
7 4     4 0 28 my ( $class, $ctx ) = @_;
8 4         41 bless {
9             input => '',
10             ctx => $ctx,
11             }, $class;
12             }
13              
14             sub next_record {
15 34     34 0 2910 my $self = shift;
16 34         117 my $record = $self->{ctx}->dequeue;
17 34 100       136 tracer->debug( sprintf "send one record of %i bytes to wire\n",
18             length($record) )
19             if $record;
20 34         67 return $record;
21             }
22              
23             sub feed {
24 15     15 0 173488 my ( $self, $chunk ) = @_;
25 15         60 $self->{input} .= $chunk;
26 15         95 my $offset = 0;
27 15         32 my $len;
28 15         30 my $ctx = $self->{ctx};
29 15         52 tracer->debug( "got " . length($chunk) . " bytes on a wire\n" );
30 15         98 while ( $len = $ctx->record_decode( \$self->{input}, $offset ) ) {
31 20         52 tracer->debug("decoded record at $offset, length $len\n");
32 20         63 $offset += $len;
33             }
34 15 50       102 substr( $self->{input}, 0, $offset ) = '' if $offset;
35             }
36              
37             sub shutdown {
38 14     14 0 97 shift->{ctx}->shutdown;
39             }
40              
41             1