mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:06:02 +02:00
use deque of pointers, make sure DS silent count is refreshed
This commit is contained in:
parent
9244ec1c25
commit
f7b0158cfe
5 changed files with 25 additions and 46 deletions
|
@ -21,7 +21,7 @@ const int MAX_PACKET_SIZE_BYTES = 1400;
|
||||||
|
|
||||||
int main(int argc, const char* argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
|
|
||||||
std::deque<Assignment> assignmentQueue;
|
std::deque<Assignment*> assignmentQueue;
|
||||||
|
|
||||||
sockaddr_in senderSocket;
|
sockaddr_in senderSocket;
|
||||||
unsigned char senderData[MAX_PACKET_SIZE_BYTES] = {};
|
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
|
// make sure there are assignments in the queue at all
|
||||||
if (assignmentQueue.size() > 0) {
|
if (assignmentQueue.size() > 0) {
|
||||||
|
|
||||||
|
std::deque<Assignment*>::iterator assignment = assignmentQueue.begin();
|
||||||
|
|
||||||
// enumerate assignments until we find one to give this client (if possible)
|
// enumerate assignments until we find one to give this client (if possible)
|
||||||
for (std::deque<Assignment>::iterator assignment = assignmentQueue.begin();
|
while (assignment != assignmentQueue.end()) {
|
||||||
assignment != assignmentQueue.end();
|
|
||||||
assignment++) {
|
|
||||||
|
|
||||||
bool eitherHasPool = (assignment->getPool() || requestAssignment.getPool());
|
bool eitherHasPool = ((*assignment)->getPool() || requestAssignment.getPool());
|
||||||
bool bothHavePool = (assignment->getPool() && requestAssignment.getPool());
|
bool bothHavePool = ((*assignment)->getPool() && requestAssignment.getPool());
|
||||||
|
|
||||||
// make sure there is a pool match for the created and requested assignment
|
// make sure there is a pool match for the created and requested assignment
|
||||||
// or that neither has a designated pool
|
// or that neither has a designated pool
|
||||||
if ((eitherHasPool && bothHavePool
|
if ((eitherHasPool && bothHavePool
|
||||||
&& strcmp(assignment->getPool(), requestAssignment.getPool()) == 0)
|
&& strcmp((*assignment)->getPool(), requestAssignment.getPool()) == 0)
|
||||||
|| !eitherHasPool) {
|
|| !eitherHasPool) {
|
||||||
assignmentQueue.erase(assignment);
|
|
||||||
|
|
||||||
int numAssignmentBytes = assignment->packToBuffer(assignmentPacket + numSendHeaderBytes);
|
int numAssignmentBytes = (*assignment)->packToBuffer(assignmentPacket + numSendHeaderBytes);
|
||||||
|
|
||||||
// send the assignment
|
// send the assignment
|
||||||
serverSocket.send((sockaddr*) &senderSocket,
|
serverSocket.send((sockaddr*) &senderSocket,
|
||||||
assignmentPacket,
|
assignmentPacket,
|
||||||
numSendHeaderBytes + numAssignmentBytes);
|
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)) {
|
} else if (senderData[0] == PACKET_TYPE_CREATE_ASSIGNMENT && packetVersionMatch(senderData)) {
|
||||||
// construct the create assignment from the packet data
|
// 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() << "Received a created assignment:" << createdAssignment;
|
||||||
qDebug() << "Current queue size is" << assignmentQueue.size();
|
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
|
// assignment server is on a public server
|
||||||
// assume that the address we now have for the sender is the public address/port
|
// 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
|
// 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
|
// add this assignment to the queue
|
||||||
assignmentQueue.push_back(createdAssignment);
|
assignmentQueue.push_back(createdAssignment);
|
||||||
|
|
|
@ -391,7 +391,7 @@ void AudioMixer::run() {
|
||||||
|
|
||||||
// give the new audio data to the matching injector node
|
// give the new audio data to the matching injector node
|
||||||
nodeList->updateNodeWithData(matchingInjector, packetData, receivedBytes);
|
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.
|
// If the packet is a ping, let processNodeData handle it.
|
||||||
nodeList->processNodeData(nodeAddress, packetData, receivedBytes);
|
nodeList->processNodeData(nodeAddress, packetData, receivedBytes);
|
||||||
|
|
|
@ -139,9 +139,6 @@ void AvatarMixer::run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PACKET_TYPE_DOMAIN:
|
|
||||||
// ignore the DS packet, for now nodes are added only when they communicate directly with us
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
// hand this off to the NodeList
|
// hand this off to the NodeList
|
||||||
nodeList->processNodeData(nodeAddress, packetData, receivedBytes);
|
nodeList->processNodeData(nodeAddress, packetData, receivedBytes);
|
||||||
|
|
|
@ -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() {
|
Assignment::~Assignment() {
|
||||||
delete _domainSocket;
|
delete _domainSocket;
|
||||||
delete _pool;
|
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
|
// create a new sockaddr or sockaddr_in depending on what type of address this is
|
||||||
if (domainSocket->sa_family == AF_INET) {
|
if (domainSocket->sa_family == AF_INET) {
|
||||||
sockaddr_in* newSocket = new sockaddr_in;
|
_domainSocket = (sockaddr*) new sockaddr_in;
|
||||||
memcpy(newSocket, domainSocket, sizeof(sockaddr_in));
|
memcpy(_domainSocket, domainSocket, sizeof(sockaddr_in));
|
||||||
_domainSocket = (sockaddr*) newSocket;
|
|
||||||
} else {
|
} else {
|
||||||
sockaddr_in6* newSocket = new sockaddr_in6;
|
_domainSocket = (sockaddr*) new sockaddr_in6;
|
||||||
memcpy(newSocket, domainSocket, sizeof(sockaddr_in6));
|
memcpy(_domainSocket, domainSocket, sizeof(sockaddr_in6));
|
||||||
_domainSocket = (sockaddr*) newSocket;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
|
|
||||||
Assignment(Assignment::Direction direction, Assignment::Type type, const char* pool = NULL);
|
Assignment(Assignment::Direction direction, Assignment::Type type, const char* pool = NULL);
|
||||||
Assignment(const unsigned char* dataBuffer, int numBytes);
|
Assignment(const unsigned char* dataBuffer, int numBytes);
|
||||||
Assignment(const Assignment& assignment);
|
|
||||||
~Assignment();
|
~Assignment();
|
||||||
|
|
||||||
Assignment::Direction getDirection() const { return _direction; }
|
Assignment::Direction getDirection() const { return _direction; }
|
||||||
|
|
Loading…
Reference in a new issue