… | |
… | |
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; |
7 | use AnyEvent::Fork::RPC; |
8 | 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 ( |
… | |
… | |
37 | concurrently in the child, using AnyEvent. |
37 | concurrently in the child, using AnyEvent. |
38 | |
38 | |
39 | It also implements an asynchronous event mechanism from the child to the |
39 | It also implements an asynchronous event mechanism from the child to the |
40 | parent, that could be used for progress indications or other information. |
40 | parent, that could be used for progress indications or other information. |
41 | |
41 | |
42 | Loading this module also always loads L<AnyEvent::Fork>, so you can make a |
|
|
43 | separate C<use AnyEvent::Fork> if you wish, but you don't have to. |
|
|
44 | |
|
|
45 | =head1 EXAMPLES |
42 | =head1 EXAMPLES |
46 | |
43 | |
47 | =head2 Example 1: Synchronous Backend |
44 | =head2 Example 1: Synchronous Backend |
48 | |
45 | |
49 | Here is a simple example that implements a backend that executes C<unlink> |
46 | Here is a simple example that implements a backend that executes C<unlink> |
… | |
… | |
52 | silly, but illustrates the use of events. |
49 | silly, but illustrates the use of events. |
53 | |
50 | |
54 | First the parent process: |
51 | First the parent process: |
55 | |
52 | |
56 | use AnyEvent; |
53 | use AnyEvent; |
|
|
54 | use AnyEvent::Fork; |
57 | use AnyEvent::Fork::RPC; |
55 | use AnyEvent::Fork::RPC; |
58 | |
56 | |
59 | my $done = AE::cv; |
57 | my $done = AE::cv; |
60 | |
58 | |
61 | my $rpc = AnyEvent::Fork |
59 | my $rpc = AnyEvent::Fork |
… | |
… | |
192 | so silly anymore. |
190 | so silly anymore. |
193 | |
191 | |
194 | Without further ado, here is the code: |
192 | Without further ado, here is the code: |
195 | |
193 | |
196 | use AnyEvent; |
194 | use AnyEvent; |
|
|
195 | use AnyEvent::Fork; |
197 | use AnyEvent::Fork::RPC; |
196 | use AnyEvent::Fork::RPC; |
198 | |
197 | |
199 | my $done = AE::cv; |
198 | my $done = AE::cv; |
200 | |
199 | |
201 | my $rpc = AnyEvent::Fork |
200 | my $rpc = AnyEvent::Fork |
… | |
… | |
304 | |
303 | |
305 | use Errno (); |
304 | use Errno (); |
306 | use Guard (); |
305 | use Guard (); |
307 | |
306 | |
308 | use AnyEvent; |
307 | use AnyEvent; |
309 | # explicit version on next line, as some cpan-testers test with the 0.1 version, |
|
|
310 | # ignoring dependencies, and this line will at least give a clear indication of that. |
|
|
311 | use AnyEvent::Fork 0.6; # we don't actually depend on it, this is for convenience |
|
|
312 | |
308 | |
313 | our $VERSION = 1.1; |
309 | our $VERSION = 1.1; |
314 | |
310 | |
315 | =item my $rpc = AnyEvent::Fork::RPC::run $fork, $function, [key => value...] |
311 | =item my $rpc = AnyEvent::Fork::RPC::run $fork, $function, [key => value...] |
316 | |
312 | |
… | |
… | |
729 | half it has passed earlier. |
725 | half it has passed earlier. |
730 | |
726 | |
731 | Here is some (untested) pseudocode to that effect: |
727 | Here is some (untested) pseudocode to that effect: |
732 | |
728 | |
733 | use AnyEvent::Util; |
729 | use AnyEvent::Util; |
|
|
730 | use AnyEvent::Fork; |
734 | use AnyEvent::Fork::RPC; |
731 | use AnyEvent::Fork::RPC; |
735 | use IO::FDPass; |
732 | use IO::FDPass; |
736 | |
733 | |
737 | my ($s1, $s2) = AnyEvent::Util::portable_socketpair; |
734 | my ($s1, $s2) = AnyEvent::Util::portable_socketpair; |
738 | |
735 | |
… | |
… | |
785 | |
782 | |
786 | =head1 SEE ALSO |
783 | =head1 SEE ALSO |
787 | |
784 | |
788 | L<AnyEvent::Fork>, to create the processes in the first place. |
785 | L<AnyEvent::Fork>, to create the processes in the first place. |
789 | |
786 | |
790 | L<AnyEvent::Fork::Remote>, like above, but helpful for remote processes. |
787 | L<AnyEvent::Fork::Remote>, likewise, but helpful for remote processes. |
791 | |
788 | |
792 | L<AnyEvent::Fork::Pool>, to manage whole pools of processes. |
789 | L<AnyEvent::Fork::Pool>, to manage whole pools of processes. |
793 | |
790 | |
794 | =head1 AUTHOR AND CONTACT INFORMATION |
791 | =head1 AUTHOR AND CONTACT INFORMATION |
795 | |
792 | |