--- IO-FDPass/README 2013/04/05 08:20:36 1.3 +++ IO-FDPass/README 2013/04/06 22:42:42 1.4 @@ -4,10 +4,18 @@ SYNOPSIS use IO::FDPass; + IO::FDPass::send fileno $socket, fileno $fh_to_pass + or die "send failed: $!"; + + my $fd = IO::FDPass::recv fileno $socket; + $fd >= 0 or die "recv failed: $!"; + DESCRIPTION This small low-level module only has one purpose: pass a file descriptor to another process, using a (streaming) unix domain socket (on POSIX - systems) or any (streaming) socket (on WIN32 systems). + systems) or any (streaming) socket (on WIN32 systems). The ability to + pass file descriptors on windows is currently the unique selling point + of this module. Have I mentioned that it is really small, too? FUNCTIONS $bool = IO::FDPass::send $socket_fd, $fd_to_pass @@ -30,16 +38,16 @@ Receive a file descriptor from the socket and return it if successful. On errors, return -1. - Note that *both* $socket_fd amd the returned file descriptor are, in + Note that *both* $socket_fd and the returned file descriptor are, in fact, file descriptors, not handles. When used on non-blocking sockets, this function might fail with $! - set to "EAGAIN" or equivalent, in which case you are free to try. It - should succeed if called on a socket that indicates readability - (e.g. via "select"). + set to "EAGAIN" or equivalent, in which case you are free to try + again. It should succeed if called on a socket that indicates + readability (e.g. via "select"). - Example: receive a file desriptor from a blockign socket and convetr - it to a file handle. + Example: receive a file descriptor from a blocking socket and + convert it to a file handle. my $fd = IO::FDPass::recv fileno $socket; $fd >= 0 or die "unable to receive file handle: $!"; @@ -57,7 +65,8 @@ However, windows doesn't support asynchronous file descriptor passing, so the source process must still be around when the destination process wants to receive the file handle. Also, if the target process fails to - fetch the handle, the handle will leak, so never do that. + fetch the handle for any reason (crashes, fails to call "recv" etc.), + the handle will leak, so never do that. Also, on windows, the receiving process must have the PROCESS_DUP_HANDLE access right on the sender process for this module to work. @@ -70,17 +79,23 @@ OTHER MODULES At the time of this writing, the author of this module was aware of two - other file descriptor passing modules on CPAN: Linux::FDPasser and + other file descriptor passing modules on CPAN: File::FDPasser and AnyEvent::FDPasser. 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. + and it's author didn't respond to my mail with the fix, so doesn't work + on many 64 bit machines. It does, however, support a number of + pre-standard unices, basically everything of relevance at the time it + was written. 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. + doesn't support mixing data and file descriptors, and requires AnyEvent. + Presumably that makes it much more user friendly than this module + (skimming the manpage shows that a lot of thought has gone into it, and + you are well advised to read it and maybe use it before trying a + low-level module such as this one). In fact, the manpage discusses even + more file descriptor passing modules on CPAN. Neither seems to support native win32 perls.