From 6533d7fcde35fc8bbe11dc66dc4d5675f0fdecae Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 20 Sep 2013 14:40:09 -0700 Subject: [PATCH] add method to packet sender to flush queue without sleep --- assignment-client/src/Agent.cpp | 4 ++-- libraries/shared/src/PacketSender.cpp | 19 +++++++++++++++++++ libraries/shared/src/PacketSender.h | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index aa9bfae31f..7ace955ccd 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -82,8 +82,8 @@ void Agent::run() { // allow the scripter's call back to setup visual data emit preSendCallback(); - // flush the voxel packet queue - voxelScripter.getVoxelPacketSender()->process(); + // flush the voxel packet queue, don't allow it to sleep us + voxelScripter.getVoxelPacketSender()->processWithoutSleep(); while (NodeList::getInstance()->getNodeSocket()->receive((sockaddr*) &senderAddress, receivedData, &receivedBytes)) { NodeList::getInstance()->processNodeData((sockaddr*) &senderAddress, receivedData, receivedBytes); diff --git a/libraries/shared/src/PacketSender.cpp b/libraries/shared/src/PacketSender.cpp index 511b01541f..ebf3b50060 100644 --- a/libraries/shared/src/PacketSender.cpp +++ b/libraries/shared/src/PacketSender.cpp @@ -68,3 +68,22 @@ bool PacketSender::process() { } return isStillRunning(); // keep running till they terminate us } + +void PacketSender::processWithoutSleep() { + while (_packets.size() > 0) { + NetworkPacket& packet = _packets.front(); + + // send the packet through the NodeList... + UDPSocket* nodeSocket = NodeList::getInstance()->getNodeSocket(); + + nodeSocket->send(&packet.getAddress(), packet.getData(), packet.getLength()); + + if (_notify) { + _notify->packetSentNotification(packet.getLength()); + } + + lock(); + _packets.erase(_packets.begin()); + unlock(); + } +} diff --git a/libraries/shared/src/PacketSender.h b/libraries/shared/src/PacketSender.h index 3a07444f2b..5309043743 100644 --- a/libraries/shared/src/PacketSender.h +++ b/libraries/shared/src/PacketSender.h @@ -43,6 +43,7 @@ public: PacketSenderNotify* getPacketSenderNotify() const { return _notify; } virtual bool process(); + virtual void processWithoutSleep(); protected: int _packetsPerSecond;