… | |
… | |
371 | |
371 | |
372 | There is an important twist - the C<AnyEvent::Fork::RPC::event> function |
372 | There is an important twist - the C<AnyEvent::Fork::RPC::event> function |
373 | is only defined when the child is fully initialised. If you redirect the |
373 | is only defined when the child is fully initialised. If you redirect the |
374 | log messages in your C<init> function for example, then the C<event> |
374 | log messages in your C<init> function for example, then the C<event> |
375 | function might not yet be available. This is why the log callback checks |
375 | function might not yet be available. This is why the log callback checks |
376 | whether the fucntion is there using C<defined>, and only then uses it to |
376 | whether the function is there using C<defined>, and only then uses it to |
377 | log the message. |
377 | log the message. |
378 | |
378 | |
379 | =head1 PARENT PROCESS USAGE |
379 | =head1 PARENT PROCESS USAGE |
380 | |
380 | |
381 | This module exports nothing, and only implements a single function: |
381 | This module exports nothing, and only implements a single function: |
… | |
… | |
391 | use Errno (); |
391 | use Errno (); |
392 | use Guard (); |
392 | use Guard (); |
393 | |
393 | |
394 | use AnyEvent; |
394 | use AnyEvent; |
395 | |
395 | |
396 | our $VERSION = 1.22; |
396 | our $VERSION = 1.24; |
397 | |
397 | |
398 | =item my $rpc = AnyEvent::Fork::RPC::run $fork, $function, [key => value...] |
398 | =item my $rpc = AnyEvent::Fork::RPC::run $fork, $function, [key => value...] |
399 | |
399 | |
400 | The traditional way to call it. But it is way cooler to call it in the |
400 | The traditional way to call it. But it is way cooler to call it in the |
401 | following way: |
401 | following way: |
… | |
… | |
661 | my $module = "AnyEvent::Fork::RPC::" . ($arg{async} ? "Async" : "Sync"); |
661 | my $module = "AnyEvent::Fork::RPC::" . ($arg{async} ? "Async" : "Sync"); |
662 | |
662 | |
663 | $self->require ($module) |
663 | $self->require ($module) |
664 | ->send_arg ($function, $arg{init}, $serialiser, $arg{done} || "$module\::do_exit") |
664 | ->send_arg ($function, $arg{init}, $serialiser, $arg{done} || "$module\::do_exit") |
665 | ->run ("$module\::run", sub { |
665 | ->run ("$module\::run", sub { |
666 | $fh = shift; |
666 | $fh = shift |
|
|
667 | or return $on_error->("connection failed"); |
667 | |
668 | |
668 | my ($id, $len); |
669 | my ($id, $len); |
669 | $rw = AE::io $fh, 0, sub { |
670 | $rw = AE::io $fh, 0, sub { |
670 | $rlen = $rlen * 2 + 16 if $rlen - 128 < length $rbuf; |
671 | $rlen = $rlen * 2 + 16 if $rlen - 128 < length $rbuf; |
671 | $len = sysread $fh, $rbuf, $rlen - length $rbuf, length $rbuf; |
672 | $len = sysread $fh, $rbuf, $rlen - length $rbuf, length $rbuf; |