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.
51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
//
|
|
// Created by koncord on 02.05.17.
|
|
//
|
|
|
|
#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();
|
|
}
|