From 8e786cb95313dde784b70fa5e6786ef6d156ca44 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 30 Jul 2015 17:40:51 -0700 Subject: [PATCH] repairs while testing with UDTTest --- libraries/networking/src/udt/Connection.cpp | 30 +++++++++++---------- libraries/networking/src/udt/SendQueue.cpp | 25 ++++++++--------- libraries/networking/src/udt/SendQueue.h | 3 +-- tools/udt-test/src/UDTTest.cpp | 2 ++ 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index e26f524c31..0d0140dbca 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -203,20 +203,22 @@ void Connection::sendNAK(SequenceNumber sequenceNumberRecieved) { } void Connection::sendTimeoutNAK() { - // construct a NAK packet that will hold all of the lost sequence numbers - // TODO size is wrong, fix it. - auto lossListPacket = ControlPacket::create(ControlPacket::TimeoutNAK, _lossList.getLength() * sizeof(SequenceNumber)); - - // Pack in the lost sequence numbers - _lossList.write(*lossListPacket); - - // have our SendQueue send off this control packet - _sendQueue->sendPacket(*lossListPacket); - - // record this as the last NAK time - _lastNAKTime = high_resolution_clock::now(); - - _stats.recordSentTimeoutNAK(); + if (_lossList.getLength() > 0) { + // construct a NAK packet that will hold all of the lost sequence numbers + // TODO size is wrong, fix it. + auto lossListPacket = ControlPacket::create(ControlPacket::TimeoutNAK, _lossList.getLength() * sizeof(SequenceNumber)); + + // Pack in the lost sequence numbers + _lossList.write(*lossListPacket); + + // have our SendQueue send off this control packet + _sendQueue->sendPacket(*lossListPacket); + + // record this as the last NAK time + _lastNAKTime = high_resolution_clock::now(); + + _stats.recordSentTimeoutNAK(); + } } SequenceNumber Connection::nextACK() const { diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index d0ec6ee38e..66051ad1c4 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -58,19 +58,6 @@ void SendQueue::queuePacket(std::unique_ptr packet) { } } -void SendQueue::run() { - // We need to make sure this is called on the right thread - if (thread() != QThread::currentThread()) { - QMetaObject::invokeMethod(this, "run", Qt::QueuedConnection); - return; - } - - _isRunning = true; - - // This will loop and sleep to send packets - loop(); -} - void SendQueue::stop() { _isRunning = false; } @@ -128,7 +115,16 @@ SequenceNumber SendQueue::getNextSequenceNumber() { return _currentSequenceNumber; } -void SendQueue::loop() { +void SendQueue::run() { + + // We need to make sure this is called on the right thread + if (thread() != QThread::currentThread()) { + QMetaObject::invokeMethod(this, "run", Qt::QueuedConnection); + return; + } + + _isRunning = true; + while (_isRunning) { // Record timing _lastSendTimestamp = high_resolution_clock::now(); @@ -170,6 +166,7 @@ void SendQueue::loop() { } if (nextPacket) { + qDebug() << "the next packet is" << nextPacket->getDataSize() << "bytes"; bool shouldSendSecondOfPair = false; if (!hasResend) { diff --git a/libraries/networking/src/udt/SendQueue.h b/libraries/networking/src/udt/SendQueue.h index 1b6b6181b8..3915414e1f 100644 --- a/libraries/networking/src/udt/SendQueue.h +++ b/libraries/networking/src/udt/SendQueue.h @@ -55,7 +55,6 @@ public: void sendPacket(const BasePacket& packet); public slots: - void run(); void stop(); void ack(SequenceNumber ack); @@ -66,7 +65,7 @@ signals: void packetSent(); private slots: - void loop(); + void run(); private: SendQueue(Socket* socket, HifiSockAddr dest); diff --git a/tools/udt-test/src/UDTTest.cpp b/tools/udt-test/src/UDTTest.cpp index 8d9655437d..2bfcd48a76 100644 --- a/tools/udt-test/src/UDTTest.cpp +++ b/tools/udt-test/src/UDTTest.cpp @@ -66,6 +66,7 @@ UDTTest::UDTTest(int& argc, char** argv) : QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); } else { _target = HifiSockAddr(address, port); + qDebug() << "Packets will be sent to" << _target; } } @@ -184,6 +185,7 @@ void UDTTest::sendPacket() { } auto newPacket = udt::Packet::create(packetPayloadSize, _sendReliable); + newPacket->setPayloadSize(packetPayloadSize); _totalQueuedBytes += newPacket->getDataSize();