script/simple_keepalive.pl untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 48 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use lib '../lib';
5 use LightTCP::SSLclient;
6  
7 my $client = LightTCP::SSLclient->new(
8 timeout => 30,
9 keep_alive => 1,
10 );
11  
12 my ($ok, $errors, $debug, $code) = $client->connect('reqbin.com', 443);
13  
14 unless ($ok) {
15 die "Connect failed: @$errors";
16 }
17  
18 print "Connected. Making 3 requests on same connection...\n";
19 print "Keep-alive: " . ($client->is_keep_alive() ? "enabled" : "disabled") . "\n\n";
20  
21 for my $i (1 .. 3) {
22 my ($req_ok, $req_errors, $req_debug, $req_code)
23 = $client->request('GET', "/echo?id=$i", host => 'reqbin.com');
24  
25 unless ($req_ok) {
26 warn "Request $i failed: @$req_errors";
27 next;
28 }
29  
30 my ($status, $state, $headers, $body, $resp_errors, $resp_debug, $resp_code)
31 = $client->response();
32  
33 if (defined $status && $status =~ /^\d+$/) {
34 print "Request $i: $status $state (Connection: $headers->{'connection'})\n";
35 } else {
36 print "Request $i: Response error\n";
37 }
38 }
39  
40 print "\nConnection still alive: " . ($client->is_connected() ? "yes" : "no") . "\n";
41  
42 $client->close();