diff --git a/assignment-client/src/main.cpp b/assignment-client/src/main.cpp index f3d6b8c0cd..ac34fb0723 100644 --- a/assignment-client/src/main.cpp +++ b/assignment-client/src/main.cpp @@ -16,7 +16,7 @@ #include #include -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[]) { @@ -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 nodeList->getNodeSocket()->setBlockingReceiveTimeoutInUsecs(ASSIGNMENT_REQUEST_INTERVAL_USECS); + timeval lastRequest = {}; + unsigned char packetData[MAX_PACKET_SIZE]; ssize_t receivedBytes = 0; @@ -51,38 +53,41 @@ int main(int argc, char* const argv[]) { Assignment requestAssignment(Assignment::Request, Assignment::All, assignmentPool); while (true) { - // if we're here we have no assignment, so send a request - qDebug() << "Sending an assignment request -" << requestAssignment; - nodeList->sendAssignment(requestAssignment); + if (usecTimestampNow() - usecTimestamp(&lastRequest) >= ASSIGNMENT_REQUEST_INTERVAL_USECS) { + gettimeofday(&lastRequest, NULL); + // if we're here we have no assignment, so send a request + qDebug() << "Sending an assignment request -" << requestAssignment; + nodeList->sendAssignment(requestAssignment); + } - while (nodeList->getNodeSocket()->receive(packetData, &receivedBytes)) { - if (packetData[0] == PACKET_TYPE_DEPLOY_ASSIGNMENT && packetVersionMatch(packetData)) { + if (nodeList->getNodeSocket()->receive(packetData, &receivedBytes) && + packetData[0] == PACKET_TYPE_DEPLOY_ASSIGNMENT && packetVersionMatch(packetData)) { + + // construct the deployed assignment from the packet data + Assignment deployedAssignment(packetData, receivedBytes); + + qDebug() << "Received an assignment - " << deployedAssignment << "\n"; + + // switch our nodelist DOMAIN_IP to the ip receieved in the assignment + if (deployedAssignment.getDomainSocket()->sa_family == AF_INET) { + in_addr domainSocketAddr = ((sockaddr_in*) deployedAssignment.getDomainSocket())->sin_addr; + nodeList->setDomainIP(inet_ntoa(domainSocketAddr)); - // construct the deployed assignment from the packet data - Assignment deployedAssignment(packetData, receivedBytes); - - qDebug() << "Received an assignment - " << deployedAssignment << "\n"; - - // switch our nodelist DOMAIN_IP to the ip receieved in the assignment - if (deployedAssignment.getDomainSocket()->sa_family == AF_INET) { - in_addr domainSocketAddr = ((sockaddr_in*) deployedAssignment.getDomainSocket())->sin_addr; - nodeList->setDomainIP(inet_ntoa(domainSocketAddr)); - - qDebug() << "Changed domain IP to " << inet_ntoa(domainSocketAddr); - } - - if (deployedAssignment.getType() == Assignment::AudioMixer) { - AudioMixer::run(); - } else { - AvatarMixer::run(); - } - - qDebug() << "Assignment finished or never started - waiting for new assignment"; - - // reset our NodeList by switching back to unassigned and clearing the list - nodeList->setOwnerType(NODE_TYPE_UNASSIGNED); - nodeList->clear(); + qDebug() << "Changed domain IP to " << inet_ntoa(domainSocketAddr); } + + if (deployedAssignment.getType() == Assignment::AudioMixer) { + AudioMixer::run(); + } else { + qDebug() << "Running as an avatar mixer!"; + AvatarMixer::run(); + } + + qDebug() << "Assignment finished or never started - waiting for new assignment"; + + // reset our NodeList by switching back to unassigned and clearing the list + nodeList->setOwnerType(NODE_TYPE_UNASSIGNED); + nodeList->clear(); } } } \ No newline at end of file diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index c650190a4a..db90856251 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -255,6 +255,7 @@ void NodeList::clear() { } _numNodes = 0; + _numNoReplyDomainCheckIns = 0; } void NodeList::setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNodeTypesOfInterest) {