--- src/beacon.in.orig 2004-09-07 16:36:42.000000000 +0200 +++ src/beacon.in 2005-10-26 18:08:39.000000000 +0200 @@ -125,6 +125,10 @@ my %tcp_ip_lookup; # Central Server SSRC to IP hash my %tcp_meta; # Central Server SSRC to metadata hash +my %lines; # Central server, hash of references to + # arrays of lines, one array per TCP client + + my %stats; # Where to keep the overall stats my %reports; # Count of reports from each SR during each interval my %tcp_reports; # Count of reports from each SR during each interval @@ -2967,31 +2971,51 @@ # As long as there's data pending on the connection - while (@ready = $select->can_read(1)) { - foreach $fh (@ready) { - if($fh == $server) { + # As long as there's data pending on the connection + while (@ready = $select->can_read(1)) { + NEXTFH: + foreach $fh (@ready) { + if($fh == $server) { # Create a new socket - $newsock = $server->accept; + $newsock = $server->accept; + $select->add($newsock); + } + else { + if (eof($fh)) { + undef(@{$lines{$fh}}); + $select->remove($fh); + close($fh); + next; + } + while(defined($line = <$fh>) && ($line ne $ENDMESSAGE)) { + if (!defined($lines{$fh})) { + @{$lines{$fh}} = (); + } + push(@{$lines{$fh}}, $line); + } + if (!defined($line)) { + if ($DEBUG>4) { + printf("Incomplete message, %d lines collected\n", + scalar(@{$lines{$fh}})); + } + next NEXTFH; # incomplete message, collect more later + } - $select->add($newsock); - } - else { - @lines = (); + # Here we have $line eq $ENDMESSAGE, i.e. a complete message + # has been collected, so proceed to process it + @lines = @{$lines{$fh}}; + undef(@{$lines{$fh}}); + + if ($DEBUG>4) { + printf("Processing %d lines\n", scalar(@lines)); + } + + # "scalar(@lines) is just the length of @lines -- Ie, + # loop for all lines in the array. + my $ii=0; # Simple linecounter for receiving report + while ($ii < scalar(@lines)) { - if (eof($fh)) { - $select->remove($fh); - close($fh); - next; - } - while (defined ($line = <$fh>) && ($line ne $ENDMESSAGE)) { - push(@lines, $line); - } - - # "scalar(@lines) is just the length of @lines -- Ie, loop for all lines - # in the array. - my $ii=0; # Simple linecounter for receiving report - while ($ii < scalar(@lines)) { chomp $lines[$ii]; # Whack trailing line return # First line - Authenticate! Is this valid Beacon TCP traffic?