… | |
… | |
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.21; |
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: |
… | |
… | |
509 | |
509 | |
510 | If you need an external module for serialisation, then you can either |
510 | If you need an external module for serialisation, then you can either |
511 | pre-load it into your L<AnyEvent::Fork> process, or you can add a C<use> |
511 | pre-load it into your L<AnyEvent::Fork> process, or you can add a C<use> |
512 | or C<require> statement into the serialiser string. Or both. |
512 | or C<require> statement into the serialiser string. Or both. |
513 | |
513 | |
514 | Here are some examples - some of them are also available as global |
514 | Here are some examples - all of them are also available as global |
515 | variables that make them easier to use. |
515 | variables that make them easier to use. |
516 | |
516 | |
517 | =over 4 |
517 | =over 4 |
518 | |
518 | |
519 | =item C<$AnyEvent::Fork::RPC::STRING_SERIALISER> - octet strings only |
519 | =item C<$AnyEvent::Fork::RPC::STRING_SERIALISER> - octet strings only |
… | |
… | |
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; |
… | |
… | |
783 | values. |
784 | values. |
784 | |
785 | |
785 | See the examples section earlier in this document for some actual |
786 | See the examples section earlier in this document for some actual |
786 | examples. |
787 | examples. |
787 | |
788 | |
|
|
789 | Note: the event data, like any data send to the parent, might not be sent |
|
|
790 | immediatelly but queued for later sending, so there is no guarantee that |
|
|
791 | the event has been sent to the parent when the call returns - when you |
|
|
792 | e.g. exit directly after calling this function, the parent might never |
|
|
793 | receive the event. |
|
|
794 | |
788 | =back |
795 | =back |
789 | |
796 | |
790 | =head2 PROCESS EXIT |
797 | =head2 PROCESS EXIT |
791 | |
798 | |
792 | If and when the child process exits depends on the backend and |
799 | If and when the child process exits depends on the backend and |