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

Comparing AnyEvent-FCP/FCP.pm (file contents):
Revision 1.20 by root, Sun Jun 12 01:32:37 2016 UTC vs.
Revision 1.21 by root, Sun Jun 12 01:48:05 2016 UTC

61 61
62use common::sense; 62use common::sense;
63 63
64use Carp; 64use Carp;
65 65
66our $VERSION = 0.4; 66our $VERSION = 0.5;
67 67
68use Scalar::Util (); 68use Scalar::Util ();
69 69
70use AnyEvent; 70use AnyEvent;
71use AnyEvent::Handle; 71use AnyEvent::Handle;
126 126
127These keepalive messages are useful both to detect that a connection is 127These keepalive messages are useful both to detect that a connection is
128no longer working and to keep any (home) routers from expiring their 128no longer working and to keep any (home) routers from expiring their
129masquerading entry. 129masquerading entry.
130 130
131=item on_eof => $callback->($fcp)
132
133Invoked when the underlying L<AnyEvent::Handle> signals EOF, currently
134regardless of whether the EOF was expected or not.
135
131=item on_error => $callback->($fcp, $message) 136=item on_error => $callback->($fcp, $message)
132 137
133Invoked on any (fatal) errors, such as unexpected connection close. The 138Invoked on any (fatal) errors, such as unexpected connection close. The
134callback receives the FCP object and a textual error message. 139callback receives the FCP object and a textual error message.
135 140
136=item on_failure => $callback->($fcp, $backtrace, $args, $error) 141=item on_failure => $callback->($fcp, $type, $backtrace, $args, $error)
137 142
138Invoked when an FCP request fails that didn't have a failure callback. See 143Invoked when an FCP request fails that didn't have a failure callback. See
139L<FCP REQUESTS> for details. 144L<FCP REQUESTS> for details.
140 145
141=back 146=back
234 239
235 $self->{hdl} = new AnyEvent::Handle 240 $self->{hdl} = new AnyEvent::Handle
236 connect => [$self->{host} => $self->{port}], 241 connect => [$self->{host} => $self->{port}],
237 timeout => $self->{timeout}, 242 timeout => $self->{timeout},
238 on_read => $on_read, 243 on_read => $on_read,
239 on_eof => $self->{on_eof}, 244 on_eof => sub {
245 if ($self->{on_eof}) {
246 $self->{on_eof}($self);
247 } else {
248 $self->fatal ("EOF");
249 }
250 },
240 on_error => sub { 251 on_error => sub {
241 $self->fatal ($_[2]); 252 $self->fatal ($_[2]);
242 }, 253 },
243 ; 254 ;
244 255
434 445
435This is a popular choice, but it makes handling errors hard - make sure 446This is a popular choice, but it makes handling errors hard - make sure
436you never generate protocol errors! 447you never generate protocol errors!
437 448
438If an C<on_failure> hook exists, it will be invoked with the FCP object, 449If an C<on_failure> hook exists, it will be invoked with the FCP object,
439a (textual) backtrace as generated by C<Carp::longmess>, and arrayref 450the request type (the name of the method), a (textual) backtrace as
440containing the arguments from the original request invocation and the 451generated by C<Carp::longmess>, and arrayref containing the arguments from
441error object from the server, in this order, e.g.: 452the original request invocation and the error object from the server, in
453this order, e.g.:
442 454
443 on_failure => sub { 455 on_failure => sub {
444 my ($fcp, $backtrace, $orig_args, $error_object) = @_; 456 my ($fcp, $request_type, $backtrace, $orig_args, $error_object) = @_;
445 ... 457
458 warn "FCP failure ($type), $error_object->{code_description} ($error_object->{extra_description})$backtrace";
459 exit 1;
446 }, 460 },
447 461
448=item A condvar (as returned by e.g. C<< AnyEvent->condvar >>) 462=item A condvar (as returned by e.g. C<< AnyEvent->condvar >>)
449 463
450When a condvar is passed, it is sent (C<< $cv->send ($results) >>) the 464When a condvar is passed, it is sent (C<< $cv->send ($results) >>) the
498 my $bt = Carp::longmess "AnyEvent::FCP request $name"; 512 my $bt = Carp::longmess "AnyEvent::FCP request $name";
499 Scalar::Util::weaken (my $self = $_[0]); 513 Scalar::Util::weaken (my $self = $_[0]);
500 my $args = [@_]; shift @$args; 514 my $args = [@_]; shift @$args;
501 $err = sub { 515 $err = sub {
502 if ($self->{on_failure}) { 516 if ($self->{on_failure}) {
503 $self->{on_failure}($self, $args, $bt, $_[0]); 517 $self->{on_failure}($self, $name, $args, $bt, $_[0]);
504 } else { 518 } else {
505 die "$_[0]{code_description} ($_[0]{extra_description})$bt"; 519 die "$_[0]{code_description} ($_[0]{extra_description})$bt";
506 } 520 }
507 }; 521 };
508 } 522 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines