… | |
… | |
320 | |
320 | |
321 | # everything written |
321 | # everything written |
322 | undef $self->[3]; |
322 | undef $self->[3]; |
323 | |
323 | |
324 | # invoke run callback, if any |
324 | # invoke run callback, if any |
325 | $self->[0]->($self->[1]) if $self->[0]; |
325 | $self->[4]->($self->[1]) if $self->[4]; |
326 | }; |
326 | }; |
327 | |
327 | |
328 | () # make sure we don't leak the watcher |
328 | () # make sure we don't leak the watcher |
329 | } |
329 | } |
330 | |
330 | |
… | |
… | |
332 | my ($self, $fh, $pid) = @_; |
332 | my ($self, $fh, $pid) = @_; |
333 | |
333 | |
334 | AnyEvent::Util::fh_nonblocking $fh, 1; |
334 | AnyEvent::Util::fh_nonblocking $fh, 1; |
335 | |
335 | |
336 | $self = bless [ |
336 | $self = bless [ |
337 | undef, # run callback |
337 | $pid, |
338 | $fh, |
338 | $fh, |
339 | [], # write queue - strings or fd's |
339 | [], # write queue - strings or fd's |
340 | undef, # AE watcher |
340 | undef, # AE watcher |
341 | $pid, |
|
|
342 | ], $self; |
341 | ], $self; |
343 | |
342 | |
344 | $self |
343 | $self |
345 | } |
344 | } |
346 | |
345 | |
… | |
… | |
473 | ) or die "unable to spawn AnyEvent::Fork server: $!"; |
472 | ) or die "unable to spawn AnyEvent::Fork server: $!"; |
474 | |
473 | |
475 | $self->_new ($fh, $pid) |
474 | $self->_new ($fh, $pid) |
476 | } |
475 | } |
477 | |
476 | |
|
|
477 | =item $pid = $proc->pid |
|
|
478 | |
|
|
479 | Returns the process id of the process I<iff it is a direct child of the |
|
|
480 | process> running AnyEvent::Fork, and C<undef> otherwise. |
|
|
481 | |
|
|
482 | Normally, only processes created via C<< AnyEvent::Fork->new_exec >> and |
|
|
483 | L<AnyEvent::Fork::Template> are direct children, and you are responsible |
|
|
484 | to clean up their zombies when they die. |
|
|
485 | |
|
|
486 | All other processes are not direct children, and will be cleaned up by |
|
|
487 | AnyEvent::Fork. |
|
|
488 | |
|
|
489 | =cut |
|
|
490 | |
|
|
491 | sub pid { |
|
|
492 | $_[0][0] |
|
|
493 | } |
|
|
494 | |
478 | =item $proc = $proc->eval ($perlcode, @args) |
495 | =item $proc = $proc->eval ($perlcode, @args) |
479 | |
496 | |
480 | Evaluates the given C<$perlcode> as ... perl code, while setting C<@_> to |
497 | Evaluates the given C<$perlcode> as ... perl code, while setting C<@_> to |
481 | the strings specified by C<@args>. |
498 | the strings specified by C<@args>. |
482 | |
499 | |
… | |
… | |
628 | =cut |
645 | =cut |
629 | |
646 | |
630 | sub run { |
647 | sub run { |
631 | my ($self, $func, $cb) = @_; |
648 | my ($self, $func, $cb) = @_; |
632 | |
649 | |
633 | $self->[0] = $cb; |
650 | $self->[4] = $cb; |
634 | $self->_cmd (r => $func); |
651 | $self->_cmd (r => $func); |
635 | } |
652 | } |
636 | |
653 | |
637 | =back |
654 | =back |
638 | |
655 | |