The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::Async::TransferFD - support for transferring handles between processes via socketpair

VERSION

version 0.002

SYNOPSIS

 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);

DESCRIPTION

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.

METHODS

outgoing_packet

Convert a list of handles to a cmsghdr struct suitable for transferring to another process.

Returns the encoded cmsghdr struct.

recv_fds

Receive packet containing FDs.

Takes a single coderef which will be called with two parameters.

Returns $self.

send_queued

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.

Returns $self.

read_pending

Reads any pending messages, converting to FDs as appropriate and calling the on_fh callback.

Returns $self.

accept_fds

Attempts to accept the given FDs from the remote.

Will call "on_fh" for each received file descriptor after reopening.

on_fh

Calls the configured filehandle method if provided (via "configure"(on_fh)).

send

Sends the given FDs to the remote, returning a Future which will resolve once all FDs have been transferred.

SEE ALSO

INHERITED METHODS

IO::Async::Notifier

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

AUTHOR

Tom Molesworth <TEAM@cpan.org>

LICENSE

Copyright Tom Molesworth 2011-2015. Licensed under the same terms as Perl itself.