From 60a301a93b6057bb2c54ac04a7c38c38389037b3 Mon Sep 17 00:00:00 2001 From: Dark1-dev Date: Wed, 1 Mar 2023 21:30:57 +0600 Subject: Add files via upload --- src/UdpTasks/BeaconServer/Receive/udpontimeout.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/UdpTasks/BeaconServer/Receive/udpontimeout.cpp (limited to 'src/UdpTasks/BeaconServer/Receive/udpontimeout.cpp') diff --git a/src/UdpTasks/BeaconServer/Receive/udpontimeout.cpp b/src/UdpTasks/BeaconServer/Receive/udpontimeout.cpp new file mode 100644 index 0000000..7767029 --- /dev/null +++ b/src/UdpTasks/BeaconServer/Receive/udpontimeout.cpp @@ -0,0 +1,27 @@ +#include "../beaconserver.h" + +// soft timeout. every , remove all servers older than from the list. +// that means a server has a maximum wait/response time of 2* +void BeaconServer::onUdpTimedOut() +{ + // iterate through the server list + QHashIterator list(_beaconList); + while (list.hasNext()) + { + // select + list.next(); + + // check passed time: add date < remove date? + qint64 currentTime = QDateTime::currentSecsSinceEpoch(); + if ( list.value().time < currentTime - (_timeOutTime_ms / 1000) ) + { + // if timeout has passed, remove the server from the list + _coreObject->Log.logEvent("udp", QStringLiteral("%1 timed out").arg(list.key())); + _beaconList.remove(list.key()); + } + } + + // periodically emit readyread signal to avoid issues similar to StatusChecker + // readyread function will handle any inconsistencies + emit _udpSocket.readyRead(); +} -- cgit v1.2.3