Beispiel #1
0
void CHostSet::update_hosts(const char *file_name)
{
	int count = 0;
	CFileReader reader(file_name);
	int host_id;
	
	while (reader.get_next()) {
		const char *begin = reader.begin();
		const char *end = reader.end();
		// skip empty lines
		if (end == begin) continue;
		CHostData t_host(begin, end);
		// get host id
		host_id = t_host.host_id();
		// find host
		CHostData *host = m_hosts[host_id];
		// std::map automatically creates new entry if key is not found
		if (host == 0) {
			// add new if not exist
			logger->log(2, "Adding new host %d", host_id);
			host = new CHostData(begin, end);
			m_hosts[host_id] = host;
		}
		// update values
		host->from_string(begin, end);
		count++;
	}
	reader.close();
	calc_priorities();
}
Beispiel #2
0
bool hostArray::addHost(const std::string& ip, const std::string& port)
{
	for (auto hItr : m_Hosts)
	{
		if (hItr.getIp().compare(ip) == 0 && hItr.getPort().compare(port) == 0)
		{
			return false;
		}
	}
	host t_host(ip,port);
	m_Hosts.push_back(t_host);
	return true;
}