use deque of pointers, make sure DS silent count is refreshed

This commit is contained in:
Stephen Birarda 2013-09-06 10:26:29 -07:00
parent 9244ec1c25
commit f7b0158cfe
5 changed files with 25 additions and 46 deletions

View file

@ -21,7 +21,7 @@ const int MAX_PACKET_SIZE_BYTES = 1400;
int main(int argc, const char* argv[]) {
std::deque<Assignment> assignmentQueue;
std::deque<Assignment*> assignmentQueue;
sockaddr_in senderSocket;
unsigned char senderData[MAX_PACKET_SIZE_BYTES] = {};
@ -44,33 +44,41 @@ int main(int argc, const char* argv[]) {
// make sure there are assignments in the queue at all
if (assignmentQueue.size() > 0) {
std::deque<Assignment*>::iterator assignment = assignmentQueue.begin();
// enumerate assignments until we find one to give this client (if possible)
for (std::deque<Assignment>::iterator assignment = assignmentQueue.begin();
assignment != assignmentQueue.end();
assignment++) {
while (assignment != assignmentQueue.end()) {
bool eitherHasPool = (assignment->getPool() || requestAssignment.getPool());
bool bothHavePool = (assignment->getPool() && requestAssignment.getPool());
bool eitherHasPool = ((*assignment)->getPool() || requestAssignment.getPool());
bool bothHavePool = ((*assignment)->getPool() && requestAssignment.getPool());
// make sure there is a pool match for the created and requested assignment
// or that neither has a designated pool
if ((eitherHasPool && bothHavePool
&& strcmp(assignment->getPool(), requestAssignment.getPool()) == 0)
&& strcmp((*assignment)->getPool(), requestAssignment.getPool()) == 0)
|| !eitherHasPool) {
assignmentQueue.erase(assignment);
int numAssignmentBytes = assignment->packToBuffer(assignmentPacket + numSendHeaderBytes);
int numAssignmentBytes = (*assignment)->packToBuffer(assignmentPacket + numSendHeaderBytes);
// send the assignment
serverSocket.send((sockaddr*) &senderSocket,
assignmentPacket,
numSendHeaderBytes + numAssignmentBytes);
// delete this assignment now that it has been sent out
delete *assignment;
// remove it from the deque and make the iterator the next assignment
assignment = assignmentQueue.erase(assignment);
} else {
// push forward the iterator
assignment++;
}
}
}
} else if (senderData[0] == PACKET_TYPE_CREATE_ASSIGNMENT && packetVersionMatch(senderData)) {
// construct the create assignment from the packet data
Assignment createdAssignment(senderData, receivedBytes);
Assignment* createdAssignment = new Assignment(senderData, receivedBytes);
qDebug() << "Received a created assignment:" << createdAssignment;
qDebug() << "Current queue size is" << assignmentQueue.size();
@ -78,7 +86,7 @@ int main(int argc, const char* argv[]) {
// assignment server is on a public server
// assume that the address we now have for the sender is the public address/port
// and store that with the assignment so it can be given to the requestor later
createdAssignment.setDomainSocket((sockaddr*) &senderSocket);
createdAssignment->setDomainSocket((sockaddr*) &senderSocket);
// add this assignment to the queue
assignmentQueue.push_back(createdAssignment);

View file

@ -391,7 +391,7 @@ void AudioMixer::run() {
// give the new audio data to the matching injector node
nodeList->updateNodeWithData(matchingInjector, packetData, receivedBytes);
} else if (packetData[0] == PACKET_TYPE_PING) {
} else if (packetData[0] == PACKET_TYPE_PING || packetData[0] == PACKET_TYPE_DOMAIN) {
// If the packet is a ping, let processNodeData handle it.
nodeList->processNodeData(nodeAddress, packetData, receivedBytes);

View file

@ -139,9 +139,6 @@ void AvatarMixer::run() {
}
}
break;
case PACKET_TYPE_DOMAIN:
// ignore the DS packet, for now nodes are added only when they communicate directly with us
break;
default:
// hand this off to the NodeList
nodeList->processNodeData(nodeAddress, packetData, receivedBytes);

View file

@ -70,30 +70,6 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
}
}
Assignment::Assignment(const Assignment& assignment) :
_pool(NULL),
_domainSocket(NULL)
{
_direction = assignment._direction;
_type = assignment._type;
if (assignment._pool) {
_pool = new char[strlen(assignment._pool)];
strcpy(_pool, assignment._pool);
}
if (assignment._domainSocket) {
if (assignment._domainSocket->sa_family == AF_INET) {
_domainSocket = (sockaddr*) new sockaddr_in;
memcpy(_domainSocket, assignment._domainSocket, sizeof(sockaddr_in));
} else {
_domainSocket = (sockaddr*) new sockaddr_in6;
memcpy(_domainSocket, assignment._domainSocket, sizeof(sockaddr_in6));
}
}
}
Assignment::~Assignment() {
delete _domainSocket;
delete _pool;
@ -137,13 +113,11 @@ void Assignment::setDomainSocket(const sockaddr* domainSocket) {
// create a new sockaddr or sockaddr_in depending on what type of address this is
if (domainSocket->sa_family == AF_INET) {
sockaddr_in* newSocket = new sockaddr_in;
memcpy(newSocket, domainSocket, sizeof(sockaddr_in));
_domainSocket = (sockaddr*) newSocket;
_domainSocket = (sockaddr*) new sockaddr_in;
memcpy(_domainSocket, domainSocket, sizeof(sockaddr_in));
} else {
sockaddr_in6* newSocket = new sockaddr_in6;
memcpy(newSocket, domainSocket, sizeof(sockaddr_in6));
_domainSocket = (sockaddr*) newSocket;
_domainSocket = (sockaddr*) new sockaddr_in6;
memcpy(_domainSocket, domainSocket, sizeof(sockaddr_in6));
}
}

View file

@ -28,7 +28,7 @@ public:
Assignment(Assignment::Direction direction, Assignment::Type type, const char* pool = NULL);
Assignment(const unsigned char* dataBuffer, int numBytes);
Assignment(const Assignment& assignment);
~Assignment();
Assignment::Direction getDirection() const { return _direction; }