Revision history for IPC-MorseSignals
+0.03 2007-08-16 16:20 UTC
+ + Chg : Better t/10-base.t... Or at least, I hope so.
+
0.02 2007-08-16 15:55 UTC
+ Add : samples/bench.pl, a transfer speed benchmark script.
+ Add : New tests : t/02-sigusr.t, t/11-speed.t
use IPC::MorseSignals qw/msend mrecv/;
-my $speed = 128;
-
sub trysend {
my ($msg, $desc) = @_;
- pipe my $rdr, my $wtr or die "$desc: pipe() failed : $!";
- my $pid = fork;
- if (!defined $pid) {
- die "$desc: fork() failed : $!";
- } elsif ($pid == 0) {
- close $rdr;
- local @SIG{qw/USR1 USR2/} = mrecv sub {
- print $wtr $_[0], "\n";
- close $wtr;
- exit EXIT_SUCCESS;
+ my $speed = 2 ** 16;
+ my $ok = 0;
+SPEED:
+ while (($speed > 1) && !$ok) {
+ $speed /= 2;
+ pipe my $rdr, my $wtr or die "$desc: pipe() failed : $!";
+ my $pid = fork;
+ if (!defined $pid) {
+ die "$desc: fork() failed : $!";
+ } elsif ($pid == 0) {
+ close $rdr;
+ local @SIG{qw/USR1 USR2/} = mrecv sub {
+ print $wtr $_[0], "\n";
+ close $wtr;
+ exit EXIT_SUCCESS;
+ };
+ 1 while 1;
+ }
+ close $wtr or die "$desc: close() failed : $!";
+ eval {
+ local $SIG{ALRM} = sub { die 'timeout' };
+ my $a = (int(100 * (3 * length $msg) / $speed) || 1);
+ $a = 10 if $a > 10;
+ alarm $a;
+ msend $msg => $pid, $speed;
+ waitpid $pid, 0;
};
- 1 while 1;
- }
- close $wtr or die "$desc: close() failed : $!";
- eval {
- local $SIG{ALRM} = sub { die 'timeout' };
- my $a = (int(100 * (3 * length $msg) / $speed) || 1);
- $a = 10 if $a > 10;
- alarm $a;
- msend $msg => $pid, $speed;
- waitpid $pid, 0;
- };
- alarm 0;
- if ($@) {
- kill SIGINT, $pid;
- kill SIGTERM, $pid;
- kill SIGKILL, $pid;
- die "$desc: died ($@)";
+ alarm 0;
+ if ($@) {
+ kill SIGINT, $pid;
+ kill SIGTERM, $pid;
+ kill SIGKILL, $pid;
+ close $rdr or die "$desc: close() failed : $!";
+ next SPEED;
+ }
+ my $recv = do { local $/; <$rdr> };
+ close $rdr or die "$desc: close() failed : $!";
+ next SPEED unless $recv;
+ chomp $recv;
+ next SPEED unless $msg eq $recv;
+ $ok = 1;
}
- my $recv = do { local $/; <$rdr> };
- close $rdr;
- chomp $recv;
- ok($msg eq $recv, $desc);
+ ok($speed >= 1, $desc);
}
for (1 .. 5) {
my $ok = 0;
my $msg = join '', map { chr int rand 256 } 1 .. $l;
my $desc;
- while (($speed >= 1) && ($ok < $n)) {
+ while (($speed > 1) && ($ok < $n)) {
$desc = "$n sends of $l bytes at $speed bits/s";
$speed /= 2;
$ok = 0;
}
close $wtr or die "$desc: close() failed : $!";
eval {
- local $SIG{ALRM} = sub { die 'alarm' };
+ local $SIG{ALRM} = sub { die 'timeout' };
my $a = (int(100 * (3 * $l) / $speed) || 1);
$a = 10 if $a > 10;
alarm $a;