=head1 NAME IO::FDPass - pass a file descriptor over a socket =head1 SYNOPSIS use IO::FDPass; =head1 DESCRIPTION This small low-level module only has one purpose: pass a file descriptor to another process, using a unix domain socket (on POSIX systems) or any socket (on WIN32 systems). =head1 FUNCTIONS =over 4 =cut package IO::FDPass; BEGIN { $VERSION = '0.0'; require XSLoader; XSLoader::load (__PACKAGE__, $VERSION); } =item $bool = IO::FDPass::send $socket_fd, $fd_to_pass Sends the file descriptor given by C<$fd_to_pass> over the socket C<$socket_fd>. Return true if it worked, false otherwise. Note that I parameters must be file descriptors, not handles. When used on non-blocking sockets, this function might fail with C<$!> set to C or equivalent, in which case you are free to try. It should succeed if called on a socket that indicates writability (e.g. via C). Example: receive a file desriptor from a blockign socket and convetr it to a file handle. my $fd = IO::FDPass::recv fileno $socket; $fd >= 0 or die "unable to receive file handle: $!"; open my $fh, "+<&=$fd" or die "unable to convert file descriptor to handle: $!"; =back =head1 PORTABILITY NOTES This module has been tested on NetBSD 6, OS X 10.5, Windows 2000 ActivePerl 5.10, Solaris 10, OpenBSD 4.4, 4.5, 4.8 and 5.0, DragonFly BSD, FreeBSD 7, 8 and 9, Windows 7 + ActivePerl 5.16.3 32 and 64 bit and Strawberry Perl 5.16.3 32 and 64 bit, and found to work, although ActivePerl 32 bit needed a newer MinGW version (that supports XP and higher). However, windows doesn't support asynchronous file descriptor passing, so C and C will have to "rendezvous", that is, they have to wait for each other. Therefore, on windows, it's advisable to run them at the same time to avoid any unnecessary delays. Also, on windows, the passing process must give the receiving process the PROCESS_DUP_HANDLE access right for this module to work. =head1 OTHER MODULES At the time of this writing, the author of this module was aware of two other file descriptor passing modules on CPAN: L and L. The former hasn't seen any release for over a decade, isn't 64 bit clean and it's author didn't respond to my mail with the fix. It does, however, support a snumber of pre-standard unices. The latter seems to have similar support for antique unices, and doesn't seem to suffer from 64 bit bugs, but inexplicably has a large perl part, and requires AnyEvent. Presumably that makes it much more user friendly than this module. Neither seems to support native win32 perls. =head1 AUTHOR Marc Lehmann http://home.schmorp.de/ =cut 1