ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-Fork-RPC/RPC.pm
(Generate patch)

Comparing AnyEvent-Fork-RPC/RPC.pm (file contents):
Revision 1.37 by root, Thu May 12 16:43:08 2016 UTC vs.
Revision 1.43 by root, Tue Mar 26 04:19:31 2019 UTC

391use Errno (); 391use Errno ();
392use Guard (); 392use Guard ();
393 393
394use AnyEvent; 394use AnyEvent;
395 395
396our $VERSION = 1.21; 396our $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
400The traditional way to call it. But it is way cooler to call it in the 400The traditional way to call it. But it is way cooler to call it in the
401following way: 401following way:
509 509
510If you need an external module for serialisation, then you can either 510If you need an external module for serialisation, then you can either
511pre-load it into your L<AnyEvent::Fork> process, or you can add a C<use> 511pre-load it into your L<AnyEvent::Fork> process, or you can add a C<use>
512or C<require> statement into the serialiser string. Or both. 512or C<require> statement into the serialiser string. Or both.
513 513
514Here are some examples - some of them are also available as global 514Here are some examples - all of them are also available as global
515variables that make them easier to use. 515variables 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;
783values. 784values.
784 785
785See the examples section earlier in this document for some actual 786See the examples section earlier in this document for some actual
786examples. 787examples.
787 788
789Note: the event data, like any data send to the parent, might not be sent
790immediatelly but queued for later sending, so there is no guarantee that
791the event has been sent to the parent when the call returns - when you
792e.g. exit directly after calling this function, the parent might never
793receive the event.
794
788=back 795=back
789 796
790=head2 PROCESS EXIT 797=head2 PROCESS EXIT
791 798
792If and when the child process exits depends on the backend and 799If and when the child process exits depends on the backend and

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines