2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

Add new ReadyFn Function for external ready check

set default timeout for select to 0.2s, if nothing else came out from HandleTimeout()


git-svn-id: https://svn.fhem.de/fhem/trunk@175 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
tdressler 2008-05-11 17:27:01 +00:00
parent c4411ba2c3
commit 9e2e97b3f0

View File

@ -103,7 +103,8 @@ sub CommandTrigger($$);
# StateFn - set local info for this device, do not activate anything # StateFn - set local info for this device, do not activate anything
# TimeFn - if the TRIGGERTIME of a device is reached, call this function # TimeFn - if the TRIGGERTIME of a device is reached, call this function
# NotifyFn - call this if some device changed its properties # NotifyFn - call this if some device changed its properties
# ReadFn - Reading from a filedescriptor (see FHZ/WS300) # ReadyFn - check for available data, if no FD
# ReadFn - Reading from a Device (see FHZ/WS300)
#Special values in %defs: #Special values in %defs:
# TYPE - The name of the module it belongs to # TYPE - The name of the module it belongs to
@ -139,7 +140,7 @@ my %intAt; # Internal at timer hash.
my $intAtCnt=0; my $intAtCnt=0;
my $reread_active = 0; my $reread_active = 0;
my $AttrList = "room comment"; my $AttrList = "room comment";
my $cvsid = '$Id: fhem.pl,v 1.42 2008-05-09 13:58:10 rudolfkoenig Exp $'; my $cvsid = '$Id: fhem.pl,v 1.43 2008-05-11 17:27:01 tdressler Exp $';
$init_done = 0; $init_done = 0;
@ -263,6 +264,7 @@ Log 0, "Server started (version $attr{global}{version}, pid $$)";
################################################ ################################################
# Main Loop # Main Loop
MAIN:
while (1) { while (1) {
my ($rout, $rin) = ('', ''); my ($rout, $rin) = ('', '');
@ -273,8 +275,8 @@ while (1) {
foreach my $c (keys %client) { foreach my $c (keys %client) {
vec($rin, fileno($client{$c}{fd}), 1) = 1; vec($rin, fileno($client{$c}{fd}), 1) = 1;
} }
my $timeout=HandleTimeout()||0.2;#0.2s if nothing else defined
my $nfound = select($rout=$rin, undef, undef, HandleTimeout()); my $nfound = select($rout=$rin, undef, undef, $timeout);
CommandShutdown(undef, undef) if($sig_term); CommandShutdown(undef, undef) if($sig_term);
@ -284,11 +286,13 @@ while (1) {
} }
############################### ###############################
# Message from the hardware (FHZ1000/WS3000/etc) # Message from the hardware (FHZ1000/WS3000/etc) via FD or from Ready Function
foreach my $p (keys %defs) { foreach my $p (keys %defs) {
next if(!$defs{$p}{FD} || !vec($rout, $defs{$p}{FD}, 1)); my $ready=CallFn($p,"ReadyFn",$defs{$p}) if ($modules{$p}{ReadyFn});
if(($defs{$p}{FD} && vec($rout, $defs{$p}{FD}, 1)) || $ready) {
CallFn($p, "ReadFn", $defs{$p}); CallFn($p, "ReadFn", $defs{$p});
} }
}
if(vec($rout, $server->fileno(), 1)) { if(vec($rout, $server->fileno(), 1)) {
my @clientinfo = $server->accept(); my @clientinfo = $server->accept();