IPC-Fork-Simple
view release on metacpan or search on metacpan
lib/IPC/Fork/Simple.pm view on Meta::CPAN
If this parameter is set to false, no more child processes will be able to
send data back to the master, as the data handler will have exited. This
should only be called after all children have ended.
The second, optional, parameter is one of the BLOCK flags, as used by
L<process_child_data>. See EXAMPLES for details on the meaning of these flags.
=cut
sub collect_data_from_handler {
my ( $self, $keep_alive, $block ) = @_;
my ( $r, $msg );
if ( !$self->{'handler_pid'} ) { return; }
local $SIG{'PIPE'} = 'IGNORE';
if ( $keep_alive ) {
if ( $block == BLOCK_NEVER ) {
$msg = FLAG_PACKET_GET_CHILD_DATA;
} elsif ( $block == BLOCK_UNTIL_DATA ) {
$msg = FLAG_PACKET_GET_CHILD_DATA_BLOCK;
} elsif ( $block == BLOCK_UNTIL_CHILD ) {
$msg = FLAG_PACKET_GET_CHILD_DATA_FINISHED_BLOCK;
} else {
carp "Invalid value for BLOCK!";
}
} else {
lib/IPC/Fork/Simple.pm view on Meta::CPAN
}
$self->{'handler_socket_comm'}->send( pack( HEADER_PACKING, $msg ) )
|| die "Failed to send data to data handler: $!";
# _data_from_socket will return when
# FLAG_PACKET_DATA_HANDLER_DATA_CHECKPOINT is received.
do {
$r = $self->_data_from_socket( $self->{'handler_select'}, BLOCK_UNTIL_CHILD );
} until ( $r == FLAG_PACKET_DATA_HANDLER_DATA_CHECKPOINT );
if ( !$keep_alive ) {
# _data_from_socket will return when the remote socket is closed.
$self->_data_from_socket( $self->{'handler_select'}, BLOCK_UNTIL_CHILD );
waitpid( $self->{'handler_pid'}, 0 );
$self->{'handler_pid'} = 0;
}
return 1;
}
=head2 init_child
( run in 1.725 second using v1.01-cache-2.11-cpan-39bf76dae61 )