… | |
… | |
152 | |
152 | |
153 | # now $master_filehandle is connected to the |
153 | # now $master_filehandle is connected to the |
154 | # $slave_filehandle in the new process. |
154 | # $slave_filehandle in the new process. |
155 | }); |
155 | }); |
156 | |
156 | |
157 | # MyModule::worker might look like this |
157 | MyModule might look like this: |
|
|
158 | |
|
|
159 | package MyModule; |
|
|
160 | |
158 | sub MyModule::worker { |
161 | sub worker { |
159 | my ($slave_filehandle) = @_; |
162 | my ($slave_filehandle) = @_; |
160 | |
163 | |
161 | # now $slave_filehandle is connected to the $master_filehandle |
164 | # now $slave_filehandle is connected to the $master_filehandle |
162 | # in the original prorcess. have fun! |
165 | # in the original prorcess. have fun! |
163 | } |
166 | } |
… | |
… | |
182 | } |
185 | } |
183 | |
186 | |
184 | # now do other things - maybe use the filehandle provided by run |
187 | # now do other things - maybe use the filehandle provided by run |
185 | # to wait for the processes to die. or whatever. |
188 | # to wait for the processes to die. or whatever. |
186 | |
189 | |
187 | # My::Server::run might look like this |
190 | My::Server might look like this: |
188 | sub My::Server::run { |
191 | |
|
|
192 | package My::Server; |
|
|
193 | |
|
|
194 | sub run { |
189 | my ($slave, $listener, $id) = @_; |
195 | my ($slave, $listener, $id) = @_; |
190 | |
196 | |
191 | close $slave; # we do not use the socket, so close it to save resources |
197 | close $slave; # we do not use the socket, so close it to save resources |
192 | |
198 | |
193 | # we could go ballistic and use e.g. AnyEvent here, or IO::AIO, |
199 | # we could go ballistic and use e.g. AnyEvent here, or IO::AIO, |
… | |
… | |
560 | Normally, only processes created via C<< AnyEvent::Fork->new_exec >> and |
566 | Normally, only processes created via C<< AnyEvent::Fork->new_exec >> and |
561 | L<AnyEvent::Fork::Template> are direct children, and you are responsible |
567 | L<AnyEvent::Fork::Template> are direct children, and you are responsible |
562 | to clean up their zombies when they die. |
568 | to clean up their zombies when they die. |
563 | |
569 | |
564 | All other processes are not direct children, and will be cleaned up by |
570 | All other processes are not direct children, and will be cleaned up by |
565 | AnyEvent::Fork. |
571 | AnyEvent::Fork itself. |
566 | |
572 | |
567 | =cut |
573 | =cut |
568 | |
574 | |
569 | sub pid { |
575 | sub pid { |
570 | $_[0][0] |
576 | $_[0][0] |