aboutsummaryrefslogtreecommitdiff
path: root/src/UdpTasks/BeaconServer/Receive/udpontimeout.cpp
blob: 77670298917fefdf5bd550af12ffc3d23affe2ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "../beaconserver.h"

// soft timeout. every <timeout>, remove all servers older than <timeout> from the list.
// that means a server has a maximum wait/response time of 2*<timeout>
void BeaconServer::onUdpTimedOut()
{
    // iterate through the server list
    QHashIterator<QString, UdpData> 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();
}