Win32 POE FollowTail strange Behaviour

[email protected] ("Alberto (WarfoX) De Boni") Sat, 14 Jan 2012 11:25:26 +0100
Newsgroups perl.poe
Message-ID <[email protected]>
Hi all,
    i've started to use POE for logging event on various sistems. Now, 
i'm facing the problem to track a log file, being written by a power 
inverter control software, on a Windows machine
The control sofware create the log file as soon as the inverter starts 
to perform operations (we're talking about a PV control system). 
Considering that i've used the "Filename" watch which documentation 
says: Specify the|Filename|to watch. POE::Wheel::FollowTail will wait 
for the file to appear if it doesn't exist.

The issue happens as soon as file appears, it seems that the application 
goes in an infinite loop calling log_got_line. The only way is to stop 
the application.

Am i missing something?
Thanks in advance for any hints.

Alberto De Boni


Here the application.

use warnings;
use strict;

# Include POE and POE::Component::Server::TCP.

use POE qw(Component::Server::TCP);
use POE qw/Wheel::FollowTail/;

use constant port => 10240;

my $currentPower;
my $totalProduction;

my @timeData = localtime(time);


my $year = 1900+$timeData[5];
my $month = 1+$timeData[4];
my $day = $timeData[3];

my $log_file = "C:\\inverter\\".$year."-".$month."-".$day.".log";

print "START LOG OPERATION\n\n";
print "Logging $log_file\n";

# Start a TCP server.  Client input will be logged to the console and
# echoed back to the client, one line at a time.

POE::Component::Server::TCP->new(
   Alias       => "PVMonitor",
   Port        => port,
   ClientInput => sub {
     my ($session, $heap, $input) = @_[SESSION, HEAP, ARG0];
     print "Session ", $session->ID(), " got input: $input\n";
     if ($input eq "DATA"){
     my $answer = $currentPower.";".$totalProduction;
     $heap->{client}->put($answer);
     }
   }
);


POE::Session->create
(
     inline_states =>{
       _start => sub {
         $_[HEAP]->{wheel} = POE::Wheel::FollowTail->new(
                 Filename   => $log_file,
                 InputEvent => 'got_line',
                 ErrorEvent => 'got_error',
                 #SeekBack   => 2048,
                 ResetEvent => 'log_reset',

               );
             $_[HEAP]->{first} = 0;
         },
     got_line => \&log_got_line,,
         got_error => sub { warn "$_[ARG0]\n" },
         log_reset => \&got_log_reset,
     },
         args=> $log_file,
   );


sub got_log_reset{
    my ($heap, $wheel_id) = @_[HEAP, ARG0];
    my $service = $heap->{services}->{$wheel_id};
}
# Start the server.
sub log_got_line{
   if ($_[HEAP]->{first}++){
     my @splitted = split (';', $_[ARG0]);
     #print "$_[ARG0]\n" ;
     print "$splitted[0]\n";
     $currentPower=$splitted[12];
     $totalProduction=$splitted[15];
   }
}
$poe_kernel->run();
exit 0;