Subject: | a problem with EOF on tcp connection |
Date: | Mon, 4 Apr 2016 17:11:32 +0300 |
To: | bug-MikroTik-API [...] rt.cpan.org |
From: | "Alexander V. Lukyanov" <lav [...] netis.ru> |
Hello!
It seems that MikroTik::API loops forever over _read_sentence when the TCP
connection is closed and _read_word gets nothing (an empty string).
This patch may fix the problem (but it needs more testing).
diff --git a/lib/MikroTik/API.pm b/lib/MikroTik/API.pm
index 4337c25..809ee85 100644
--- a/lib/MikroTik/API.pm
+++ b/lib/MikroTik/API.pm
@@ -381,6 +381,7 @@ sub talk {
my $retval = 0;
while ( ( $retval, @reply ) = $self->_read_sentence() ) {
+ last if !defined $retval;
my %dataset;
foreach my $line ( @reply ) {
if ( my ($key, $value) = ( $line =~ /^=([^=]+)=(.*)/s ) ) {
@@ -484,7 +485,7 @@ sub _read_sentence {
my ( $self ) = @_;
my ( @reply );
- my $retval = 0;
+ my $retval;
while ( my $word = $self->_read_word() ) {
if ($word =~ /!done/) {
@@ -496,6 +497,9 @@ sub _read_sentence {
elsif ($word =~ /!fatal/) {
$retval = 3;
}
+ else
+ $retval //= 0;
+ }
push( @reply, $word );
if ( $self->get_debug() > 2 ) {
print "<<< $word\n"
--
Alexander.