… | |
… | |
2 | |
2 | |
3 | AnyEvent::Fork::RPC - simple RPC extension for AnyEvent::Fork |
3 | AnyEvent::Fork::RPC - simple RPC extension for AnyEvent::Fork |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use AnyEvent::Fork; |
|
|
8 | use AnyEvent::Fork::RPC; |
7 | use AnyEvent::Fork::RPC; |
|
|
8 | # use AnyEvent::Fork is not needed |
9 | |
9 | |
10 | my $rpc = AnyEvent::Fork |
10 | my $rpc = AnyEvent::Fork |
11 | ->new |
11 | ->new |
12 | ->require ("MyModule") |
12 | ->require ("MyModule") |
13 | ->AnyEvent::Fork::RPC::run ( |
13 | ->AnyEvent::Fork::RPC::run ( |
… | |
… | |
33 | normal function call, and an asynchronous one that can run multiple jobs |
33 | normal function call, and an asynchronous one that can run multiple jobs |
34 | concurrently in the child, using AnyEvent. |
34 | concurrently in the child, using AnyEvent. |
35 | |
35 | |
36 | It also implements an asynchronous event mechanism from the child to the |
36 | It also implements an asynchronous event mechanism from the child to the |
37 | parent, that could be used for progress indications or other information. |
37 | parent, that could be used for progress indications or other information. |
|
|
38 | |
|
|
39 | Loading this module also always loads L<AnyEvent::Fork>, so you can make a |
|
|
40 | separate C<use AnyEvent::Fork> if you wish, but you don't have to. |
38 | |
41 | |
39 | =head1 EXAMPLES |
42 | =head1 EXAMPLES |
40 | |
43 | |
41 | =head2 Synchronous Backend |
44 | =head2 Synchronous Backend |
42 | |
45 | |
… | |
… | |
150 | |
153 | |
151 | use Errno (); |
154 | use Errno (); |
152 | use Guard (); |
155 | use Guard (); |
153 | |
156 | |
154 | use AnyEvent; |
157 | use AnyEvent; |
155 | #use AnyEvent::Fork; |
158 | use AnyEvent::Fork; # we don't actually depend on it, this is for convenience |
156 | |
159 | |
157 | our $VERSION = 0.1; |
160 | our $VERSION = 0.1; |
158 | |
161 | |
159 | =item my $rpc = AnyEvent::Fork::RPC::run $fork, $function, [key => value...] |
162 | =item my $rpc = AnyEvent::Fork::RPC::run $fork, $function, [key => value...] |
160 | |
163 | |
… | |
… | |
308 | $rw = AE::io $fh, 0, sub { |
311 | $rw = AE::io $fh, 0, sub { |
309 | $rlen = $rlen * 2 + 16 if $rlen - 128 < length $rbuf; |
312 | $rlen = $rlen * 2 + 16 if $rlen - 128 < length $rbuf; |
310 | my $len = sysread $fh, $rbuf, $rlen - length $rbuf, length $rbuf; |
313 | my $len = sysread $fh, $rbuf, $rlen - length $rbuf, length $rbuf; |
311 | |
314 | |
312 | if ($len) { |
315 | if ($len) { |
313 | while (5 <= length $rbuf) { |
316 | while (4 <= length $rbuf) { |
314 | $len = unpack "L", $rbuf; |
317 | $len = unpack "L", $rbuf; |
315 | 4 + $len <= length $rbuf |
318 | 4 + $len <= length $rbuf |
316 | or last; |
319 | or last; |
317 | |
320 | |
318 | my @r = $t->(substr $rbuf, 4, $len); |
321 | my @r = $t->(substr $rbuf, 4, $len); |