1 | #!/opt/bin/perl |
1 | #!/OPT/BIn/perl |
2 | |
2 | |
3 | =head1 NAME |
3 | =head1 NAME |
4 | |
4 | |
5 | aemp - AnyEvent:MP utility |
5 | aemp - AnyEvent:MP utility |
6 | |
6 | |
… | |
… | |
453 | sub trace { |
453 | sub trace { |
454 | my ($node) = @_; |
454 | my ($node) = @_; |
455 | my $cv = AE::cv; |
455 | my $cv = AE::cv; |
456 | my %seen; |
456 | my %seen; |
457 | |
457 | |
458 | my $to = AE::timer 15, 0, sub { |
458 | my $to = AE::timer 15, 0, sub { exit 1 }; |
459 | warn "timeout\n"; |
|
|
460 | $cv->(); |
|
|
461 | }; |
|
|
462 | |
459 | |
463 | init; |
460 | init; |
464 | |
461 | |
465 | my $reply = port { |
462 | my $reply = port { |
466 | my ($node, @neigh) = @_; |
463 | my ($node, @neigh) = @_; |
… | |
… | |
493 | init; |
490 | init; |
494 | |
491 | |
495 | snd $port, @ARGV; @ARGV = (); |
492 | snd $port, @ARGV; @ARGV = (); |
496 | |
493 | |
497 | my $cv = AE::cv; |
494 | my $cv = AE::cv; |
498 | my $to = AE::timer 5, 0, sub { $cv->("timeout") }; |
495 | my $to = AE::timer 5, 0, sub { exit 1 }; |
499 | mon $port, $cv; |
496 | mon $port, $cv; |
500 | my $reply = port sub { &$cv }; |
497 | my $reply = port sub { &$cv }; |
501 | snd node_of $port, snd => $reply, "message sent successfully"; |
498 | snd node_of $port, snd => $reply, "message sent successfully"; |
502 | |
499 | |
503 | print join " ", $cv->recv, "\n"; |
500 | print join " ", $cv->recv, "\n"; |
… | |
… | |
506 | rpc => sub { |
503 | rpc => sub { |
507 | my $port = shift @ARGV; |
504 | my $port = shift @ARGV; |
508 | init; |
505 | init; |
509 | |
506 | |
510 | my $cv = AE::cv; |
507 | my $cv = AE::cv; |
511 | my $to = AE::timer 5, 0, sub { $cv->("timeout") }; |
508 | my $to = AE::timer 5, 0, sub { exit 1 }; |
512 | snd $port, @ARGV, port { &$cv }; @ARGV = (); |
509 | snd $port, @ARGV, port { &$cv }; @ARGV = (); |
513 | mon $port, $cv; |
510 | mon $port, $cv; |
514 | |
511 | |
515 | print +(substr JSON::XS->new->encode ([$cv->recv]), 1, -1), "\n"; |
512 | print +(substr JSON::XS->new->encode ([$cv->recv]), 1, -1), "\n"; |
516 | }, |
513 | }, |
… | |
… | |
527 | my $node = node_of shift @ARGV; |
524 | my $node = node_of shift @ARGV; |
528 | my $expr = join " ", @ARGV; @ARGV = (); |
525 | my $expr = join " ", @ARGV; @ARGV = (); |
529 | init; |
526 | init; |
530 | |
527 | |
531 | my $cv = AE::cv; |
528 | my $cv = AE::cv; |
532 | my $to = AE::timer 5, 0, sub { $cv->("timeout") }; |
529 | my $to = AE::timer 5, 0, sub { exit 1 }; |
533 | AnyEvent::MP::Kernel::eval_on $node, $expr, port { &$cv }; |
530 | AnyEvent::MP::Kernel::eval_on $node, $expr, port { &$cv }; |
534 | mon $node, $cv; |
531 | mon $node, $cv; |
535 | |
532 | |
536 | my ($err, @res) = $cv->recv; |
533 | my ($err, @res) = $cv->recv; |
537 | |
534 | |