I have this map
std::map<IPv4Address,std::vector<Agent>> report;
Where agent is defined as the following
typedef struct
{
IPv4Address Address;
AgentType Type;
std::map <IPv4Address, IPRoute> RoutingTable;
MetricType metric;
int UpdateReceived = 0;
}Agent;
I am sending this Agent struct through tcp sockets and saving the values in the report std::map
int receive = recv(as.socket, (void *) &agent, sizeof(agent),0);
The routing table is initially empty and there is no problem, but when the routing table size becomes >=1 the app crashes when adding it like the following
mutex.lock();
PrintInfo("Mutex locked");
if(report.find(as.ip) != report.end())
{
//f tells us if the agent was connected before to the router
bool f = false;
std::vector<Agent> tmpv =report[as.ip];
int tmp;
PrintInfo("Vector loop");
for(std::size_t i=0 ; i < tmpv.size() ; i++)
{
if(tmpv[i].Type == agent.Type)
{
f = true;
tmp = i;
break;
}
}
PrintInfo("Vector loop End");
if(f)
{
PrintInfo("Found -> Replacing");
--> This line crashes report[as.ip][tmp] = agent;
}
else
{
PrintInfo("Not Found -> Adding");
report[as.ip].push_back(agent);
}
PrintInfo("After add");
}
Aucun commentaire:
Enregistrer un commentaire