fix VoxelServer to be correctly event-driven, closes #1314

This commit is contained in:
Stephen Birarda 2013-12-05 10:08:41 -08:00
parent a376ebbca2
commit 7613f3d00c
2 changed files with 24 additions and 34 deletions

View file

@ -91,6 +91,29 @@ VoxelServer::~VoxelServer() {
} }
delete[] _parsedArgV; 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) { void VoxelServer::initMongoose(int port) {
@ -751,38 +774,4 @@ void VoxelServer::run() {
QTimer* pingNodesTimer = new QTimer(this); QTimer* pingNodesTimer = new QTimer(this);
connect(pingNodesTimer, SIGNAL(timeout()), nodeList, SLOT(pingInactiveNodes())); connect(pingNodesTimer, SIGNAL(timeout()), nodeList, SLOT(pingInactiveNodes()));
pingNodesTimer->start(PING_INACTIVE_NODE_INTERVAL_USECS / 1000); 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";
}

View file

@ -27,6 +27,7 @@
/// Handles assignments of type VoxelServer - sending voxels to various clients. /// Handles assignments of type VoxelServer - sending voxels to various clients.
class VoxelServer : public ThreadedAssignment { class VoxelServer : public ThreadedAssignment {
Q_OBJECT
public: public:
VoxelServer(const unsigned char* dataBuffer, int numBytes); VoxelServer(const unsigned char* dataBuffer, int numBytes);