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.33 by root, Sat Apr 6 09:34:11 2013 UTC vs.
Revision 1.35 by root, Sat Apr 6 09:39:12 2013 UTC

591 591
592If you want to execute some code (that isn't in a module) to take over the 592If you want to execute some code (that isn't in a module) to take over the
593process, you should compile a function via C<eval> first, and then call 593process, you should compile a function via C<eval> first, and then call
594it via C<run>. This also gives you access to any arguments passed via the 594it via C<run>. This also gives you access to any arguments passed via the
595C<send_xxx> methods, such as file handles. See the L<use AnyEvent::Fork as 595C<send_xxx> methods, such as file handles. See the L<use AnyEvent::Fork as
596a faster fork+exec> example. 596a faster fork+exec> example to see it in action.
597 597
598Returns the process object for easy chaining of method calls. 598Returns the process object for easy chaining of method calls.
599 599
600=cut 600=cut
601 601
627=item $proc = $proc->send_fh ($handle, ...) 627=item $proc = $proc->send_fh ($handle, ...)
628 628
629Send one or more file handles (I<not> file descriptors) to the process, 629Send one or more file handles (I<not> file descriptors) to the process,
630to prepare a call to C<run>. 630to prepare a call to C<run>.
631 631
632The process object keeps a reference to the handles until this is done, 632The process object keeps a reference to the handles until they have
633so you must not explicitly close the handles. This is most easily 633been passed over to the process, so you must not explicitly close the
634accomplished by simply not storing the file handles anywhere after passing 634handles. This is most easily accomplished by simply not storing the file
635them to this method. 635handles anywhere after passing them to this method - when AnyEvent::Fork
636is finished using them, perl will automatically close them.
636 637
637Returns the process object for easy chaining of method calls. 638Returns the process object for easy chaining of method calls.
638 639
639Example: pass a file handle to a process, and release it without 640Example: pass a file handle to a process, and release it without
640closing. It will be closed automatically when it is no longer used. 641closing. It will be closed automatically when it is no longer used.
656} 657}
657 658
658=item $proc = $proc->send_arg ($string, ...) 659=item $proc = $proc->send_arg ($string, ...)
659 660
660Send one or more argument strings to the process, to prepare a call to 661Send one or more argument strings to the process, to prepare a call to
661C<run>. The strings can be any octet string. 662C<run>. The strings can be any octet strings.
662 663
663The protocol is optimised to pass a moderate number of relatively short 664The protocol is optimised to pass a moderate number of relatively short
664strings - while you can pass up to 4GB of data in one go, this is more 665strings - while you can pass up to 4GB of data in one go, this is more
665meant to pass some ID information or other startup info, not big chunks of 666meant to pass some ID information or other startup info, not big chunks of
666data. 667data.
682Enter the function specified by the function name in C<$func> in the 683Enter the function specified by the function name in C<$func> in the
683process. The function is called with the communication socket as first 684process. The function is called with the communication socket as first
684argument, followed by all file handles and string arguments sent earlier 685argument, followed by all file handles and string arguments sent earlier
685via C<send_fh> and C<send_arg> methods, in the order they were called. 686via C<send_fh> and C<send_arg> methods, in the order they were called.
686 687
688The process object becomes unusable on return from this function - any
689further method calls result in undefined behaviour.
690
687The function name should be fully qualified, but if it isn't, it will be 691The function name should be fully qualified, but if it isn't, it will be
688looked up in the main package. 692looked up in the C<main> package.
689 693
690If the called function returns, doesn't exist, or any error occurs, the 694If the called function returns, doesn't exist, or any error occurs, the
691process exits. 695process exits.
692 696
693Preparing the process is done in the background - when all commands have 697Preparing the process is done in the background - when all commands have
694been sent, the callback is invoked with the local communications socket 698been sent, the callback is invoked with the local communications socket
695as argument. At this point you can start using the socket in any way you 699as argument. At this point you can start using the socket in any way you
696like. 700like.
697
698The process object becomes unusable on return from this function - any
699further method calls result in undefined behaviour.
700 701
701If the communication socket isn't used, it should be closed on both sides, 702If the communication socket isn't used, it should be closed on both sides,
702to save on kernel memory. 703to save on kernel memory.
703 704
704The socket is non-blocking in the parent, and blocking in the newly 705The socket is non-blocking in the parent, and blocking in the newly

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines