Make sure the ping timer exists to prevent crash if not available

pull/511/head
Simon Stürz 2022-04-26 16:45:07 +02:00
parent f3760ff84a
commit 1d04da6205
1 changed files with 7 additions and 7 deletions

View File

@ -49,6 +49,13 @@ NYMEA_LOGGING_CATEGORY(dcPingTraffic, "PingTraffic")
Ping::Ping(QObject *parent) : QObject(parent)
{
m_queueTimer = new QTimer(this);
m_queueTimer->setInterval(20);
m_queueTimer->setSingleShot(true);
connect(m_queueTimer, &QTimer::timeout, this, [=](){
sendNextReply();
});
// Build socket descriptor
m_socketDescriptor = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (m_socketDescriptor < 0) {
@ -78,13 +85,6 @@ Ping::Ping(QObject *parent) : QObject(parent)
m_socketNotifier = new QSocketNotifier(m_socketDescriptor, QSocketNotifier::Read, this);
connect(m_socketNotifier, &QSocketNotifier::activated, this, &Ping::onSocketReadyRead);
m_queueTimer = new QTimer(this);
m_queueTimer->setInterval(20);
m_queueTimer->setSingleShot(true);
connect(m_queueTimer, &QTimer::timeout, this, [=](){
sendNextReply();
});
m_socketNotifier->setEnabled(true);
m_available = true;
qCDebug(dcPing()) << "ICMP socket set up successfully (Socket ID:" << m_socketDescriptor << ")";