Splitting line, adding agentId to copy constructor and swap

This commit is contained in:
Leonardo Murillo 2013-03-25 15:54:08 -06:00
parent fc382997bd
commit 54a946ee80
2 changed files with 10 additions and 1 deletions

View file

@ -84,8 +84,13 @@ int main(int argc, const char * argv[])
agentType = packetData[0];
unpackSocket(&packetData[1], (sockaddr *)&agentLocalAddress);
if (agentList.addOrUpdateAgent((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType, agentList.getLastAgentId())) {
if (agentList.addOrUpdateAgent((sockaddr *)&agentPublicAddress,
(sockaddr *)&agentLocalAddress,
agentType,
agentList.getLastAgentId())) {
agentList.increaseAgentId();
}
currentBufferPos = broadcastPacket + 1;

View file

@ -43,6 +43,9 @@ Agent::Agent(const Agent &otherAgent) {
localSocket = new sockaddr;
memcpy(localSocket, otherAgent.localSocket, sizeof(sockaddr));
agentId = *new uint16_t;
memcpy(&agentId, &otherAgent.agentId, sizeof(uint16_t));
if (otherAgent.activeSocket == otherAgent.publicSocket) {
activeSocket = publicSocket;
} else if (otherAgent.activeSocket == otherAgent.localSocket) {
@ -153,6 +156,7 @@ void Agent::swap(Agent &first, Agent &second) {
swap(first.activeSocket, second.activeSocket);
swap(first.type, second.type);
swap(first.linkedData, second.linkedData);
swap(first.agentId, second.agentId);
}
bool Agent::matches(sockaddr *otherPublicSocket, sockaddr *otherLocalSocket, char otherAgentType) {