Net::Async::TransferFD - support for transferring handles between processes via socketpair
version 0.002
use feature qw(say); my $loop = IO::Async::Loop->new; my $proc = IO::Async::Process->new( code => sub { ... }, fd3 => { via => 'socketpair' }, ); $loop->add(my $control = Net::Async::TransferFD->new( handle => $proc->fd(3), on_fh => sub { my $h = shift; say "New handle $h - " . join '', <$h>; } )); $control->send(\*STDIN);
Uses SCM_RIGHTS to pass an open handle from one process to another. Typically used to hand a network socket off to another process, for example an accept loop in one process dispatching incoming connections to other active processes.
Convert a list of handles to a cmsghdr struct suitable for transferring to another process.
Returns the encoded cmsghdr struct.
Receive packet containing FDs.
Takes a single coderef which will be called with two parameters.
Returns $self.
If we have any FDs queued for sending, bundle them into a packet and send them over. Will close the FDs once the send is complete.
Reads any pending messages, converting to FDs as appropriate and calling the on_fh callback.
Attempts to accept the given FDs from the remote.
Will call "on_fh" for each received file descriptor after reopening.
Calls the configured filehandle method if provided (via "configure"(on_fh)).
on_fh
Sends the given FDs to the remote, returning a Future which will resolve once all FDs have been transferred.
Socket::MsgHdr - we use this to do all the real work
File::FDpasser - another implementation
add_child, adopt_future, can_event, children, configure_unknown, debug_printf, get_loop, invoke_error, invoke_event, loop, make_event_cb, maybe_invoke_event, maybe_make_event_cb, new, notifier_name, parent, remove_child, remove_from_parent
Tom Molesworth <TEAM@cpan.org>
Copyright Tom Molesworth 2011-2015. Licensed under the same terms as Perl itself.
To install Net::Async::TransferFD, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::TransferFD
CPAN shell
perl -MCPAN -e shell install Net::Async::TransferFD
For more information on module installation, please visit the detailed CPAN module installation guide.