- 论坛徽章:
- 3
|
本帖最后由 墨迹哥 于 2013-10-24 13:17 编辑
@laputa73
之前邮件里跟你说了。。。
后来你没回邮件,我就直接在这发吧,也没啥见不得人的。
不知道为什么,现在都不能入库了,续倒是续上去了。。- #!/usr/bin/perl
- use IO::Socket;
- use IO::Select;
- use DBI;
- use Config::Abstract::Ini;
- eval{
- my $cfg=new Config::Abstract::Ini("config.ini");
- %Data=$cfg->get_entry('mysql');
- };
- $|++;
- my $socket=IO::Socket::INET->new(LocalAddr =>'192.168.31.167',
- LocalPort =>9981,
- Listen =>5,
- Proto =>'tcp') or die $@;
- my $read_set=new IO::Select();
- $read_set->add($socket);
- while(1){
- my ($rh_set) = IO::Select->select($read_set, undef, undef, undef);
- foreach my $rh (@$rh_set){
- if($rh == $socket){
- my $ns = $rh->accept();
- $read_set->add($ns);
- }else{
- $buf = $bufall{$rh}.$buf; #补上之前的未完部分
- #my ($buf1,$buf2)=split /\n|\r\n/, $buf; #分开完整行和不完整行
- my $pos=rindex($buf,"\n");
- my $buf1=substr($buf,0,$pos);
- my $buf2=substr($buf,$pos+1);
- $bufall{$rh}=$buf2; #保存未完整行部分
- $buf=$buf1; #处理完整部分,可能是多行,需要后续处理考虑
- print "[buf]$buf.\n";
- if (sysread($rh,$buf,1024)){
- @ack=split(/\|/,$buf);
- if(@ack[0]=~m#t:(.*)#){
- $type=$1;
- $log_type=type_result($type);
- }
- if(@ack[1]=~m#me:(.*)#){
- $method=$1;
- %log_result=log_result($method);
- }
- if(@ack[2]=~m#so:(.*)#){
- $source=$1;
- }
- if(@ack[3]=~m#lo:(.*)#){
- $local=$1;
- }
- if(@ack[4]=~m#da:(.*)#){
- $date=$1;
- }
- if(@ack[5]=~m#ti:(.*)#){
- $time=$1;
- }
- if(@ack[6]=~m#opt:(.*)#){
- $option=$1;
- }
- if(@ack[7]=~m#of:(.*)#){
- $offer=$1;
- }
- #如果触发规则
- if(%log_result){
- print "触发规则了,入库!\n";
- if(get_result_db($log_type,$log_result{'id'},$method,$source,$local,result_data($date,$time),$option,$offer) eq 'true')
- {
- if($log_result{'level'}==1){
- if(update_report_item(1,report_info($local)) eq 'false'){
- print "Error:Data Update No sucessful for report, level one!\n";
- }
- }elsif($log_result{'level'}==2){
- if(update_report_item(2,report_info($local)) eq 'false'){
- print "Error:Data Update No sucessful for report, level two!\n";
- }
- }elsif($log_result{'level'}==3){
- if(update_report_item(3,report_info($local)) eq 'false'){
- print "Error:Data Update No sucessful for report, level three!\n";
- }
- }
- }else{
- print "Error:Data insert No sucessful!\n";
- }
- }
- }else{
- print "数据传送完!\n";
- $read_set->remove($rh);
- $rh->close;
- }
- }
- }
- }
复制代码 |
|