Hide the call to error_cb in a new method _log_error, API changes:

The new error_cb will still receive the same two first parameters, the
connection object and the raw error, but will also receive a third
parameter, more user friendly error message.

Signed-off-by: Pedro Melo <melo@simplicidade.org>
This commit is contained in:
Pedro Melo
2014-07-20 17:38:11 +01:00
parent bfa5a905d7
commit 522f4e1670

View File

@@ -59,8 +59,6 @@ sub connect {
my ($self) = @_;
return if $self->{handle};
my $err_cb = $self->{error_cb};
$self->{handle} = AnyEvent::Handle->new(
connect => [$self->{host}, $self->{port}],
@@ -69,11 +67,11 @@ sub connect {
on_connect_error => sub {
$self->_disconnected;
$err_cb->($self, '(connect) ' . ($_[1] || $!));
$self->_log_error('(connect failed) ' . ($_[1] || $!));
},
on_error => sub {
$self->_disconnected;
$err_cb->($self, '(read) ' . ($_[2] || $!));
$self->_log_error('(read error) ' . ($_[2] || $!));
},
on_eof => sub {
$self->_disconnected;
@@ -311,4 +309,13 @@ sub _on_success_frame {
}
## Error logging
sub _log_error {
my ($self, $err) = @_;
$self->{error_cb}->($err, qq{FATAL: dropping connection to host '$self->{host}' port $self->{port}, reason: $err});
return;
}
1;