… | |
… | |
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 | |
158 | |
|
|
159 | package MyModule; |
|
|
160 | |
159 | sub MyModule::worker { |
161 | sub worker { |
160 | my ($slave_filehandle) = @_; |
162 | my ($slave_filehandle) = @_; |
161 | |
163 | |
162 | # now $slave_filehandle is connected to the $master_filehandle |
164 | # now $slave_filehandle is connected to the $master_filehandle |
163 | # in the original prorcess. have fun! |
165 | # in the original prorcess. have fun! |
164 | } |
166 | } |
… | |
… | |
183 | } |
185 | } |
184 | |
186 | |
185 | # now do other things - maybe use the filehandle provided by run |
187 | # now do other things - maybe use the filehandle provided by run |
186 | # to wait for the processes to die. or whatever. |
188 | # to wait for the processes to die. or whatever. |
187 | |
189 | |
188 | My::Server::run might look like this: |
190 | My::Server might look like this: |
189 | |
191 | |
190 | sub My::Server::run { |
192 | package My::Server; |
|
|
193 | |
|
|
194 | sub run { |
191 | my ($slave, $listener, $id) = @_; |
195 | my ($slave, $listener, $id) = @_; |
192 | |
196 | |
193 | 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 |
194 | |
198 | |
195 | # 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, |