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