File: 01_basic.t

package info (click to toggle)
libio-fdpass-perl 1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid
  • size: 96 kB
  • sloc: perl: 7; makefile: 3
file content (58 lines) | stat: -rw-r--r-- 1,006 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
BEGIN { $| = 1; print "1..7\n"; }

use Socket;
use IO::FDPass;

print "ok 1\n";

socketpair my $fh1, my $fh2, AF_UNIX, SOCK_STREAM, 0
   or die "socketpair: $!";

socketpair my $fh3, my $fh4, AF_UNIX, SOCK_STREAM, 0
   or die "socketpair: $!";

print "ok 2\n";

my $pid = fork;

defined $pid
   or die "fork: $!";

unless ($pid) {
   close $fh3;

   my $fd = IO::FDPass::recv fileno $fh2;

   print $fd > 0 ? "" : "not ", "ok 4 # $fd\n";

   open my $fh, "+<&=$fd"
      or die "open(fd) failed: $!";

   sysread $fh, my $buf, 1
      or die "sysread(child) failed: $!";

   print $buf eq "4" ? "" : "not ", "ok 5 # $buf\n";

   syswrite $fh, "3", 1
      or die "syswrite(child) failed: $!";

   exit;
}

print "ok 3\n";

IO::FDPass::send fileno $fh1, fileno $fh4
   or die "send failed: $!";

close $fh4;

syswrite $fh3, "4", 1
   or die "syswrite(parent) failed: $!";

sysread $fh3, my $buf, 1
   or die "sysread(parent) failed: $!";

print $buf eq "3" ? "" : "not ", "ok 6 # $buf\n";

print "ok 7\n";