mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-20 19:36:02 +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:
parent
e68098f571
commit
45cd402b4d
@ -141,25 +141,33 @@ DevIo_Expect($$$)
|
||||
# the device has failed to deliver a result
|
||||
DevIo_setStates($hash, "failed");
|
||||
DoTrigger($name, "FAILED");
|
||||
|
||||
# reopen device
|
||||
# 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.";
|
||||
# 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.
|
||||
Log3 $name, 2, "$name: first attempt to read timed out, ".
|
||||
"trying to close and open the device.";
|
||||
|
||||
# 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_OpenDev($hash, 0, undef); # where to get the initfn from?
|
||||
|
||||
# write something again
|
||||
return undef unless defined(DevIo_SimpleWrite($hash, $msg, 0));
|
||||
|
||||
# read answer again
|
||||
$answer= DevIo_SimpleReadWithTimeout($hash, $timeout);
|
||||
|
||||
# success
|
||||
if($answer ne "") {
|
||||
DevIo_setStates($hash, "opened");
|
||||
DoTrigger($name, "CONNECTED");
|
||||
return $answer;
|
||||
}
|
||||
|
||||
# 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");
|
||||
return undef; # undef means ultimate failure
|
||||
}
|
||||
@ -175,6 +183,11 @@ DevIo_OpenDev($$$)
|
||||
my $baudrate;
|
||||
($dev, $baudrate) = split("@", $dev);
|
||||
|
||||
if($hash->{DevIoJustClosed}) {
|
||||
delete $hash->{DevIoJustClosed};
|
||||
return;
|
||||
}
|
||||
|
||||
$hash->{PARTIAL} = "";
|
||||
Log3 $name, 3, ($hash->{DevioText} ? $hash->{DevioText} : "Opening").
|
||||
" $name device $dev" if(!$reopen);
|
||||
@ -397,6 +410,7 @@ DevIo_Disconnected($)
|
||||
DevIo_CloseDev($hash);
|
||||
$readyfnlist{"$name.$dev"} = $hash; # Start polling
|
||||
DevIo_setStates($hash, "disconnected");
|
||||
$hash->{DevIoJustClosed} = 1; # Avoid a direct reopen
|
||||
|
||||
DoTrigger($name, "DISCONNECTED");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user