add the option for PacketReceiver to drop packets

This commit is contained in:
Stephen Birarda 2015-07-14 15:49:54 -07:00
parent b7b2cb73ef
commit fb7cb7ff53
5 changed files with 21 additions and 7 deletions

View file

@ -330,6 +330,9 @@ void AssignmentClient::assignmentCompleted() {
auto nodeList = DependencyManager::get<NodeList>();
// tell the packet receiver to stop dropping packets
nodeList->getPacketReceiver().setShouldDropPackets(false);
// reset our NodeList by switching back to unassigned and clearing the list
nodeList->setOwnerType(NodeType::Unassigned);
nodeList->reset();

View file

@ -663,12 +663,11 @@ void Application::aboutToQuit() {
void Application::cleanupBeforeQuit() {
// stop handling packets we've asked to handle
DependencyManager::get<LimitedNodeList>()->getPacketReceiver().unregisterListener(this);
_entities.clear(); // this will allow entity scripts to properly shutdown
//_datagramProcessor->shutdown(); // tell the datagram processor we're shutting down, so it can short circuit
// tell the packet receiver we're shutting down, so it can drop packets
DependencyManager::get<NodeList>()->getPacketReceiver().setShouldDropPackets(true);
_entities.shutdown(); // tell the entities system we're shutting down, so it will stop running scripts
ScriptEngine::stopAllScripts(this); // stop all currently running global scripts

View file

@ -180,6 +180,11 @@ void PacketReceiver::processDatagrams() {
// setup a buffer to read the packet into
int packetSizeWithHeader = nodeList->getNodeSocket().pendingDatagramSize();
std::unique_ptr<char> buffer = std::unique_ptr<char>(new char[packetSizeWithHeader]);
// if we're supposed to drop this packet then break out here
if (_shouldDropPackets) {
break;
}
// setup a HifiSockAddr to read into
HifiSockAddr senderSockAddr;

View file

@ -34,6 +34,8 @@ public:
int getInPacketCount() const { return _inPacketCount; }
int getInByteCount() const { return _inByteCount; }
void setShouldDropPackets(bool shouldDropPackets) { _shouldDropPackets = shouldDropPackets; }
void resetCounters() { _inPacketCount = 0; _inByteCount = 0; }
@ -61,7 +63,7 @@ private:
QHash<PacketType::Value, ObjectMethodPair> _packetListenerMap;
int _inPacketCount = 0;
int _inByteCount = 0;
bool _isShuttingDown = false;
bool _shouldDropPackets = false;
};
#endif // hifi_PacketReceiver_h

View file

@ -34,8 +34,13 @@ void ThreadedAssignment::setFinished(bool isFinished) {
qDebug() << "ThreadedAssignment::setFinished(true) called - finishing up.";
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
// we should de-register immediately for any of our packets
DependencyManager::get<NodeList>()->getPacketReceiver().unregisterListener(this);
packetReceiver.unregisterListener(this);
// we should also tell the packet receiver to drop packets while we're cleaning up
packetReceiver.setShouldDropPackets(true);
if (_domainServerTimer) {
_domainServerTimer->stop();