correct timing for assignment-client check in

This commit is contained in:
Stephen Birarda 2013-09-06 15:12:53 -07:00
parent 9eef894e24
commit f18a40dc89
2 changed files with 36 additions and 30 deletions

View file

@ -16,7 +16,7 @@
#include <PacketHeaders.h> #include <PacketHeaders.h>
#include <SharedUtil.h> #include <SharedUtil.h>
const int ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000; const long long ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000;
int main(int argc, char* const argv[]) { int main(int argc, char* const argv[]) {
@ -28,6 +28,8 @@ int main(int argc, char* const argv[]) {
// change the timeout on the nodelist socket to be as often as we want to re-request // change the timeout on the nodelist socket to be as often as we want to re-request
nodeList->getNodeSocket()->setBlockingReceiveTimeoutInUsecs(ASSIGNMENT_REQUEST_INTERVAL_USECS); nodeList->getNodeSocket()->setBlockingReceiveTimeoutInUsecs(ASSIGNMENT_REQUEST_INTERVAL_USECS);
timeval lastRequest = {};
unsigned char packetData[MAX_PACKET_SIZE]; unsigned char packetData[MAX_PACKET_SIZE];
ssize_t receivedBytes = 0; ssize_t receivedBytes = 0;
@ -51,12 +53,15 @@ int main(int argc, char* const argv[]) {
Assignment requestAssignment(Assignment::Request, Assignment::All, assignmentPool); Assignment requestAssignment(Assignment::Request, Assignment::All, assignmentPool);
while (true) { while (true) {
if (usecTimestampNow() - usecTimestamp(&lastRequest) >= ASSIGNMENT_REQUEST_INTERVAL_USECS) {
gettimeofday(&lastRequest, NULL);
// if we're here we have no assignment, so send a request // if we're here we have no assignment, so send a request
qDebug() << "Sending an assignment request -" << requestAssignment; qDebug() << "Sending an assignment request -" << requestAssignment;
nodeList->sendAssignment(requestAssignment); nodeList->sendAssignment(requestAssignment);
}
while (nodeList->getNodeSocket()->receive(packetData, &receivedBytes)) { if (nodeList->getNodeSocket()->receive(packetData, &receivedBytes) &&
if (packetData[0] == PACKET_TYPE_DEPLOY_ASSIGNMENT && packetVersionMatch(packetData)) { packetData[0] == PACKET_TYPE_DEPLOY_ASSIGNMENT && packetVersionMatch(packetData)) {
// construct the deployed assignment from the packet data // construct the deployed assignment from the packet data
Assignment deployedAssignment(packetData, receivedBytes); Assignment deployedAssignment(packetData, receivedBytes);
@ -74,6 +79,7 @@ int main(int argc, char* const argv[]) {
if (deployedAssignment.getType() == Assignment::AudioMixer) { if (deployedAssignment.getType() == Assignment::AudioMixer) {
AudioMixer::run(); AudioMixer::run();
} else { } else {
qDebug() << "Running as an avatar mixer!";
AvatarMixer::run(); AvatarMixer::run();
} }
@ -85,4 +91,3 @@ int main(int argc, char* const argv[]) {
} }
} }
} }
}

View file

@ -255,6 +255,7 @@ void NodeList::clear() {
} }
_numNodes = 0; _numNodes = 0;
_numNoReplyDomainCheckIns = 0;
} }
void NodeList::setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNodeTypesOfInterest) { void NodeList::setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNodeTypesOfInterest) {