389
|
0 |
12 |
0 |
$self->{'_tcp_server_guard'} ||= &tcp_server($host, $port, sub {
return $inner_self->_server_error($!) unless my($fh) = @_;
my $handle;
$handle = 'AnyEvent::Handle'->new('fh', $fh, 'on_error', sub {
my($hdl, $fatal, $msg) = @_;
my $SID = $inner_self->_session_id($hdl);
$inner_self->hangup_client($SID);
$inner_self->_server_error($msg, $fatal);
$hdl->destroy;
}
, 'on_eof', sub {
my($hdl) = @_;
my $SID = $inner_self->_session_id($hdl);
$inner_self->hangup_client($SID);
$hdl->destroy;
&AE::log('debug', "SERVER, client $SID disconnected.");
}
, 'on_read', sub {
my($hdl) = @_;
chomp(my $line = delete $hdl->{'rbuf'});
my $SID = $inner_self->_session_id($hdl);
foreach my $command (keys %client_commands) {
my $regex = $client_commands{$command};
if (my($args) = $line =~ /$regex/i) {
my $method = "handle_$command";
return $inner_self->$method($hdl, $SID, $args);
};
};
$hdl->push_write("UNKNOWN COMMAND, Ignored.\r\n");
}
);
my $SID = $inner_self->_session_id($handle);
$handle->push_write("EHLO Streamer (KERNEL: $$:$SID)\n");
$inner_self->register_client($SID, $handle);
}
)
|