From 0510411ac139fb963d6ad25900b11c88296c2b24 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 5 Oct 2016 16:19:39 -0700 Subject: [PATCH] fix timer use --- tools/ice-client/src/ICEClientApp.cpp | 42 +++++++++++++-------------- tools/ice-client/src/ICEClientApp.h | 6 ++-- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tools/ice-client/src/ICEClientApp.cpp b/tools/ice-client/src/ICEClientApp.cpp index 992014ad7d..e0a08b7fcb 100644 --- a/tools/ice-client/src/ICEClientApp.cpp +++ b/tools/ice-client/src/ICEClientApp.cpp @@ -178,16 +178,9 @@ void ICEClientApp::doSomething() { qDebug() << "sending STUN request"; } _socket->writeDatagram(stunRequestPacket, sizeof(stunRequestPacket), _stunSockAddr); - _stunResponseTimerCanceled = false; - _stunResponseTimer.singleShot(stunResponseTimeoutMilliSeconds, this, [&] { - if (_stunResponseTimerCanceled) { - return; - } - if (_verbose) { - qDebug() << "timeout waiting for stun-server response"; - } - QCoreApplication::exit(stunFailureExitStatus); - }); + _stunResponseTimer.setSingleShot(true); + connect(&_iceResponseTimer, SIGNAL(timeout()), this, SLOT(stunResponseTimeout())); + _stunResponseTimer.start(stunResponseTimeoutMilliSeconds); setState(waitForStunResponse); } else { @@ -215,16 +208,9 @@ void ICEClientApp::doSomething() { } sendPacketToIceServer(PacketType::ICEServerQuery, _iceServerAddr, _sessionUUID, peerID); - _iceResponseTimerCanceled = false; - _iceResponseTimer.singleShot(iceResponseTimeoutMilliSeconds, this, [=] { - if (_iceResponseTimerCanceled) { - return; - } - if (_verbose) { - qDebug() << "timeout waiting for ice-server response"; - } - QCoreApplication::exit(iceFailureExitStatus); - }); + _iceResponseTimer.setSingleShot(true); + connect(&_iceResponseTimer, SIGNAL(timeout()), this, SLOT(iceResponseTimeout())); + _iceResponseTimer.start(iceResponseTimeoutMilliSeconds); } else if (_state == pause0) { setState(pause1); } else if (_state == pause1) { @@ -237,6 +223,20 @@ void ICEClientApp::doSomething() { } } +void ICEClientApp::iceResponseTimeout() { + if (_verbose) { + qDebug() << "timeout waiting for ice-server response"; + } + QCoreApplication::exit(iceFailureExitStatus); +} + +void ICEClientApp::stunResponseTimeout() { + if (_verbose) { + qDebug() << "timeout waiting for stun-server response"; + } + QCoreApplication::exit(stunFailureExitStatus); +} + void ICEClientApp::sendPacketToIceServer(PacketType packetType, const HifiSockAddr& iceServerSockAddr, const QUuid& clientID, const QUuid& peerID) { std::unique_ptr icePacket = NLPacket::create(packetType); @@ -298,7 +298,6 @@ void ICEClientApp::processSTUNResponse(std::unique_ptr packet) } _stunResponseTimer.stop(); - _stunResponseTimerCanceled = true; uint16_t newPublicPort; QHostAddress newPublicAddress; @@ -331,7 +330,6 @@ void ICEClientApp::processPacket(std::unique_ptr packet) { if (nlPacket->getType() == PacketType::ICEServerPeerInformation) { // cancel the timeout timer _iceResponseTimer.stop(); - _iceResponseTimerCanceled = true; QDataStream iceResponseStream(message->getMessage()); if (!_domainServerPeerSet) { diff --git a/tools/ice-client/src/ICEClientApp.h b/tools/ice-client/src/ICEClientApp.h index 3635bc07f4..de6b6abb14 100644 --- a/tools/ice-client/src/ICEClientApp.h +++ b/tools/ice-client/src/ICEClientApp.h @@ -33,6 +33,10 @@ public: const int stunResponseTimeoutMilliSeconds { 2000 }; const int iceResponseTimeoutMilliSeconds { 2000 }; +public slots: + void iceResponseTimeout(); + void stunResponseTimeout(); + private: enum State { lookUpStunServer, // 0 @@ -83,9 +87,7 @@ private: int _state { 0 }; QTimer _stunResponseTimer; - bool _stunResponseTimerCanceled { false }; QTimer _iceResponseTimer; - bool _iceResponseTimerCanceled { false }; int _domainPingCount { 0 }; };