File: acceptSSL-timeout.t

package info (click to toggle)
libio-socket-ssl-perl 1.16-1%2Blenny1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 352 kB
  • ctags: 102
  • sloc: perl: 2,817; makefile: 16
file content (55 lines) | stat: -rw-r--r-- 1,360 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use strict;
use warnings;
do './testlib.pl' || do './t/testlib.pl' || die "no testlib";

$|=1;
print "1..14\n";

my ($server,$saddr) = create_listen_socket();
ok( 'listening' );

# first try bad non-SSL client
my $srv = fork_sub( 'server' );
fd_grep_ok( 'Waiting', $srv );
my $cl = fork_sub( 'client_no_ssl' );
fd_grep_ok( 'Connect from',$srv );
fd_grep_ok( 'Connected', $cl );
fd_grep_ok( 'SSL Handshake FAILED', $srv );
killall();

# then use SSL client
$srv = fork_sub( 'server' );
fd_grep_ok( 'Waiting', $srv );
$cl = fork_sub( 'client_ssl' );
fd_grep_ok( 'Connect from',$srv );
fd_grep_ok( 'Connected', $cl );
fd_grep_ok( 'SSL Handshake OK', $srv );
fd_grep_ok( 'Hi!', $cl );
killall();


sub server {
	print "Waiting\n";
	my $client = $server->accept || die "accept failed: $!";
	print "Connect from ".$client->peerhost.':'.$client->peerport."\n";
	if ( IO::Socket::SSL->start_SSL( $client, SSL_server => 1, Timeout => 5 )) {
		print "SSL Handshake OK\n";
		print $client "Hi!\n";
	} else {
		print "SSL Handshake FAILED - $!\n"
	}
}

sub client_no_ssl {
	my $c = IO::Socket::INET->new( $saddr ) || die "connect failed: $!";
	print "Connected\n";
	while ( sysread( $c,my $buf,8000 )) {}
}

sub client_ssl {
	my $c = IO::Socket::SSL->new( $saddr ) || die "connect failed: $!";
	print "Connected\n";
	while ( sysread( $c,my $buf,8000 )) { print $buf }
}