… | |
… | |
550 | undef $rw; undef $ww; # it ends here |
550 | undef $rw; undef $ww; # it ends here |
551 | |
551 | |
552 | if (@rcb || %rcb) { |
552 | if (@rcb || %rcb) { |
553 | $on_error->("unexpected eof"); |
553 | $on_error->("unexpected eof"); |
554 | } else { |
554 | } else { |
555 | $on_destroy->(); |
555 | $on_destroy->() |
|
|
556 | if $on_destroy; |
556 | } |
557 | } |
557 | } elsif ($! != Errno::EAGAIN && $! != Errno::EWOULDBLOCK) { |
558 | } elsif ($! != Errno::EAGAIN && $! != Errno::EWOULDBLOCK) { |
558 | undef $rw; undef $ww; # it ends here |
559 | undef $rw; undef $ww; # it ends here |
559 | $on_error->("read: $!"); |
560 | $on_error->("read: $!"); |
560 | } |
561 | } |
… | |
… | |
563 | $ww ||= AE::io $fh, 1, $wcb; |
564 | $ww ||= AE::io $fh, 1, $wcb; |
564 | }); |
565 | }); |
565 | |
566 | |
566 | my $guard = Guard::guard { |
567 | my $guard = Guard::guard { |
567 | $shutdown = 1; |
568 | $shutdown = 1; |
568 | $ww ||= $fh && AE::io $fh, 1, $wcb; |
569 | |
|
|
570 | shutdown $fh, 1 if $fh && !$ww; |
569 | }; |
571 | }; |
570 | |
572 | |
571 | my $id; |
573 | my $id; |
572 | |
574 | |
573 | $arg{async} |
575 | $arg{async} |
… | |
… | |
575 | $id = ($id == 0xffffffff ? 0 : $id) + 1; |
577 | $id = ($id == 0xffffffff ? 0 : $id) + 1; |
576 | $id = ($id == 0xffffffff ? 0 : $id) + 1 while exists $rcb{$id}; # rarely loops |
578 | $id = ($id == 0xffffffff ? 0 : $id) + 1 while exists $rcb{$id}; # rarely loops |
577 | |
579 | |
578 | $rcb{$id} = pop; |
580 | $rcb{$id} = pop; |
579 | |
581 | |
580 | $guard; # keep it alive |
582 | $guard if 0; # keep it alive |
581 | |
583 | |
582 | $wbuf .= pack "LL/a*", $id, &$f; |
584 | $wbuf .= pack "LL/a*", $id, &$f; |
583 | $ww ||= $fh && AE::io $fh, 1, $wcb; |
585 | $ww ||= $fh && AE::io $fh, 1, $wcb; |
584 | } |
586 | } |
585 | : sub { |
587 | : sub { |
… | |
… | |
771 | |
773 | |
772 | Of course, this might be blocking if you pass a lot of file descriptors, |
774 | Of course, this might be blocking if you pass a lot of file descriptors, |
773 | so you might want to look into L<AnyEvent::FDpasser> which can handle the |
775 | so you might want to look into L<AnyEvent::FDpasser> which can handle the |
774 | gory details. |
776 | gory details. |
775 | |
777 | |
|
|
778 | =head1 EXCEPTIONS |
|
|
779 | |
|
|
780 | There are no provisions whatsoever for catching exceptions at this time - |
|
|
781 | in the child, exeptions might kill the process, causing calls to be lost |
|
|
782 | and the parent encountering a fatal error. In the parent, exceptions in |
|
|
783 | the result callback will not be caught and cause undefined behaviour. |
|
|
784 | |
776 | =head1 SEE ALSO |
785 | =head1 SEE ALSO |
777 | |
786 | |
778 | L<AnyEvent::Fork>, to create the processes in the first place. |
787 | L<AnyEvent::Fork>, to create the processes in the first place. |
779 | |
788 | |
780 | L<AnyEvent::Fork::Pool>, to manage whole pools of processes. |
789 | L<AnyEvent::Fork::Pool>, to manage whole pools of processes. |