--- AnyEvent-Fork-RPC/RPC.pm 2013/04/20 16:07:40 1.20 +++ AnyEvent-Fork-RPC/RPC.pm 2013/04/28 14:34:40 1.27 @@ -2,12 +2,10 @@ AnyEvent::Fork::RPC - simple RPC extension for AnyEvent::Fork -THE API IS NOT FINISHED, CONSIDER THIS A TECHNOLOGY DEMO - =head1 SYNOPSIS + use AnyEvent::Fork; use AnyEvent::Fork::RPC; - # use AnyEvent::Fork is not needed my $rpc = AnyEvent::Fork ->new @@ -30,8 +28,9 @@ =head1 DESCRIPTION This module implements a simple RPC protocol and backend for processes -created via L, allowing you to call a function in the -child process and receive its return values (up to 4GB serialised). +created via L (or L), allowing you +to call a function in the child process and receive its return values (up +to 4GB serialised). It implements two different backends: a synchronous one that works like a normal function call, and an asynchronous one that can run multiple jobs @@ -40,9 +39,6 @@ It also implements an asynchronous event mechanism from the child to the parent, that could be used for progress indications or other information. -Loading this module also always loads L, so you can make a -separate C if you wish, but you don't have to. - =head1 EXAMPLES =head2 Example 1: Synchronous Backend @@ -55,6 +51,7 @@ First the parent process: use AnyEvent; + use AnyEvent::Fork; use AnyEvent::Fork::RPC; my $done = AE::cv; @@ -195,6 +192,7 @@ Without further ado, here is the code: use AnyEvent; + use AnyEvent::Fork; use AnyEvent::Fork::RPC; my $done = AE::cv; @@ -307,9 +305,8 @@ use Guard (); use AnyEvent; -use AnyEvent::Fork; # we don't actually depend on it, this is for convenience -our $VERSION = 0.1; +our $VERSION = 1.1; =item my $rpc = AnyEvent::Fork::RPC::run $fork, $function, [key => value...] @@ -526,7 +523,7 @@ if ($len) { while (8 <= length $rbuf) { - ($id, $len) = unpack "LL", $rbuf; + ($id, $len) = unpack "NN", $rbuf; 8 + $len <= length $rbuf or last; @@ -581,7 +578,7 @@ $guard if 0; # keep it alive - $wbuf .= pack "LL/a*", $id, &$f; + $wbuf .= pack "NN/a*", $id, &$f; $ww ||= $fh && AE::io $fh, 1, $wcb; } : sub { @@ -589,7 +586,7 @@ $guard; # keep it alive - $wbuf .= pack "L/a*", &$f; + $wbuf .= pack "N/a*", &$f; $ww ||= $fh && AE::io $fh, 1, $wcb; } } @@ -730,6 +727,7 @@ Here is some (untested) pseudocode to that effect: use AnyEvent::Util; + use AnyEvent::Fork; use AnyEvent::Fork::RPC; use IO::FDPass; @@ -775,10 +773,19 @@ so you might want to look into L which can handle the gory details. +=head1 EXCEPTIONS + +There are no provisions whatsoever for catching exceptions at this time - +in the child, exeptions might kill the process, causing calls to be lost +and the parent encountering a fatal error. In the parent, exceptions in +the result callback will not be caught and cause undefined behaviour. + =head1 SEE ALSO L, to create the processes in the first place. +L, likewise, but helpful for remote processes. + L, to manage whole pools of processes. =head1 AUTHOR AND CONTACT INFORMATION