1#!perl -w 2 3use strict; 4use Net::SSLeay; 5use Socket; 6use IO::Socket::SSL; 7 8if ( grep { $^O =~m{$_} } qw( MacOS VOS vmesa riscos amigaos ) ) { 9 print "1..0 # Skipped: fork not implemented on this platform\n"; 10 exit 11} 12 13if ( $^O =~m{mswin32}i ) { 14 print "1..0 # Skipped: signals not relevant on this platform\n"; 15 exit 16} 17 18use vars qw( $SSL_SERVER_ADDR ); 19do "t/ssl_settings.req" || do "ssl_settings.req"; 20 21print "1..9\n"; 22 23my $server = IO::Socket::SSL->new( 24 LocalAddr => $SSL_SERVER_ADDR, 25 Listen => 2, 26 ReuseAddr => 1, 27 SSL_server => 1, 28 SSL_ca_file => "certs/test-ca.pem", 29 SSL_cert_file => "certs/server-wildcard.pem", 30 SSL_key_file => "certs/server-wildcard.pem", 31); 32warn "\$!=$!, \$\@=$@, S\$SSL_ERROR=$SSL_ERROR" if ! $server; 33print "not ok\n", exit if !$server; 34ok("Server Initialization"); 35my $SSL_SERVER_PORT = $server->sockport; 36 37defined( my $pid = fork() ) || die $!; 38if ( $pid == 0 ) { 39 40 $SIG{HUP} = sub { ok("got hup") }; 41 42 close($server); 43 my $client = IO::Socket::SSL->new( "$SSL_SERVER_ADDR:$SSL_SERVER_PORT" ) 44 || print "not "; 45 ok( "client ssl connect" ); 46 47 my $line = <$client>; 48 print "not " if $line ne "foobar\n"; 49 ok("got line"); 50 51 exit; 52} 53 54my $csock = $server->accept; 55ok("accept"); 56$SIG{PIPE} = 'IGNORE'; 57 58syswrite($csock,"foo") or print "not "; 59ok("wrote foo"); 60sleep(1); 61 62kill HUP => $pid or print "not "; 63ok("send hup"); 64sleep(1); 65 66syswrite($csock,"bar\n") or print "not "; 67ok("wrote bar\\n"); 68 69wait; 70ok("wait: $?"); 71 72 73 74sub ok { print "ok #$_[0]\n"; } 75 76