kopia lustrzana https://gitlab.com/eliggett/wfview
Use global watchdog rather than per-connection
rodzic
9fe71b4495
commit
e6197f68cb
|
@ -58,8 +58,9 @@ void udpServer::init()
|
|||
udpAudio->bind(config.audioPort);
|
||||
QUdpSocket::connect(udpAudio, &QUdpSocket::readyRead, this, &udpServer::audioReceived);
|
||||
|
||||
emit haveNetworkStatus(QString("<pre>Server connections: Control:%1 CI-V:%2 Audio:%3</pre>").arg(controlClients.size()).arg(civClients.size()).arg(audioClients.size()));
|
||||
|
||||
wdTimer = new QTimer();
|
||||
connect(wdTimer, &QTimer::timeout, this, &udpServer::watchdog);
|
||||
wdTimer->start(500);
|
||||
}
|
||||
|
||||
udpServer::~udpServer()
|
||||
|
@ -79,10 +80,6 @@ udpServer::~udpServer()
|
|||
client->pingTimer->stop();
|
||||
delete client->pingTimer;
|
||||
}
|
||||
if (client->wdTimer != Q_NULLPTR) {
|
||||
client->wdTimer->stop();
|
||||
delete client->wdTimer;
|
||||
}
|
||||
|
||||
if (client->retransmitTimer != Q_NULLPTR) {
|
||||
client->retransmitTimer->stop();
|
||||
|
@ -216,10 +213,6 @@ void udpServer::controlReceived()
|
|||
connect(current->idleTimer, &QTimer::timeout, this, std::bind(&udpServer::sendControl, this, current, (quint8)0x00, (quint16)0x00));
|
||||
current->idleTimer->start(100);
|
||||
|
||||
current->wdTimer = new QTimer();
|
||||
connect(current->wdTimer, &QTimer::timeout, this, std::bind(&udpServer::watchdog, this, &controlClients, current));
|
||||
current->wdTimer->start(1000);
|
||||
|
||||
current->retransmitTimer = new QTimer();
|
||||
connect(current->retransmitTimer, &QTimer::timeout, this, std::bind(&udpServer::sendRetransmitRequest, this, current));
|
||||
current->retransmitTimer->start(RETRANSMIT_PERIOD);
|
||||
|
@ -253,7 +246,6 @@ void udpServer::controlReceived()
|
|||
deleteConnection(&civClients, current->civClient);
|
||||
}
|
||||
deleteConnection(&controlClients, current);
|
||||
emit haveNetworkStatus(QString("<pre>Server connections: Control:%1 CI-V:%2 Audio:%3</pre>").arg(controlClients.size()).arg(civClients.size()).arg(audioClients.size()));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
@ -432,8 +424,6 @@ void udpServer::controlReceived()
|
|||
break;
|
||||
}
|
||||
}
|
||||
// Report current connections:
|
||||
emit haveNetworkStatus(QString("<pre>Server connections: Control:%1 CI-V:%2 Audio:%3</pre>").arg(controlClients.size()).arg(civClients.size()).arg(audioClients.size()));
|
||||
|
||||
// Connection "may" have been deleted so check before calling common function.
|
||||
if (current != Q_NULLPTR) {
|
||||
|
@ -502,10 +492,6 @@ void udpServer::civReceived()
|
|||
connect(current->idleTimer, &QTimer::timeout, this, std::bind(&udpServer::sendControl, this, current, 0x00, (quint16)0x00));
|
||||
//current->idleTimer->start(100); // Start idleTimer after receiving iamready.
|
||||
|
||||
current->wdTimer = new QTimer();
|
||||
connect(current->wdTimer, &QTimer::timeout, this, std::bind(&udpServer::watchdog, this, &civClients, current));
|
||||
current->wdTimer->start(1000);
|
||||
|
||||
current->retransmitTimer = new QTimer();
|
||||
connect(current->retransmitTimer, &QTimer::timeout, this, std::bind(&udpServer::sendRetransmitRequest, this, current));
|
||||
current->retransmitTimer->start(RETRANSMIT_PERIOD);
|
||||
|
@ -648,10 +634,6 @@ void udpServer::audioReceived()
|
|||
connect(current->pingTimer, &QTimer::timeout, this, std::bind(&udpServer::sendPing, this, &audioClients, current, (quint16)0x00, false));
|
||||
current->pingTimer->start(100);
|
||||
|
||||
current->wdTimer = new QTimer();
|
||||
connect(current->wdTimer, &QTimer::timeout, this, std::bind(&udpServer::watchdog, this, &audioClients, current));
|
||||
current->wdTimer->start(1000);
|
||||
|
||||
current->retransmitTimer = new QTimer();
|
||||
connect(current->retransmitTimer, &QTimer::timeout, this, std::bind(&udpServer::sendRetransmitRequest, this, current));
|
||||
current->retransmitTimer->start(RETRANSMIT_PERIOD);
|
||||
|
@ -990,8 +972,6 @@ void udpServer::sendLoginResponse(CLIENT* c, bool allowed)
|
|||
c->pingTimer->stop();
|
||||
if (c->retransmitTimer != Q_NULLPTR)
|
||||
c->retransmitTimer->stop();
|
||||
if (c->wdTimer != Q_NULLPTR)
|
||||
c->wdTimer->stop();
|
||||
}
|
||||
else {
|
||||
strcpy(p.connection, "WFVIEW");
|
||||
|
@ -1235,18 +1215,59 @@ void udpServer::sendTokenResponse(CLIENT* c, quint8 type)
|
|||
|
||||
#define PURGE_SECONDS 60
|
||||
|
||||
void udpServer::watchdog(QList<CLIENT*>* l, CLIENT* c)
|
||||
void udpServer::watchdog()
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
|
||||
if (c->lastHeard.secsTo(now) > STALE_CONNECTION)
|
||||
foreach(CLIENT * client, audioClients)
|
||||
{
|
||||
qInfo(logUdpServer()) << c->ipAddress.toString() << "(" << c->type << "): Deleting stale connection ";
|
||||
deleteConnection(l, c);
|
||||
emit haveNetworkStatus(QString("<pre>Server connections: Control:%1 CI-V:%2 Audio:%3</pre>").arg(controlClients.size()).arg(civClients.size()).arg(audioClients.size()));
|
||||
return;
|
||||
if (client != Q_NULLPTR)
|
||||
{
|
||||
if (client->lastHeard.secsTo(now) > STALE_CONNECTION)
|
||||
{
|
||||
qInfo(logUdpServer()) << client->ipAddress.toString() << "(" << client->type << "): Deleting stale connection ";
|
||||
deleteConnection(&audioClients, client);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
qInfo(logUdpServer()) << "Current client is NULL!";
|
||||
}
|
||||
}
|
||||
|
||||
foreach(CLIENT* client, civClients)
|
||||
{
|
||||
if (client != Q_NULLPTR)
|
||||
{
|
||||
if (client->lastHeard.secsTo(now) > STALE_CONNECTION)
|
||||
{
|
||||
qInfo(logUdpServer()) << client->ipAddress.toString() << "(" << client->type << "): Deleting stale connection ";
|
||||
deleteConnection(&civClients, client);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
qInfo(logUdpServer()) << "Current client is NULL!";
|
||||
}
|
||||
}
|
||||
|
||||
foreach(CLIENT* client, controlClients)
|
||||
{
|
||||
if (client != Q_NULLPTR)
|
||||
{
|
||||
if (client->lastHeard.secsTo(now) > STALE_CONNECTION)
|
||||
{
|
||||
qInfo(logUdpServer()) << client->ipAddress.toString() << "(" << client->type << "): Deleting stale connection ";
|
||||
deleteConnection(&controlClients, client);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
qInfo(logUdpServer()) << "Current client is NULL!";
|
||||
}
|
||||
}
|
||||
|
||||
emit haveNetworkStatus(QString("<pre>Server connections: Control:%1 CI-V:%2 Audio:%3</pre>").arg(controlClients.size()).arg(civClients.size()).arg(audioClients.size()));
|
||||
}
|
||||
|
||||
void udpServer::sendStatus(CLIENT* c)
|
||||
|
@ -1537,10 +1558,6 @@ void udpServer::deleteConnection(QList<CLIENT*>* l, CLIENT* c)
|
|||
c->pingTimer->stop();
|
||||
delete c->pingTimer;
|
||||
}
|
||||
if (c->wdTimer != Q_NULLPTR) {
|
||||
c->wdTimer->stop();
|
||||
delete c->wdTimer;
|
||||
}
|
||||
|
||||
if (c->retransmitTimer != Q_NULLPTR) {
|
||||
c->retransmitTimer->stop();
|
||||
|
|
|
@ -94,7 +94,6 @@ private:
|
|||
|
||||
QTimer* pingTimer;
|
||||
QTimer* idleTimer;
|
||||
QTimer* wdTimer;
|
||||
QTimer* retransmitTimer;
|
||||
|
||||
// Only used for audio.
|
||||
|
@ -135,7 +134,7 @@ private:
|
|||
void sendTokenResponse(CLIENT* c,quint8 type);
|
||||
void sendStatus(CLIENT* c);
|
||||
void sendRetransmitRequest(CLIENT* c);
|
||||
void watchdog(QList<CLIENT*>* l, CLIENT* c);
|
||||
void watchdog();
|
||||
void sendRxAudio();
|
||||
void deleteConnection(QList<CLIENT*> *l, CLIENT* c);
|
||||
|
||||
|
@ -178,6 +177,7 @@ private:
|
|||
quint8 txCodec = 0;
|
||||
|
||||
QHostAddress hasTxAudio;
|
||||
QTimer* wdTimer;
|
||||
};
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue