From e8b6e3ec2af51461b5d08d7346b4b0892bd7ce11 Mon Sep 17 00:00:00 2001 From: mgehre <> Date: Fri, 18 Jan 2013 12:38:29 +0000 Subject: [PATCH] MAXLAN: fix hang on connection error git-svn-id: https://svn.fhem.de/fhem/trunk@2527 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_MAXLAN.pm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fhem/FHEM/00_MAXLAN.pm b/fhem/FHEM/00_MAXLAN.pm index ef0f34310..dbbc8fff8 100755 --- a/fhem/FHEM/00_MAXLAN.pm +++ b/fhem/FHEM/00_MAXLAN.pm @@ -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 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_version = 2; @@ -159,6 +159,7 @@ MAXLAN_Connect($) { #Receive one "C:" per device $rmsg = MAXLAN_ReadSingleResponse($hash, 1); + return undef if(!defined($rmsg)); MAXLAN_Parse($hash, $rmsg); } until($rmsg =~ m/^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 MAXLAN_ReadSingleResponse($$) { @@ -273,7 +278,10 @@ MAXLAN_ReadSingleResponse($$) #Check timeout 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;; }