mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-12 16:46:35 +00:00
00_MQTT2_SERVER.pm: add NRCLIENTS, set state. global/FileLog: add FD (Forum #90145)
git-svn-id: https://svn.fhem.de/fhem/trunk@17124 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
770280a055
commit
457cb2e9cc
@ -61,6 +61,7 @@ MQTT2_SERVER_Define($$)
|
||||
Log3 $hash, 1, "$ret. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
$hash->{NRCLIENTS} = 0;
|
||||
$hash->{clients} = {};
|
||||
$hash->{retain} = {};
|
||||
InternalTimer(1, "MQTT2_SERVER_keepaliveChecker", $hash, 0);
|
||||
@ -89,12 +90,14 @@ MQTT2_SERVER_Undef($@)
|
||||
my $ret = TcpServer_Close($hash);
|
||||
my $sname = $hash->{SNAME};
|
||||
return undef if(!$sname);
|
||||
delete($defs{$sname}{clients}{$hash->{NAME}});
|
||||
|
||||
my $shash = $defs{$sname};
|
||||
delete($shash->{clients}{$hash->{NAME}});
|
||||
$shash->{NRCLIENTS}--;
|
||||
|
||||
if($hash->{lwt}) { # Last will
|
||||
my ($tp, $val) = split(':', $hash->{lwt}, 2);
|
||||
MQTT2_SERVER_doPublish($defs{$sname}, $tp, $val, undef,
|
||||
$hash->{cflags} & 0x20);
|
||||
MQTT2_SERVER_doPublish($shash, $tp, $val, undef, $hash->{cflags} & 0x20);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
@ -164,6 +167,7 @@ MQTT2_SERVER_Read($@)
|
||||
my $nhash = TcpServer_Accept($hash, "MQTT2_SERVER");
|
||||
return if(!$nhash);
|
||||
$nhash->{CD}->blocking(0);
|
||||
$hash->{NRCLIENTS}++;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -112,6 +112,7 @@ FileLog_Define($@)
|
||||
}
|
||||
|
||||
$hash->{FH} = $fh;
|
||||
$hash->{FD} = $fh->fileno() if($fh);
|
||||
$hash->{REGEXP} = $a[3];
|
||||
$hash->{logfile} = $a[2];
|
||||
$hash->{currentlogfile} = $f;
|
||||
@ -161,6 +162,7 @@ FileLog_Switch($)
|
||||
return 0;
|
||||
}
|
||||
$log->{FH} = $fh;
|
||||
$log->{FD} = $fh->fileno();
|
||||
setReadingsVal($log, "linesInTheFile", 0, TimeNow());
|
||||
return 1;
|
||||
}
|
||||
@ -294,6 +296,7 @@ FileLog_Set($@)
|
||||
}
|
||||
return "Can't open $cn" if(!defined($fh));
|
||||
$hash->{FH} = $fh;
|
||||
$hash->{FD} = $fh->fileno();
|
||||
}
|
||||
|
||||
} elsif($cmd eq "addRegexpPart") {
|
||||
@ -355,6 +358,7 @@ FileLog_Set($@)
|
||||
rename("$mylogfile.new", $mylogfile);
|
||||
$fh = new IO::File(">>$mylogfile");
|
||||
$hash->{FH} = $fh;
|
||||
$hash->{FD} = $fh->fileno();
|
||||
|
||||
$hash->{REGEXP} .= "|".$vh->{REGEXP};
|
||||
$hash->{DEF} = $hash->{logfile} . " ". $hash->{REGEXP};
|
||||
|
@ -34,7 +34,7 @@ TcpServer_Open($$$)
|
||||
Blocking => ($^O =~ /Win/ ? 1 : 0), # Needed for .WRITEBUFFER@darwin
|
||||
ReuseAddr => 1
|
||||
);
|
||||
$hash->{STATE} = "Initialized";
|
||||
readingsSingleUpdate($hash, "state", "Initialized", 0);
|
||||
$hash->{SERVERSOCKET} = $hash->{IPV6} ?
|
||||
IO::Socket::INET6->new(@opts) :
|
||||
IO::Socket::INET->new(@opts);
|
||||
@ -145,7 +145,7 @@ TcpServer_Accept($$)
|
||||
$nhash{CD} = $clientinfo[0]; # sysread / close won't work on fileno
|
||||
$nhash{TYPE} = $type;
|
||||
$nhash{SSL} = $hash->{SSL};
|
||||
$nhash{STATE} = "Connected";
|
||||
readingsSingleUpdate(\%nhash, "state", "Connected", 0);
|
||||
$nhash{SNAME} = $name;
|
||||
$nhash{TEMPORARY} = 1; # Don't want to save it
|
||||
$nhash{BUF} = "";
|
||||
|
@ -1386,6 +1386,7 @@ OpenLogfile($)
|
||||
}
|
||||
LOG->autoflush(1);
|
||||
$logopened = 1;
|
||||
$defs{global}{FD} = LOG->fileno();
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user