1 #!/usr/local/bin/perl -w
2 # bio.pl mikem@open.com.au
4 # Test and demonstrate BIO interface
6 use Net::SSLeay qw(die_now);
8 $data = '0123456789' x 100;
11 $b = &Net::SSLeay::BIO_new(&Net::SSLeay::BIO_s_mem())
12 or die_now("Could not create memory BIO $!");
14 &Net::SSLeay::BIO_write($b, $data)
15 or die_now("Could not write memory BIO $!");
17 # Should now have 1000 bytes in BIO
18 $pending = &Net::SSLeay::BIO_pending($b);
19 die("Incorrect result from BIO_pending: $pending. Should be $len")
20 unless $pending == $len;
22 # Partial read of 9 bytes
24 $part = &Net::SSLeay::BIO_read($b, $len);
25 $nlen = length($part);
26 die("Incorrect result from BIO_read: $len. Should be 9")
29 die("Incorrect data from BIO_read: $len. Should be 012345678")
30 unless $part eq '012345678';
32 # Should be 991 bytes left
34 $pending = &Net::SSLeay::BIO_pending($b);
35 die("Incorrect result from BIO_pending: $pending. Should be $len")
36 unless $pending == $len;
39 $part = &Net::SSLeay::BIO_read($b);
40 $nlen = length($part);
41 die("Incorrect result from BIO_read: $len. Should be 991")
44 &Net::SSLeay::BIO_free($b);