99
|
0 |
1 |
0 |
$self->{'_client'} ||= &tcp_connect($addr, $port, sub {
&AE::log('fatal', "Connect failed: $!") unless my($fh) = @_;
my $hdl;
$hdl = 'AnyEvent::Handle'->new('fh', $fh, 'on_error', sub {
&AE::log('error', $_[2]);
$_[0]->destroy;
$inner_self->{'_reconnect_timer'} = &AE::timer(10, 0, sub {
undef $inner_self->{'_reconnect_timer'};
$inner_self->_connect;
}
);
}
, 'on_eof', sub {
$hdl->destroy;
&AE::log('info', 'Done.');
}
, 'on_read', sub {
$hdl->push_read('line', sub {
my($hdl, $line) = @_;
return if &List::Util::first(sub {
substr($line, 0, length $_) eq $_;
}
, @PROTOCOL_LINE_PREFIXES);
$inner_self->handle_message($line, $hdl);
}
);
}
);
$inner_self->{'buffer'} = '';
$inner_self->{'_setup_pipe_timer'} = &AE::timer(0, 0, sub {
undef $inner_self->{'_setup_pipe_timer'};
$inner_self->setup_pipe($hdl);
}
);
}
)
|