File: 06_tcpecho.t

package info (click to toggle)
libnet-ssleay-perl 1.36-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 940 kB
  • ctags: 798
  • sloc: perl: 3,668; ansic: 2,711; makefile: 7
file content (61 lines) | stat: -rw-r--r-- 1,219 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
56
57
58
59
60
61
#!/usr/bin/perl

use strict;
use warnings;
use Test::More tests => 4;
use Socket;
use Symbol qw(gensym);
use Net::SSLeay;

my $sock;
my $pid;

my $port = 1211;
my $msg = 'ssleay-tcp-test';

{
    my $ip = "\x7F\0\0\x01";
    my $serv_params = sockaddr_in($port, $ip);
    $sock = gensym();
    socket($sock, AF_INET, SOCK_STREAM, 0) or die;
    bind($sock, $serv_params) or die;
    listen($sock, 2) or die;
}

{
    $pid = fork();
    die unless defined $pid;
    if ($pid == 0) {
        my $addr = accept(Net::SSLeay::SSLCAT_S, $sock) or die;

        my $old_out = select(Net::SSLeay::SSLCAT_S);
        $| = 1;
        select($old_out);

        my $got = Net::SSLeay::tcp_read_all();
        is($got, $msg, 'tcp_read_all');

        ok(Net::SSLeay::tcp_write_all(uc($got)), 'tcp_write_all');

        close Net::SSLeay::SSLCAT_S;
        close $sock;

        exit;
    }
}

my @results;
{
    my ($got) = Net::SSLeay::tcpcat('localhost', $port, $msg);
    push @results, [ $got eq uc($msg), 'sent and recieved correctly' ];
}

waitpid $pid, 0;
push @results, [ $? == 0, 'server exited with 0' ];

END {
    Test::More->builder->current_test(2);
    for my $t (@results) {
        ok( $t->[0], $t->[1] );
    }
}