ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-Fork-RPC/RPC.pm
(Generate patch)

Comparing AnyEvent-Fork-RPC/RPC.pm (file contents):
Revision 1.16 by root, Thu Apr 18 14:07:15 2013 UTC vs.
Revision 1.20 by root, Sat Apr 20 16:07:40 2013 UTC

1=head1 NAME 1=head1 NAME
2 2
3AnyEvent::Fork::RPC - simple RPC extension for AnyEvent::Fork 3AnyEvent::Fork::RPC - simple RPC extension for AnyEvent::Fork
4
5THE API IS NOT FINISHED, CONSIDER THIS A TECHNOLOGY DEMO
4 6
5=head1 SYNOPSIS 7=head1 SYNOPSIS
6 8
7 use AnyEvent::Fork::RPC; 9 use AnyEvent::Fork::RPC;
8 # use AnyEvent::Fork is not needed 10 # use AnyEvent::Fork is not needed
548 undef $rw; undef $ww; # it ends here 550 undef $rw; undef $ww; # it ends here
549 551
550 if (@rcb || %rcb) { 552 if (@rcb || %rcb) {
551 $on_error->("unexpected eof"); 553 $on_error->("unexpected eof");
552 } else { 554 } else {
553 $on_destroy->(); 555 $on_destroy->()
556 if $on_destroy;
554 } 557 }
555 } elsif ($! != Errno::EAGAIN && $! != Errno::EWOULDBLOCK) { 558 } elsif ($! != Errno::EAGAIN && $! != Errno::EWOULDBLOCK) {
556 undef $rw; undef $ww; # it ends here 559 undef $rw; undef $ww; # it ends here
557 $on_error->("read: $!"); 560 $on_error->("read: $!");
558 } 561 }
561 $ww ||= AE::io $fh, 1, $wcb; 564 $ww ||= AE::io $fh, 1, $wcb;
562 }); 565 });
563 566
564 my $guard = Guard::guard { 567 my $guard = Guard::guard {
565 $shutdown = 1; 568 $shutdown = 1;
566 $ww ||= $fh && AE::io $fh, 1, $wcb; 569
570 shutdown $fh, 1 if $fh && !$ww;
567 }; 571 };
568 572
569 my $id; 573 my $id;
570 574
571 $arg{async} 575 $arg{async}
573 $id = ($id == 0xffffffff ? 0 : $id) + 1; 577 $id = ($id == 0xffffffff ? 0 : $id) + 1;
574 $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
575 579
576 $rcb{$id} = pop; 580 $rcb{$id} = pop;
577 581
578 $guard; # keep it alive 582 $guard if 0; # keep it alive
579 583
580 $wbuf .= pack "LL/a*", $id, &$f; 584 $wbuf .= pack "LL/a*", $id, &$f;
581 $ww ||= $fh && AE::io $fh, 1, $wcb; 585 $ww ||= $fh && AE::io $fh, 1, $wcb;
582 } 586 }
583 : sub { 587 : sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines