2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-20 07:16:03 +00:00

DevIo.pm: Fix the original 5s delay after disappear (Forum #36215)

git-svn-id: https://svn.fhem.de/fhem/trunk@8576 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2015-05-14 11:16:10 +00:00
parent e68098f571
commit 45cd402b4d

View File

@ -141,25 +141,33 @@ DevIo_Expect($$$)
# the device has failed to deliver a result # the device has failed to deliver a result
DevIo_setStates($hash, "failed"); DevIo_setStates($hash, "failed");
DoTrigger($name, "FAILED"); DoTrigger($name, "FAILED");
# reopen device # reopen device
# unclear how to know whether the following succeeded # unclear how to know whether the following succeeded
Log3 $name, 2, "$name: first attempt to read timed out, trying to close and open the device."; Log3 $name, 2, "$name: first attempt to read timed out, ".
# The next two lines are required to avoid a deadlock when the remote end closes the connection "trying to close and open the device.";
# upon DevIo_OpenDev, as e.g. netcat -l <port> does.
# The next two lines are required to avoid a deadlock when the remote end
# closes the connection upon DevIo_OpenDev, as e.g. netcat -l <port> does.
DevIo_CloseDev($hash); DevIo_CloseDev($hash);
DevIo_OpenDev($hash, 0, undef); # where to get the initfn from? DevIo_OpenDev($hash, 0, undef); # where to get the initfn from?
# write something again # write something again
return undef unless defined(DevIo_SimpleWrite($hash, $msg, 0)); return undef unless defined(DevIo_SimpleWrite($hash, $msg, 0));
# read answer again # read answer again
$answer= DevIo_SimpleReadWithTimeout($hash, $timeout); $answer= DevIo_SimpleReadWithTimeout($hash, $timeout);
# success # success
if($answer ne "") { if($answer ne "") {
DevIo_setStates($hash, "opened"); DevIo_setStates($hash, "opened");
DoTrigger($name, "CONNECTED"); DoTrigger($name, "CONNECTED");
return $answer; return $answer;
} }
# ultimate failure # ultimate failure
Log3 $name, 2, "$name: second attempt to read timed out, this is an unrecoverable error."; Log3 $name, 2,
"$name: second attempt to read timed out, this is an unrecoverable error.";
DoTrigger($name, "DISCONNECTED"); DoTrigger($name, "DISCONNECTED");
return undef; # undef means ultimate failure return undef; # undef means ultimate failure
} }
@ -175,6 +183,11 @@ DevIo_OpenDev($$$)
my $baudrate; my $baudrate;
($dev, $baudrate) = split("@", $dev); ($dev, $baudrate) = split("@", $dev);
if($hash->{DevIoJustClosed}) {
delete $hash->{DevIoJustClosed};
return;
}
$hash->{PARTIAL} = ""; $hash->{PARTIAL} = "";
Log3 $name, 3, ($hash->{DevioText} ? $hash->{DevioText} : "Opening"). Log3 $name, 3, ($hash->{DevioText} ? $hash->{DevioText} : "Opening").
" $name device $dev" if(!$reopen); " $name device $dev" if(!$reopen);
@ -397,6 +410,7 @@ DevIo_Disconnected($)
DevIo_CloseDev($hash); DevIo_CloseDev($hash);
$readyfnlist{"$name.$dev"} = $hash; # Start polling $readyfnlist{"$name.$dev"} = $hash; # Start polling
DevIo_setStates($hash, "disconnected"); DevIo_setStates($hash, "disconnected");
$hash->{DevIoJustClosed} = 1; # Avoid a direct reopen
DoTrigger($name, "DISCONNECTED"); DoTrigger($name, "DISCONNECTED");
} }