Add the original source packages to maemo, source lenny
[dh-make-perl] / dev / i386 / libio-socket-ssl-perl / libio-socket-ssl-perl-1.16 / t / connectSSL-timeout.t
1 use strict;
2 use warnings;
3 do './testlib.pl' || do './t/testlib.pl' || die "no testlib";
4
5 $|=1;
6 print "1..15\n";
7
8 my ($server,$saddr) = create_listen_socket();
9 ok( 'listening' );
10
11 # first try bad non-SSL client
12 my $srv = fork_sub( 'server' );
13 fd_grep_ok( 'Waiting', $srv );
14 my $cl = fork_sub( 'client' );
15 fd_grep_ok( 'Connect from',$srv );
16 fd_grep_ok( 'Connected', $cl );
17 fd_grep_ok( 'SSL Handshake FAILED', $cl );
18 killall();
19
20 # then use SSL client
21 $srv = fork_sub( 'server','ssl' );
22 fd_grep_ok( 'Waiting', $srv );
23 $cl = fork_sub( 'client' );
24 fd_grep_ok( 'Connect from',$srv );
25 fd_grep_ok( 'Connected', $cl );
26 fd_grep_ok( 'SSL Handshake OK', $srv );
27 fd_grep_ok( 'SSL Handshake OK', $cl );
28 fd_grep_ok( 'Hi!', $cl );
29 killall();
30
31
32 sub server {
33         my $behavior = shift || 'nossl';
34         print "Waiting\n";
35         my $client = $server->accept || die "accept failed: $!";
36         print "Connect from ".$client->peerhost.':'.$client->peerport."\n";
37         if ( $behavior eq 'ssl' ) {
38                 if ( IO::Socket::SSL->start_SSL( $client, SSL_server => 1, Timeout => 30 )) {
39                         print "SSL Handshake OK\n";
40                         print $client "Hi!\n";
41                 }
42         } else {
43                 while ( sysread( $client, my $buf,8000 )) {}
44         }
45 }
46
47 sub client {
48         my $c = IO::Socket::INET->new( $saddr ) || die "connect failed: $!";
49         print "Connected\n";
50         if ( IO::Socket::SSL->start_SSL( $c, Timeout => 5 )) {
51                  print "SSL Handshake OK\n";
52                  print <$c>
53         } else {
54                 print "SSL Handshake FAILED - $!\n";
55         }
56 }
57
58