… | |
… | |
200 | |
200 | |
201 | sub worker { |
201 | sub worker { |
202 | my ($slave_filehandle) = @_; |
202 | my ($slave_filehandle) = @_; |
203 | |
203 | |
204 | # now $slave_filehandle is connected to the $master_filehandle |
204 | # now $slave_filehandle is connected to the $master_filehandle |
205 | # in the original prorcess. have fun! |
205 | # in the original process. have fun! |
206 | } |
206 | } |
207 | |
207 | |
208 | =head2 Create a pool of server processes all accepting on the same socket. |
208 | =head2 Create a pool of server processes all accepting on the same socket. |
209 | |
209 | |
210 | # create listener socket |
210 | # create listener socket |
… | |
… | |
465 | use AnyEvent; |
465 | use AnyEvent; |
466 | use AnyEvent::Util (); |
466 | use AnyEvent::Util (); |
467 | |
467 | |
468 | use IO::FDPass; |
468 | use IO::FDPass; |
469 | |
469 | |
470 | our $VERSION = 1.2; |
470 | our $VERSION = 1.3; |
471 | |
471 | |
472 | # the early fork template process |
472 | # the early fork template process |
473 | our $EARLY; |
473 | our $EARLY; |
474 | |
474 | |
475 | # the empty template process |
475 | # the empty template process |
… | |
… | |
673 | my %env = %ENV; |
673 | my %env = %ENV; |
674 | $env{PERL5LIB} = join +($^O eq "MSWin32" ? ";" : ":"), grep !ref, @INC; |
674 | $env{PERL5LIB} = join +($^O eq "MSWin32" ? ";" : ":"), grep !ref, @INC; |
675 | |
675 | |
676 | my $pid = Proc::FastSpawn::spawn ( |
676 | my $pid = Proc::FastSpawn::spawn ( |
677 | $PERL, |
677 | $PERL, |
678 | ["perl", "-MAnyEvent::Fork::Serve", "-e", "AnyEvent::Fork::Serve::me", fileno $slave, $$], |
678 | [$PERL, "-MAnyEvent::Fork::Serve", "-e", "AnyEvent::Fork::Serve::me", fileno $slave, $$], |
679 | [map "$_=$env{$_}", keys %env], |
679 | [map "$_=$env{$_}", keys %env], |
680 | ) or die "unable to spawn AnyEvent::Fork server: $!"; |
680 | ) or die "unable to spawn AnyEvent::Fork server: $!"; |
681 | |
681 | |
682 | $self->_new ($fh, $pid) |
682 | $self->_new ($fh, $pid) |
683 | } |
683 | } |
… | |
… | |
719 | it via C<run>. This also gives you access to any arguments passed via the |
719 | it via C<run>. This also gives you access to any arguments passed via the |
720 | C<send_xxx> methods, such as file handles. See the L<use AnyEvent::Fork as |
720 | C<send_xxx> methods, such as file handles. See the L<use AnyEvent::Fork as |
721 | a faster fork+exec> example to see it in action. |
721 | a faster fork+exec> example to see it in action. |
722 | |
722 | |
723 | Returns the process object for easy chaining of method calls. |
723 | Returns the process object for easy chaining of method calls. |
|
|
724 | |
|
|
725 | It's common to want to call an iniitalisation function with some |
|
|
726 | arguments. Make sure you actually pass C<@_> to that function (for example |
|
|
727 | by using C<&name> syntax), and do not just specify a function name: |
|
|
728 | |
|
|
729 | $proc->eval ('&MyModule::init', $string1, $string2); |
724 | |
730 | |
725 | =cut |
731 | =cut |
726 | |
732 | |
727 | sub eval { |
733 | sub eval { |
728 | my ($self, $code, @args) = @_; |
734 | my ($self, $code, @args) = @_; |