1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | AnyEvent::Fork::RPC - simple RPC extension for AnyEvent::Fork |
3 | AnyEvent::Fork::RPC - simple RPC extension for AnyEvent::Fork |
|
|
4 | |
|
|
5 | THE API IS NOT FINISHED, CONSIDER THIS A TECHNOLOGY DEMO |
4 | |
6 | |
5 | =head1 SYNOPSIS |
7 | =head1 SYNOPSIS |
6 | |
8 | |
7 | use AnyEvent::Fork::RPC; |
9 | use AnyEvent::Fork::RPC; |
8 | # use AnyEvent::Fork is not needed |
10 | # use AnyEvent::Fork is not needed |
… | |
… | |
11 | ->new |
13 | ->new |
12 | ->require ("MyModule") |
14 | ->require ("MyModule") |
13 | ->AnyEvent::Fork::RPC::run ( |
15 | ->AnyEvent::Fork::RPC::run ( |
14 | "MyModule::server", |
16 | "MyModule::server", |
15 | ); |
17 | ); |
|
|
18 | |
|
|
19 | use AnyEvent; |
16 | |
20 | |
17 | my $cv = AE::cv; |
21 | my $cv = AE::cv; |
18 | |
22 | |
19 | $rpc->(1, 2, 3, sub { |
23 | $rpc->(1, 2, 3, sub { |
20 | print "MyModule::server returned @_\n"; |
24 | print "MyModule::server returned @_\n"; |
… | |
… | |
372 | |
376 | |
373 | The default server used in the child does all I/O blockingly, and only |
377 | The default server used in the child does all I/O blockingly, and only |
374 | allows a single RPC call to execute concurrently. |
378 | allows a single RPC call to execute concurrently. |
375 | |
379 | |
376 | Setting C<async> to a true value switches to another implementation that |
380 | Setting C<async> to a true value switches to another implementation that |
377 | uses L<AnyEvent> in the child and allows multiple concurrent RPC calls. |
381 | uses L<AnyEvent> in the child and allows multiple concurrent RPC calls (it |
|
|
382 | does not support recursion in the event loop however, blocking condvar |
|
|
383 | calls will fail). |
378 | |
384 | |
379 | The actual API in the child is documented in the section that describes |
385 | The actual API in the child is documented in the section that describes |
380 | the calling semantics of the returned C<$rpc> function. |
386 | the calling semantics of the returned C<$rpc> function. |
381 | |
387 | |
382 | If you want to pre-load the actual back-end modules to enable memory |
388 | If you want to pre-load the actual back-end modules to enable memory |
… | |
… | |
557 | $ww ||= AE::io $fh, 1, $wcb; |
563 | $ww ||= AE::io $fh, 1, $wcb; |
558 | }); |
564 | }); |
559 | |
565 | |
560 | my $guard = Guard::guard { |
566 | my $guard = Guard::guard { |
561 | $shutdown = 1; |
567 | $shutdown = 1; |
562 | $ww ||= $fh && AE::io $fh, 1, $wcb; |
568 | |
|
|
569 | shutdown $fh, 1 if $fh && !$ww; |
563 | }; |
570 | }; |
564 | |
571 | |
565 | my $id; |
572 | my $id; |
566 | |
573 | |
567 | $arg{async} |
574 | $arg{async} |
… | |
… | |
693 | are queued and the jobs are slow, they will all run concurrently. The |
700 | are queued and the jobs are slow, they will all run concurrently. The |
694 | child must implement some queueing/limiting mechanism if this causes |
701 | child must implement some queueing/limiting mechanism if this causes |
695 | problems. Alternatively, the parent could limit the amount of rpc calls |
702 | problems. Alternatively, the parent could limit the amount of rpc calls |
696 | that are outstanding. |
703 | that are outstanding. |
697 | |
704 | |
|
|
705 | Blocking use of condvars is not supported. |
|
|
706 | |
698 | Using event-based modules such as L<IO::AIO>, L<Gtk2>, L<Tk> and so on is |
707 | Using event-based modules such as L<IO::AIO>, L<Gtk2>, L<Tk> and so on is |
699 | easy. |
708 | easy. |
700 | |
709 | |
701 | =back |
710 | =back |
702 | |
711 | |
… | |
… | |
765 | so you might want to look into L<AnyEvent::FDpasser> which can handle the |
774 | so you might want to look into L<AnyEvent::FDpasser> which can handle the |
766 | gory details. |
775 | gory details. |
767 | |
776 | |
768 | =head1 SEE ALSO |
777 | =head1 SEE ALSO |
769 | |
778 | |
770 | L<AnyEvent::Fork> (to create the processes in the first place), |
779 | L<AnyEvent::Fork>, to create the processes in the first place. |
|
|
780 | |
771 | L<AnyEvent::Fork::Pool> (to manage whole pools of processes). |
781 | L<AnyEvent::Fork::Pool>, to manage whole pools of processes. |
772 | |
782 | |
773 | =head1 AUTHOR AND CONTACT INFORMATION |
783 | =head1 AUTHOR AND CONTACT INFORMATION |
774 | |
784 | |
775 | Marc Lehmann <schmorp@schmorp.de> |
785 | Marc Lehmann <schmorp@schmorp.de> |
776 | http://software.schmorp.de/pkg/AnyEvent-Fork-RPC |
786 | http://software.schmorp.de/pkg/AnyEvent-Fork-RPC |