switch node pinging to QTimer in QCoreApplication instance

This commit is contained in:
Stephen Birarda 2013-12-03 10:57:31 -08:00
parent c3b6a7b24c
commit 606eaa579a
4 changed files with 14 additions and 20 deletions

View file

@ -272,6 +272,10 @@ void AudioMixer::run() {
connect(silentNodeTimer, SIGNAL(timeout()), nodeList, SLOT(removeSilentNodes()));
silentNodeTimer->start(NODE_SILENCE_THRESHOLD_USECS / 1000);
QTimer* pingNodesTimer = new QTimer(this);
connect(pingNodesTimer, SIGNAL(timeout()), nodeList, SLOT(pingInactiveNodes()));
pingNodesTimer->start(PING_INACTIVE_NODE_INTERVAL_USECS / 1000);
int nextFrame = 0;
timeval startTime;
@ -314,9 +318,6 @@ void AudioMixer::run() {
}
}
// get the NodeList to ping any inactive nodes, for hole punching
nodeList->possiblyPingInactiveNodes();
int usecToSleep = usecTimestamp(&startTime) + (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - usecTimestampNow();
if (usecToSleep > 0) {

View file

@ -724,20 +724,12 @@ unsigned NodeList::broadcastToNodes(unsigned char* broadcastData, size_t dataByt
return n;
}
const uint64_t PING_INACTIVE_NODE_INTERVAL_USECS = 1 * 1000 * 1000;
void NodeList::possiblyPingInactiveNodes() {
static timeval lastPing = {};
// make sure PING_INACTIVE_NODE_INTERVAL_USECS has elapsed since last ping
if (usecTimestampNow() - usecTimestamp(&lastPing) >= PING_INACTIVE_NODE_INTERVAL_USECS) {
gettimeofday(&lastPing, NULL);
for(NodeList::iterator node = begin(); node != end(); node++) {
if (!node->getActiveSocket()) {
// we don't have an active link to this node, ping it to set that up
pingPublicAndLocalSocketsForInactiveNode(&(*node));
}
void NodeList::pingInactiveNodes() {
qDebug() << "Pinging inactive nodes\n";
for(NodeList::iterator node = begin(); node != end(); node++) {
if (!node->getActiveSocket()) {
// we don't have an active link to this node, ping it to set that up
pingPublicAndLocalSocketsForInactiveNode(&(*node));
}
}
}

View file

@ -31,7 +31,8 @@ const int NODES_PER_BUCKET = 100;
const int MAX_PACKET_SIZE = 1500;
const uint64_t NODE_SILENCE_THRESHOLD_USECS = 2 * 1000 * 1000;
const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000;
const uint64_t DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000;
const uint64_t PING_INACTIVE_NODE_INTERVAL_USECS = 1 * 1000 * 1000;
extern const char SOLO_NODE_TYPES[2];
@ -141,10 +142,10 @@ public:
void addDomainListener(DomainChangeListener* listener);
void removeDomainListener(DomainChangeListener* listener);
void possiblyPingInactiveNodes();
const HifiSockAddr* getNodeActiveSocketOrPing(Node* node);
public slots:
void sendDomainServerCheckIn();
void pingInactiveNodes();
void removeSilentNodes();
private:
static NodeList* _sharedInstance;

View file

@ -666,7 +666,7 @@ void VoxelServer::run() {
}
// ping our inactive nodes to punch holes with them
nodeList->possiblyPingInactiveNodes();
nodeList->pingInactiveNodes();
if (nodeList->getNodeSocket().hasPendingDatagrams()
&& (packetLength = nodeList->getNodeSocket().readDatagram((char*) packetData, MAX_PACKET_SIZE,