From 7613f3d00c13fd54b5b0cbc05a57ca6b595c81e3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 5 Dec 2013 10:08:41 -0800 Subject: [PATCH] fix VoxelServer to be correctly event-driven, closes #1314 --- .../voxel-server-library/src/VoxelServer.cpp | 57 ++++++++----------- .../voxel-server-library/src/VoxelServer.h | 1 + 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index 96323f7d1a..b53f44ee88 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -91,6 +91,29 @@ VoxelServer::~VoxelServer() { } delete[] _parsedArgV; } + + if (_jurisdictionSender) { + _jurisdictionSender->terminate(); + delete _jurisdictionSender; + } + + if (_voxelServerPacketProcessor) { + _voxelServerPacketProcessor->terminate(); + delete _voxelServerPacketProcessor; + } + + if (_voxelPersistThread) { + _voxelPersistThread->terminate(); + delete _voxelPersistThread; + } + + // tell our NodeList we're done with notifications + NodeList::getInstance()->removeHook(&_nodeWatcher); + + delete _jurisdiction; + _jurisdiction = NULL; + + qDebug() << "VoxelServer::run()... DONE\n"; } void VoxelServer::initMongoose(int port) { @@ -751,38 +774,4 @@ void VoxelServer::run() { QTimer* pingNodesTimer = new QTimer(this); connect(pingNodesTimer, SIGNAL(timeout()), nodeList, SLOT(pingInactiveNodes())); pingNodesTimer->start(PING_INACTIVE_NODE_INTERVAL_USECS / 1000); - - // loop to send to nodes requesting data - while (!_isFinished) { - QCoreApplication::processEvents(); - } - - // call NodeList::clear() so that all of our node specific objects, including our sending threads, are - // properly shutdown and cleaned up. - NodeList::getInstance()->clear(); - - if (_jurisdictionSender) { - _jurisdictionSender->terminate(); - delete _jurisdictionSender; - } - - if (_voxelServerPacketProcessor) { - _voxelServerPacketProcessor->terminate(); - delete _voxelServerPacketProcessor; - } - - if (_voxelPersistThread) { - _voxelPersistThread->terminate(); - delete _voxelPersistThread; - } - - // tell our NodeList we're done with notifications - nodeList->removeHook(&_nodeWatcher); - - delete _jurisdiction; - _jurisdiction = NULL; - - qDebug() << "VoxelServer::run()... DONE\n"; } - - diff --git a/libraries/voxel-server-library/src/VoxelServer.h b/libraries/voxel-server-library/src/VoxelServer.h index f4923778c1..2c3b7188c6 100644 --- a/libraries/voxel-server-library/src/VoxelServer.h +++ b/libraries/voxel-server-library/src/VoxelServer.h @@ -27,6 +27,7 @@ /// Handles assignments of type VoxelServer - sending voxels to various clients. class VoxelServer : public ThreadedAssignment { + Q_OBJECT public: VoxelServer(const unsigned char* dataBuffer, int numBytes);