Skip Menu |

This queue is for tickets about the MikroTik-API CPAN distribution.

Report information
The Basics
Id: 113564
Status: resolved
Priority: 0/
Queue: MikroTik-API

People
Owner: MARTINGO [...] cpan.org
Requestors: lav [...] netis.ru
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.0.4



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.
Hi, I know for problems with disrupted connections. I will have a look to your patch in the next days. Thank you very much! Regards Martin
Thank you for submission, has been patched in 1.0.4