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

Comparing AnyEvent-Fork/Fork.pm (file contents):
Revision 1.57 by root, Sun Aug 25 17:38:43 2013 UTC vs.
Revision 1.58 by root, Sun Aug 25 21:10:10 2013 UTC

817Even if not used otherwise, the socket can be a good indicator for the 817Even if not used otherwise, the socket can be a good indicator for the
818existence of the process - if the other process exits, you get a readable 818existence of the process - if the other process exits, you get a readable
819event on it, because exiting the process closes the socket (if it didn't 819event on it, because exiting the process closes the socket (if it didn't
820create any children using fork). 820create any children using fork).
821 821
822=over 4
823
824=item Compatibility to L<AnyEvent::Fork::Remote>
825
826If you want to write code that works with both this module and
827L<AnyEvent::Fork::Remote>, you need to write your code so that it assumes
828there are two file handles for communications, which might not be unix
829domain sockets. The C<run> function should start like this:
830
831 sub run {
832 my ($rfh, @args) = @_; # @args is your normal arguments
833 my $wfh = fileno $rfh ? $rfh : *STDOUT;
834
835 # now use $rfh for reading and $wfh for writing
836 }
837
838This checks whether the passed file handle is, in fact, the process
839C<STDIN> handle. If it is, then the function was invoked visa
840L<AnyEvent::Fork::Remote>, so STDIN should be used for reading and
841C<STDOUT> should be used for writing.
842
843In all other cases, the function was called via this module, and there is
844only one file handle that should be sued for reading and writing.
845
846=back
847
822Example: create a template for a process pool, pass a few strings, some 848Example: create a template for a process pool, pass a few strings, some
823file handles, then fork, pass one more string, and run some code. 849file handles, then fork, pass one more string, and run some code.
824 850
825 my $pool = AnyEvent::Fork 851 my $pool = AnyEvent::Fork
826 ->new 852 ->new
873the communications socket. 899the communications socket.
874 900
875The process object becomes unusable on return from this function - any 901The process object becomes unusable on return from this function - any
876further method calls result in undefined behaviour. 902further method calls result in undefined behaviour.
877 903
878The point of this method is to give you a file handle thta you cna pass 904The point of this method is to give you a file handle that you can pass
879to another process. In that other process, you can call C<new_from_fh 905to another process. In that other process, you can call C<new_from_fh
880AnyEvent::Fork> to create a new C<AnyEvent::Fork> object from it, thereby 906AnyEvent::Fork $fh> to create a new C<AnyEvent::Fork> object from it,
881effectively passing a fork object to another process. 907thereby effectively passing a fork object to another process.
882 908
883=cut 909=cut
884 910
885sub to_fh { 911sub to_fh {
886 my ($self, $cb) = @_; 912 my ($self, $cb) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines