ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-FDPass/FDPass.pm
(Generate patch)

Comparing IO-FDPass/FDPass.pm (file contents):
Revision 1.3 by root, Fri Apr 5 05:04:59 2013 UTC vs.
Revision 1.5 by root, Fri Apr 5 09:12:59 2013 UTC

3IO::FDPass - pass a file descriptor over a socket 3IO::FDPass - pass a file descriptor over a socket
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use IO::FDPass; 7 use IO::FDPass;
8
9 IO::FDPass::send fileno $socket, fileno $fh_to_pass
10 or die "send failed: $!";
11
12 my $fd = IO::FDPass::recv fileno $socket;
13 $fd >= 0 or die "recv failed: $!";
8 14
9=head1 DESCRIPTION 15=head1 DESCRIPTION
10 16
11This small low-level module only has one purpose: pass a file descriptor 17This small low-level module only has one purpose: pass a file descriptor
12to another process, using a (streaming) unix domain socket (on POSIX 18to another process, using a (streaming) unix domain socket (on POSIX
19=cut 25=cut
20 26
21package IO::FDPass; 27package IO::FDPass;
22 28
23BEGIN { 29BEGIN {
24 $VERSION = '0.1'; 30 $VERSION = 0.2;
25 31
26 require XSLoader; 32 require XSLoader;
27 XSLoader::load (__PACKAGE__, $VERSION); 33 XSLoader::load (__PACKAGE__, $VERSION);
28} 34}
29 35
75and 64 bit and Strawberry Perl 5.16.3 32 and 64 bit, and found to work, 81and 64 bit and Strawberry Perl 5.16.3 32 and 64 bit, and found to work,
76although ActivePerl 32 bit needed a newer MinGW version (that supports XP 82although ActivePerl 32 bit needed a newer MinGW version (that supports XP
77and higher). 83and higher).
78 84
79However, windows doesn't support asynchronous file descriptor passing, so 85However, windows doesn't support asynchronous file descriptor passing, so
80C<send> and C<recv> will have to "rendezvous", that is, they have to wait 86the source process must still be around when the destination process wants
81for each other. Therefore, on windows, it's advisable to run them at the 87to receive the file handle. Also, if the target process fails to fetch the
82same time to avoid any unnecessary delays. 88handle, the handle will leak, so never do that.
83 89
84Also, on windows, the passing process must give the receiving process the 90Also, on windows, the receiving process must have the PROCESS_DUP_HANDLE
85PROCESS_DUP_HANDLE access right for this module to work. 91access right on the sender process for this module to work.
86 92
87Cygwin is not supported at the moment, as file descriptor passing in 93Cygwin is not supported at the moment, as file descriptor passing in
88cygwin is not supported, and cannot be rolled on your own as cygwin has no 94cygwin is not supported, and cannot be rolled on your own as cygwin has no
89(working) method of opening a handle as fd. That is, it has one, but that 95(working) method of opening a handle as fd. That is, it has one, but that
90one isn't exposed to programs, and only used for stdin/out/err. Sigh. 96one isn't exposed to programs, and only used for stdin/out/err. Sigh.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines