File: blocking_debug_with_sub_coprocess

package info (click to toggle)
libipc-run-perl 20231003.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 844 kB
  • sloc: perl: 6,255; makefile: 5
file content (50 lines) | stat: -rw-r--r-- 816 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl -w

## Submitted by Blair Zajac <blair@orcaware.com>

## Tests blocking when piping though a &sub coprocess.
## Fixed, now in test suite.

$| = 1;

use strict;
use Carp;
use Symbol;
use IPC::Run 0.44 qw(start);

print "My pid is $$\n";

my $out_fd = gensym;
open( $out_fd, ">ZZZ.test" )
  or die "$0: open: $!\n";

my $queue = '';

my @commands = (
    [ [ 'cat', '-' ], \$queue, '|' ],
    [ ['cat'], '|' ],
    [ \&double, '>', $out_fd ]
);

my $harness = start 'debug' => 10, map { @$_ } @commands;
$harness
  or die "$0: harness\n";

close($out_fd)
  or die "$0: cannot close: $!\n";

for ( 1 .. 100 ) {
    $queue .= rand(100) . "\n";
    $harness->pump;
}
$harness->finish
  or die "$0: finish\n";

exit 0;

sub double {
    while (<STDIN>) {
        s/\s+$//;
        print "$_ $_\n";
    }
}