File: loop-child.t

package info (click to toggle)
libnet-daemon-perl 0.38-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 192 kB
  • ctags: 38
  • sloc: perl: 752; makefile: 47; sh: 8
file content (66 lines) | stat: -rw-r--r-- 1,672 bytes parent folder | download | duplicates (7)
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
62
63
64
65
66
# -*- perl -*-
#
#   $Id: loop-child.t,v 1.1 1999/08/12 14:28:59 joe Exp $
#

require 5.004;
use strict;

use IO::Socket ();
use Config ();
use Net::Daemon::Test ();

my $numTests = 6;


my($handle, $port);
if (@ARGV) {
    $port = shift;
} else {
    ($handle, $port) =
	Net::Daemon::Test->Child($numTests,
				 $^X, '-Iblib/lib', '-Iblib/arch',
				 't/server', '--mode=single',
				 '--loop-timeout=2', '--loop-child',
				 '--debug', '--timeout', 60);    
}

print "Making first connection to port $port...\n";
my $fh = IO::Socket::INET->new('PeerAddr' => '127.0.0.1',
			       'PeerPort' => $port);
printf("%s 1\n", $fh ? "ok" : "not ok");
printf("%s 2\n", $fh->close() ? "ok" : "not ok");
print "Making second connection to port $port...\n";
$fh = IO::Socket::INET->new('PeerAddr' => '127.0.0.1',
			    'PeerPort' => $port);
printf("%s 3\n", $fh ? "ok" : "not ok");
my($ok) = $fh ? 1 : 0;
for (my $i = 0;  $ok  &&  $i < 20;  $i++) {
    print "Writing number: $i\n";
    if (!$fh->print("$i\n")  ||  !$fh->flush()) { $ok = 0; last; }
    print "Written.\n";
    my($line) = $fh->getline();
    print "line = ", (defined($line) ? $line : "undef"), "\n";
    if (!defined($line)) { $ok = 0;  last; }
    if ($line !~ /(\d+)/  ||  $1 != $i*2) { $ok = 0;  last; }
}
printf("%s 4\n", $ok ? "ok" : "not ok");
printf("%s 5\n", $fh->close() ? "ok" : "not ok");

$ok = 0;
for (my $i = 0;  $i < 30;  $i++) {
    my $num;
    if (open(CNT, "<ndtest.cnt") and
	defined($num = <CNT>)  and
	$num eq "10\n") {
	$ok = 1;
	last;
    }
    sleep 1;
}
printf("%s 6\n", $ok ? "ok" : "not ok");

END {
    if ($handle) { $handle->Terminate() }
    unlink "ndtest.prt", "ndtest.cnt";
}