Revision history for IPC-MorseSignals
+0.14 2008-03-13
+ + Fix : Correct die error when SIGUSR{1,2} aren't found.
+ + Tst : Don't reset the receiver state, flush the pipe instead.
+ SIGTSTP isn't needed anymore.
+ + Tst : Timeouts aren't truncated to 10 seconds anymore. This used to
+ result into physically logical failures. On the other hand, if
+ the required timeout now goes over 20 seconds, the test is
+ considered failed.
+
0.13 2008-03-10 15:25 UTC
+ Chg : Build prerequisites are now completely separated from run-time
prerequisites.
--- #YAML:1.0
name: IPC-MorseSignals
-version: 0.13
+version: 0.14
abstract: Communicate between processes with Morse signals.
license: perl
author:
generated_by: ExtUtils::MakeMaker version 6.44
distribution_type: module
requires:
- Bit::MorseSignals: 0
+ Bit::MorseSignals: 0.05
Carp: 0
POSIX: 0
Time::HiRes: 0
print "Checking if you have SIG$_... ";
unless (exists $sigs{$_}) {
print "no\n";
- die 'OS unsupported' if $@;
+ die 'OS unsupported';
}
print "yes\n";
}
ABSTRACT_FROM => 'lib/IPC/MorseSignals.pm',
PL_FILES => {},
PREREQ_PM => {
- 'Bit::MorseSignals' => 0,
+ 'Bit::MorseSignals' => 0.05,
'Carp' => 0,
'POSIX' => 0,
'Time::HiRes' => 0,
IPC::MorseSignals - Communicate between processes with Morse signals.
VERSION
- Version 0.13
+ Version 0.14
SYNOPSIS
# In the sender process
=head1 VERSION
-Version 0.13
+Version 0.14
=cut
-our $VERSION = '0.13';
+our $VERSION = '0.14';
=head1 SYNOPSIS
=head1 VERSION
-Version 0.13
+Version 0.14
=cut
-our $VERSION = '0.13';
+our $VERSION = '0.14';
=head1 SYNOPSIS
=head1 VERSION
-Version 0.13
+Version 0.14
=cut
-our $VERSION = '0.13';
+our $VERSION = '0.14';
=head1 SYNOPSIS
sub test {
my ($desc, @args) = @_;
- eval { ok(try(@args), $desc) };
+ my ($res, $speed, $len);
+ eval {
+ ($res, $speed, $len) = try(@args);
+ };
fail($desc . " (died : $@)") if $@;
+ ok($res, $desc . ' (' . $len . ' bits @ ' . $speed . ' bauds)');
}
my @msgs = qw/hlagh hlaghlaghlagh HLAGH HLAGHLAGHLAGH \x{0dd0}\x{00}
init 6;
-for (0 .. $#msgs) {
- test 'plain ' . $_ => $msgs[$_];
+for (1 .. @msgs) {
+ test 'plain ' . $_ => $msgs[$_-1];
}
cleanup;
sub test {
my ($desc, @args) = @_;
- eval { ok(try(@args), $desc) };
+ my ($res, $speed, $len);
+ eval {
+ ($res, $speed, $len) = try(@args);
+ };
fail($desc . " (died : $@)") if $@;
+ ok($res, $desc . ' (' . $len . ' bits @ ' . $speed . ' bauds)');
}
my @msgs = qw/€éèë 月語 x tata たTÂ/;
init 6;
-for (0 .. $#msgs) {
- test 'utf8 ' . $_ => $msgs[$_];
+for (1 .. @msgs) {
+ test 'utf8 ' . $_ => $msgs[$_-1];
}
cleanup;
sub test {
my ($desc, @args) = @_;
- eval { ok(try(@args), $desc) };
+ my ($res, $speed, $len);
+ eval {
+ ($res, $speed, $len) = try(@args);
+ };
fail($desc . " (died : $@)") if $@;
+ ok($res, $desc . ' (' . $len . ' bits @ ' . $speed . ' bauds)');
}
my @msgs = (
init 6;
-for (0 .. $#msgs) {
- test 'storable ' . $_ => $msgs[$_];
+for (1 .. @msgs) {
+ test 'storable ' . $_ => $msgs[$_-1];
}
cleanup;
use warnings;
use Data::Dumper;
-use POSIX qw/pause SIGUSR1 SIGTSTP SIGKILL EXIT_FAILURE/;
+use POSIX qw/pause SIGUSR1 SIGKILL EXIT_FAILURE/;
use IPC::MorseSignals::Emitter;
use IPC::MorseSignals::Receiver;
$| = 1;
my $ppid = getppid;
my $rcv = new IPC::MorseSignals::Receiver \%SIG, done => sub {
- print $wtr Dumper($_[1]), "\n";
+ my $msg = Dumper($_[1]);
+ $msg =~ s/\n\r/ /g;
+ print $wtr "$msg\n";
kill SIGUSR1 => $ppid if $ppid;
};
$SIG{__WARN__} = sub {
my $warn = join '', @_;
$warn =~ s/\n\r/ /g;
- print $wtr "!warn : $warn\n";
+ print $wtr "!warn:$warn\n";
kill SIGUSR1 => $ppid if $ppid;
};
- $SIG{TSTP} = sub {
- $rcv->reset;
- kill SIGUSR1 => $ppid if $ppid;
- };
- print $wtr "ok\n";
+ print $wtr "!ok\n";
pause while 1;
exit EXIT_FAILURE;
}
close $wtr or die "close() failed: $!";
+ my $t = <$rdr>;
my $oldfh = select $rdr;
$| = 1;
select $oldfh;
- my $t = <$rdr>;
}
sub slaughter {
}
}
+sub respawn {
+ warn "# respawn ($lives lives left)";
+ slaughter;
+ spawn;
+}
+
sub init {
($lives) = @_;
$lives ||= 10;
sub try {
my ($msg) = @_;
my $speed = 2 ** 16;
- my $ok = 0;
- my @ret;
+ my $dump = Dumper($msg);
+ 1 while chomp $dump;
+ $dump =~ s/\n\r/ /g;
+ $snd->reset;
+ my $len = 0;
+ my $ok = 0;
while (!$ok && (($speed /= 2) >= 1)) {
+ $snd->post($msg);
+ $len = $snd->len;
+ my $a = 1 + (int($len / $speed) || 1);
+ last unless $a <= 20;
+ $snd->speed($speed);
my $r = '';
- my $dump = Dumper($msg);
- 1 while chomp $dump;
eval {
local $SIG{ALRM} = sub { die 'timeout' };
- local $SIG{__WARN__} = sub { alarm 0; die 'do not want warnings' };
- my $a = (int(100 * (3 * length $msg) / $speed) || 1);
- $a = 10 if $a > 10;
+ local $SIG{__WARN__} = sub { $a = alarm 0; die 'do not want warnings' };
alarm $a;
- $snd->post($msg);
- $snd->speed($speed);
$ready = 0;
$snd->send($pid);
pause until $ready;
$r = <$rdr>;
- alarm 0;
+ $a = alarm 0;
};
if (!defined $r) { # Something bad happened, respawn
- slaughter;
- spawn;
+ $snd->reset;
+ respawn;
} else {
1 while chomp $r;
if ($r eq $dump) {
$ok = 1;
} else {
- warn $1 if $r =~ /^warn\s*:\s*(.*)/;
- $ready = 0;
- kill SIGTSTP => $pid if $pid;
- pause until $ready;
+# warn "# expected $dump, got $r";
+FLUSH:
+ while ($r =~ /^!warn:(.*)/) {
+ warn "# $1";
+ warn "# flushing for $a seconds\n";
+ eval {
+ local $SIG{ALRM} = sub { die 'timeout' };
+ alarm $a;
+ $r = <$rdr>;
+ $a = alarm 0;
+ };
+ if ($@) {
+ $snd->reset;
+ respawn;
+ last FLUSH;
+ }
+ }
+ sleep 1;
}
}
}
- return ($ok) ? $speed : 0;
+ return $ok, $speed, $len;
}
sub bench {
my @alpha = ('a' .. 'z');
my $msg = join '', map { $alpha[rand @alpha] } 1 .. $l;
my $dump = Dumper($msg);
+ 1 while chomp $dump;
+ $dump =~ s/\n\r/ /g;
my $desc_base = "$l bytes sent $n time" . ('s' x ($n != 1));
while (($ok < $n) && (($speed /= 2) >= 1)) {
$ok = 0;
$diag->("try $desc...");
TRY:
for (1 .. $n) {
+ $snd->post($msg);
+ my $a = 1 + (int($snd->len / $speed) || 1);
+ $snd->speed($speed);
my $r = '';
eval {
local $SIG{ALRM} = sub { die 'timeout' };
local $SIG{__WARN__} = sub { alarm 0; die 'do not want warnings' };
- my $a = (int(100 * (3 * $l) / $speed) || 1);
- $a = 10 if $a > 10;
alarm $a;
- $snd->post($msg);
- $snd->speed($speed);
$ready = 0;
$snd->send($pid);
pause until $ready;
alarm 0;
};
if (!defined $r) { # Something bad happened, respawn
- slaughter;
- spawn;
+ $snd->reset;
+ respawn;
last TRY;
} else {
1 while chomp $r;
if ($r eq $dump) {
++$ok;
} else {
- $ready = 0;
- kill SIGTSTP => $pid if $pid;
- pause until $ready;
- last TRY;
+ while ($r =~ /^!warn:(.*)/) {
+ warn "# $1";
+ warn "# flushing for $a seconds\n";
+ eval {
+ local $SIG{ALRM} = sub { die 'timeout' };
+ alarm $a;
+ $r = <$rdr>;
+ $a = alarm 0;
+ };
+ if ($@) {
+ $snd->reset;
+ respawn;
+ last TRY;
+ }
+ }
}
}
}