diff --git a/packettypes.h b/packettypes.h index 46cad4c..3a12b20 100644 --- a/packettypes.h +++ b/packettypes.h @@ -4,6 +4,19 @@ #pragma pack(push, 1) +// Various settings used by both client and server +#define PURGE_SECONDS 10 +#define TOKEN_RENEWAL 60000 +#define PING_PERIOD 500 +#define IDLE_PERIOD 100 +#define TXAUDIO_PERIOD 10 +#define AREYOUTHERE_PERIOD 500 +#define WATCHDOG_PERIOD 500 +#define RETRANSMIT_PERIOD 100 // How often to attempt retransmit +#define LOCK_PERIOD 10 // How long to try to lock mutex (ms) +#define STALE_CONNECTION 15 // Not heard from in this many seconds + + // Fixed Size Packets #define CONTROL_SIZE 0x10 #define WATCHDOG_SIZE 0x14 diff --git a/udphandler.h b/udphandler.h index 1a8e975..3357f32 100644 --- a/udphandler.h +++ b/udphandler.h @@ -24,15 +24,6 @@ #include "audiohandler.h" #include "packettypes.h" -#define PURGE_SECONDS 10 -#define TOKEN_RENEWAL 60000 -#define PING_PERIOD 100 -#define IDLE_PERIOD 100 -#define TXAUDIO_PERIOD 10 -#define AREYOUTHERE_PERIOD 500 -#define WATCHDOG_PERIOD 500 -#define RETRANSMIT_PERIOD 100 -#define LOCK_PERIOD 100 struct udpPreferences { QString ipAddress; diff --git a/udpserver.cpp b/udpserver.cpp index d7dd5c8..048800e 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -1,8 +1,6 @@ #include "udpserver.h" #include "logcategories.h" -#define STALE_CONNECTION 15 -#define LOCK_PERIOD 10 // time to attempt to lock Mutex in ms udpServer::udpServer(SERVERCONFIG config, audioSetup outAudio, audioSetup inAudio) : config(config), outAudio(outAudio), @@ -96,6 +94,21 @@ udpServer::~udpServer() udpAudio->close(); delete udpAudio; } + + if (rxAudioThread != Q_NULLPTR) { + rxAudioThread->quit(); + rxAudioThread->wait(); + rxaudio = Q_NULLPTR; + rxAudioThread = Q_NULLPTR; + } + + if (txAudioThread != Q_NULLPTR) { + txAudioThread->quit(); + txAudioThread->wait(); + txaudio = Q_NULLPTR; + txAudioThread = Q_NULLPTR; + } + emit haveNetworkStatus(QString("")); } @@ -106,8 +119,6 @@ void udpServer::receiveRigCaps(rigCapabilities caps) this->rigCaps = caps; } -#define RETRANSMIT_PERIOD 100 - void udpServer::controlReceived() { // Received data on control port. @@ -596,7 +607,7 @@ void udpServer::audioReceived() current->pingTimer = new QTimer(); connect(current->pingTimer, &QTimer::timeout, this, std::bind(&udpServer::sendPing, this, &audioClients, current, (quint16)0x00, false)); - current->pingTimer->start(100); + current->pingTimer->start(PING_PERIOD); current->retransmitTimer = new QTimer(); connect(current->retransmitTimer, &QTimer::timeout, this, std::bind(&udpServer::sendRetransmitRequest, this, current)); @@ -630,15 +641,9 @@ void udpServer::audioReceived() sendPing(&audioClients, current, in->seq, true); } else if (in->reply == 0x01) { - if (in->seq == current->pingSeq || in->seq == current->pingSeq - 1) + if (in->seq == current->pingSeq) { - // A Reply to our ping! - if (in->seq == current->pingSeq) { - current->pingSeq++; - } - else { - qInfo(logUdpServer()) << current->ipAddress.toString() << ": got out of sequence ping reply. Got: " << in->seq << " expecting: " << current->pingSeq; - } + current->pingSeq++; } } } @@ -1292,8 +1297,6 @@ void udpServer::sendTokenResponse(CLIENT* c, quint8 type) return; } -#define PURGE_SECONDS 60 - void udpServer::watchdog() { QDateTime now = QDateTime::currentDateTime();