- 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;