add method to packet sender to flush queue without sleep

This commit is contained in:
Stephen Birarda 2013-09-20 14:40:09 -07:00
parent 04c4dabd3d
commit 6533d7fcde
3 changed files with 22 additions and 2 deletions

View file

@ -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);

View file

@ -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();
}
}

View file

@ -43,6 +43,7 @@ public:
PacketSenderNotify* getPacketSenderNotify() const { return _notify; }
virtual bool process();
virtual void processWithoutSleep();
protected:
int _packetsPerSecond;