3 use Test::More tests => 2;
5 use POSIX qw/SIGINT SIGTERM SIGKILL SIGHUP EXIT_FAILURE/;
7 use IPC::MorseSignals qw/msend mrecv mreset/;
13 die 'forked too many times' if $lives < 0;
14 pipe my $rdr, my $wtr or die "pipe() failed: $!";
17 die "fork() failed: $!";
19 close $rdr or die "close() failed: $!";
21 my $s = mrecv local %SIG, cb => sub {
26 print $wtr $_[0], ':', $_[1], "\n";
30 $SIG{HUP} = sub { mreset $s };
31 $SIG{__WARN__} = sub { $block = 1 };
35 close $wtr or die "close() failed: $!";
47 my ($pid, $rdr) = spawn;
50 my ($sign, $desc) = @_;
53 while (!$ok && (($speed /= 2) >= 1)) {
56 local $SIG{ALRM} = sub { die 'timeout' };
57 local $SIG{__WARN__} = sub { die 'do not want warnings' };
58 my $a = (int(300 / $speed) || 1);
62 msend 'x' => $pid, speed => $speed, sign => $sign;
65 kill SIGHUP => $pid if $@;
67 if (!defined $r) { # Something bad happened, respawn
68 close $rdr or die "close() failed: $!";
71 $speed *= 2; # Retry this speed
74 my ($p, $m) = split /:/, $r;
75 $ok = ($m eq 'x') && ($p == ($sign ? $$ : 0)) if defined $m and defined $p;
81 trysend 0, 'anonymous';