本文整理汇总了C++中Address::compareDest方法的典型用法代码示例。如果您正苦于以下问题:C++ Address::compareDest方法的具体用法?C++ Address::compareDest怎么用?C++ Address::compareDest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::compareDest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void NetworkManager::run()
{
if ( resolving && ! resolver_busy ) // finished resolv
{
resolving = false;
bool found_wanted = false;
for ( std::list<Address>::iterator i = rqueue.begin(); i != rqueue.end(); i++ )
{
if ( thread_work.compareDest(*i) )
{
(*i) = thread_work;
found_wanted = true;
break;
}
}
--to_resolve;
resolving = false;
if ( ! found_wanted )
{
LOGGER.warning("Resolved something unwanted");
}
}
if ( to_resolve > 0 && ! resolving )
{
bool found_waiting = false;
for ( std::list<Address>::iterator i = rqueue.begin(); i != rqueue.end(); i++ )
{
if ( (*i).status == Address::ST_WAITING )
{
(*i).status = Address::ST_RESOLVING;
thread_work = (*i);
found_waiting = true;
break;
}
}
resolver_busy = true;
resolving = true;
SDL_SemPost(semaphore);
if ( ! found_waiting )
{
LOGGER.warning("to_resolve has something but there is no waiting here");
}
}
SocketManager::handleEvents();
}
示例2: queryAddress
int NetworkManager::queryAddress(Address &address)
{
struct addrinfo hints;
struct addrinfo *firstaddress = 0;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = address.socktype;
hints.ai_protocol = address.protocol;
if ( address.forBinding )
{
hints.ai_flags = AI_PASSIVE;
}
hints.ai_flags |= AI_NUMERICHOST|AI_NUMERICSERV;
int res = getaddrinfo(address.str_host.size() > 0 ? address.str_host.c_str() : 0,
address.str_port.c_str(),
&hints, &firstaddress);
if ( res )
{
freeaddrinfo(firstaddress);
for ( std::list<Address>::iterator i = rqueue.begin(); i != rqueue.end(); i++ )
{
if ( address.compareDest(*i) )
{
switch ( (*i).status )
{
case Address::ST_OK :
address.ss_len = (*i).ss_len;
memcpy(&address.ss, &(*i).ss, (*i).ss_len);
// fall through
case Address::ST_ERROR :
address.status = (*i).status;
rqueue.erase(i);
break;
default:
address.status = (*i).status;
}
return address.status;
}
}
address.status = Address::ST_WAITING;
rqueue.push_back(address);
++to_resolve;
}
else
{
address.ss_len = firstaddress->ai_addrlen;
memcpy(&address.ss, firstaddress->ai_addr, firstaddress->ai_addrlen);
freeaddrinfo(firstaddress);
address.status = Address::ST_OK;
}
return address.status;
}