You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/browser/PingUpdater.cpp

47 lines
1.1 KiB
C++

#include "PingUpdater.hpp"
#include "netutils/Utils.hpp"
#include <QDebug>
#include <QModelIndex>
#include <QThread>
void PingUpdater::stop()
{
servers.clear();
run = false;
}
void PingUpdater::addServer(int row, const AddrPair &addr)
{
servers.push_back({row, addr});
run = true;
emit start();
}
void PingUpdater::process()
{
while (run)
{
if (servers.count() == 0)
{
QThread::msleep(1000);
if (servers.count() == 0)
{
qDebug() << "PingUpdater stopped due to inactivity";
run = false;
continue;
}
}
ServerRow server = servers.back();
servers.pop_back();
unsigned ping = PingRakNetServer(server.second.first.toLatin1(), server.second.second);
qDebug() << "Pong from" << server.second.first + "|" + QString::number(server.second.second)
<< ":" << ping << "ms" << "Sizeof servers: " << servers.size();
emit updateModel(server.first, ping);
}
emit finished();
}