6 use POSIX qw/SIGINT SIGTERM SIGKILL SIGHUP EXIT_FAILURE/;
10 use IPC::MorseSignals qw/msend mrecv mreset/;
16 die 'forked too many times' if $lives < 0;
17 pipe my $rdr, my $wtr or die "pipe() failed: $!";
20 die "fork() failed: $!";
22 close $rdr or die "close() failed: $!";
23 my $s = mrecv local %SIG, cb => sub {
25 print $wtr $_[1], "\n";
28 $SIG{'HUP'} = sub { mreset $s };
32 close $wtr or die "close() failed: $!";
46 my ($pid, $rdr) = spawn;
52 my @alpha = ('a' .. 'z');
53 my $msg = join '', map { $alpha[rand @alpha] } 1 .. $l;
54 while (($ok < $n) && (($speed /= 2) >= 1)) {
55 print STDERR "$n sends of $l bytes at $speed bits/s";
61 local $SIG{ALRM} = sub { print STDERR "timeout\n"; die };
62 my $a = (int(100 * (3 * $l) / $speed) || 1);
65 msend $msg => $pid, speed => $speed;
68 kill SIGHUP => $pid if $@;
70 if (!defined $r) { # Something bad happened, respawn
71 print STDERR "oops\n";
72 close $rdr or die "close() failed: $!";
75 redo TRY; # Retry this send
81 print STDERR "transfer error\n";
88 my $desc = "$l bytes sent $n times";
90 print STDERR " OK\n\n";
91 push @res, "$desc at $speed bits/s";
93 print STDERR " FAILED\n\n";
94 push @res, "$desc FAILED";
114 print STDERR "=== Summary ===\n";
115 print STDERR "$_\n" for @res;