Make sure the ping timer exists to prevent crash if not available
This commit is contained in:
parent
f3760ff84a
commit
1d04da6205
@ -49,6 +49,13 @@ NYMEA_LOGGING_CATEGORY(dcPingTraffic, "PingTraffic")
|
|||||||
|
|
||||||
Ping::Ping(QObject *parent) : QObject(parent)
|
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
|
// Build socket descriptor
|
||||||
m_socketDescriptor = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
|
m_socketDescriptor = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
|
||||||
if (m_socketDescriptor < 0) {
|
if (m_socketDescriptor < 0) {
|
||||||
@ -78,13 +85,6 @@ Ping::Ping(QObject *parent) : QObject(parent)
|
|||||||
m_socketNotifier = new QSocketNotifier(m_socketDescriptor, QSocketNotifier::Read, this);
|
m_socketNotifier = new QSocketNotifier(m_socketDescriptor, QSocketNotifier::Read, this);
|
||||||
connect(m_socketNotifier, &QSocketNotifier::activated, this, &Ping::onSocketReadyRead);
|
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_socketNotifier->setEnabled(true);
|
||||||
m_available = true;
|
m_available = true;
|
||||||
qCDebug(dcPing()) << "ICMP socket set up successfully (Socket ID:" << m_socketDescriptor << ")";
|
qCDebug(dcPing()) << "ICMP socket set up successfully (Socket ID:" << m_socketDescriptor << ")";
|
||||||
|
|||||||
Reference in New Issue
Block a user