Showing the changes to libraries/networking/src/ThreadedAssignment.cpp (1 of 6 files). Show all
Unified · Split
| @@ -23,7 +23,7 @@ ThreadedAssignment::ThreadedAssignment(const QByteArray& packet) : · 22 unmodified lines | ||
| 23 | 23 | _isFinished(false), |
| 24 | 24 | _datagramProcessingThread(NULL) |
| 25 | 25 | { |
| 26 | − | |
| 26 | + | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | void ThreadedAssignment::setFinished(bool isFinished) { |
| @@ -41,7 +41,7 @@ void ThreadedAssignment::setFinished(bool isFinished) { · 11 unmodified lines | ||
| 41 | 41 | if (_statsTimer) { |
| 42 | 42 | _statsTimer->stop(); |
| 43 | 43 | } |
| 44 | − | |
| 44 | + | |
| 45 | 45 | // stop processing datagrams from the node socket |
| 46 | 46 | // this ensures we won't process a domain list while we are going down |
| 47 | 47 | auto nodeList = DependencyManager::get<NodeList>(); |
| @@ -52,20 +52,21 @@ void ThreadedAssignment::setFinished(bool isFinished) { · 4 unmodified lines | ||
| 52 | 52 | |
| 53 | 53 | // if we have a datagram processing thread, quit it and wait on it to make sure that |
| 54 | 54 | // the node socket is back on the same thread as the NodeList |
| 55 | − | |
| 55 | + | |
| 56 | + | |
| 56 | 57 | if (_datagramProcessingThread) { |
| 57 | − // tell the datagram processing thread to quit and wait until it is done, | |
| 58 | + // tell the datagram processing thread to quit and wait until it is done, | |
| 58 | 59 | // then return the node socket to the NodeList |
| 59 | 60 | _datagramProcessingThread->quit(); |
| 60 | 61 | _datagramProcessingThread->wait(); |
| 61 | − | |
| 62 | + | |
| 62 | 63 | // set node socket parent back to NodeList |
| 63 | 64 | nodeList->getNodeSocket().setParent(nodeList.data()); |
| 64 | 65 | } |
| 65 | − | |
| 66 | + | |
| 66 | 67 | // move the NodeList back to the QCoreApplication instance's thread |
| 67 | 68 | nodeList->moveToThread(QCoreApplication::instance()->thread()); |
| 68 | − | |
| 69 | + | |
| 69 | 70 | emit finished(); |
| 70 | 71 | } |
| 71 | 72 | } |
| @@ -74,17 +75,17 @@ void ThreadedAssignment::setFinished(bool isFinished) { · 2 unmodified lines | ||
| 74 | 75 | void ThreadedAssignment::commonInit(const QString& targetName, NodeType_t nodeType, bool shouldSendStats) { |
| 75 | 76 | // change the logging target name while the assignment is running |
| 76 | 77 | LogHandler::getInstance().setTargetName(targetName); |
| 77 | − | |
| 78 | + | |
| 78 | 79 | auto nodeList = DependencyManager::get<NodeList>(); |
| 79 | 80 | nodeList->setOwnerType(nodeType); |
| 80 | − | |
| 81 | + | |
| 81 | 82 | // this is a temp fix for Qt 5.3 - rebinding the node socket gives us readyRead for the socket on this thread |
| 82 | 83 | nodeList->rebindNodeSocket(); |
| 83 | − | |
| 84 | + | |
| 84 | 85 | _domainServerTimer = new QTimer(); |
| 85 | 86 | connect(_domainServerTimer, SIGNAL(timeout()), this, SLOT(checkInWithDomainServerOrExit())); |
| 86 | 87 | _domainServerTimer->start(DOMAIN_SERVER_CHECK_IN_MSECS); |
| 87 | − | |
| 88 | + | |
| 88 | 89 | if (shouldSendStats) { |
| 89 | 90 | // send a stats packet every 1 second |
| 90 | 91 | _statsTimer = new QTimer(); |
| @@ -95,15 +96,15 @@ void ThreadedAssignment::commonInit(const QString& targetName, NodeType_t nodeTy · 4 unmodified lines | ||
| 95 | 96 | |
| 96 | 97 | void ThreadedAssignment::addPacketStatsAndSendStatsPacket(QJsonObject &statsObject) { |
| 97 | 98 | auto nodeList = DependencyManager::get<NodeList>(); |
| 98 | − | |
| 99 | + | |
| 99 | 100 | float packetsPerSecond, bytesPerSecond; |
| 100 | 101 | // XXX can BandwidthRecorder be used for this? |
| 101 | 102 | nodeList->getPacketStats(packetsPerSecond, bytesPerSecond); |
| 102 | 103 | nodeList->resetPacketStats(); |
| 103 | − | |
| 104 | + | |
| 104 | 105 | statsObject["packets_per_second"] = packetsPerSecond; |
| 105 | 106 | statsObject["bytes_per_second"] = bytesPerSecond; |
| 106 | − | |
| 107 | + | |
| 107 | 108 | nodeList->sendStatsToDomainServer(statsObject); |
| 108 | 109 | } |
| 109 | 110 | |
| @@ -122,7 +123,7 @@ void ThreadedAssignment::checkInWithDomainServerOrExit() { · 12 unmodified lines | ||
| 122 | 123 | |
| 123 | 124 | bool ThreadedAssignment::readAvailableDatagram(QByteArray& destinationByteArray, HifiSockAddr& senderSockAddr) { |
| 124 | 125 | auto nodeList = DependencyManager::get<NodeList>(); |
| 125 | − | |
| 126 | + | |
| 126 | 127 | if (nodeList->getNodeSocket().hasPendingDatagrams()) { |
| 127 | 128 | destinationByteArray.resize(nodeList->getNodeSocket().pendingDatagramSize()); |
| 128 | 129 | nodeList->getNodeSocket().readDatagram(destinationByteArray.data(), destinationByteArray.size(), |