2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-19 12:46:03 +00:00

MAXLAN: fix hang on connection error

git-svn-id: https://svn.fhem.de/fhem/trunk@2527 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
mgehre 2013-01-18 12:38:29 +00:00
parent 8cab04620c
commit e8b6e3ec2a

View File

@ -27,7 +27,7 @@ my $reconnect_interval = 2; #seconds
#the time it takes after sending one command till we see its effect in the L: response #the time it takes after sending one command till we see its effect in the L: response
my $roundtriptime = 3; #seconds my $roundtriptime = 3; #seconds
my $read_timeout = 2; #seconds. How long to wait for an answer from the Cube over TCP/IP my $read_timeout = 3; #seconds. How long to wait for an answer from the Cube over TCP/IP
my $metadata_magic = 0x56; my $metadata_magic = 0x56;
my $metadata_version = 2; my $metadata_version = 2;
@ -159,6 +159,7 @@ MAXLAN_Connect($)
{ {
#Receive one "C:" per device #Receive one "C:" per device
$rmsg = MAXLAN_ReadSingleResponse($hash, 1); $rmsg = MAXLAN_ReadSingleResponse($hash, 1);
return undef if(!defined($rmsg));
MAXLAN_Parse($hash, $rmsg); MAXLAN_Parse($hash, $rmsg);
} until($rmsg =~ m/^L:/); } until($rmsg =~ m/^L:/);
#At the end, the cube sends a "L:" #At the end, the cube sends a "L:"
@ -254,7 +255,11 @@ MAXLAN_ExpectAnswer($$)
} }
##################################### #Reads single line from the Cube
#blocks if waitForResponse is true
#
#returns undef, if an error occured,
#otherwise the line
sub sub
MAXLAN_ReadSingleResponse($$) MAXLAN_ReadSingleResponse($$)
{ {
@ -273,7 +278,10 @@ MAXLAN_ReadSingleResponse($$)
#Check timeout #Check timeout
if(gettimeofday() > $maxTime) { if(gettimeofday() > $maxTime) {
Log 1, "MAXLAN_ReadSingleResponse: timeout while reading from socket" if($waitForResponse); if($waitForResponse) {
Log 1, "MAXLAN_ReadSingleResponse: timeout while reading from socket, disconnecting";
MAXLAN_Disconnect($hash);
}
return undef;; return undef;;
} }