ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-FDPass/t/01_basic.t
Revision: 1.1
Committed: Fri Apr 5 04:21:08 2013 UTC (11 years, 10 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-1_1, rel-1_0, rel-1_3, rel-1_2, rel-0_1, rel-0_2, HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 BEGIN { $| = 1; print "1..7\n"; }
2    
3     use Socket;
4     use IO::FDPass;
5    
6     print "ok 1\n";
7    
8     socketpair my $fh1, my $fh2, AF_UNIX, SOCK_STREAM, 0
9     or die "socketpair: $!";
10    
11     socketpair my $fh3, my $fh4, AF_UNIX, SOCK_STREAM, 0
12     or die "socketpair: $!";
13    
14     print "ok 2\n";
15    
16     my $pid = fork;
17    
18     defined $pid
19     or die "fork: $!";
20    
21     unless ($pid) {
22     close $fh3;
23    
24     my $fd = IO::FDPass::recv fileno $fh2;
25    
26     print $fd > 0 ? "" : "not ", "ok 4 # $fd\n";
27    
28     open my $fh, "+<&=$fd"
29     or die "open(fd) failed: $!";
30    
31     sysread $fh, my $buf, 1
32     or die "sysread(child) failed: $!";
33    
34     print $buf eq "4" ? "" : "not ", "ok 5 # $buf\n";
35    
36     syswrite $fh, "3", 1
37     or die "syswrite(child) failed: $!";
38    
39     exit;
40     }
41    
42     print "ok 3\n";
43    
44     IO::FDPass::send fileno $fh1, fileno $fh4
45     or die "send failed: $!";
46    
47     close $fh4;
48    
49     syswrite $fh3, "4", 1
50     or die "syswrite(parent) failed: $!";
51    
52     sysread $fh3, my $buf, 1
53     or die "sysread(parent) failed: $!";
54    
55     print $buf eq "3" ? "" : "not ", "ok 6 # $buf\n";
56    
57     print "ok 7\n";
58