in_queue.push_back(h);
}
+void Resolver::cancel(Host *h)
+{
+ MutexLock l_(mutex);
+
+ if(h==current)
+ {
+ current=0;
+ return;
+ }
+
+ for(list<Host *>::iterator i=in_queue.begin(); i!=in_queue.end(); ++i)
+ if(*i==h)
+ {
+ in_queue.erase(i);
+ break;
+ }
+}
+
void Resolver::tick()
{
MutexLock l_(mutex);
{
while(!done)
{
- Host *host;
+ sockaddr_in addr;
+ addr.sin_family = AF_INET;
{
MutexLock l_(mutex);
if(in_queue.empty())
break;
- host = in_queue.front();
+ current = in_queue.front();
in_queue.erase(in_queue.begin());
+ addr.sin_addr.s_addr = htonl(current->get_address());
}
- sockaddr_in addr;
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = htonl(host->get_address());
char buf[128];
int err = getnameinfo(reinterpret_cast<sockaddr *>(&addr), sizeof(addr), buf, sizeof(buf), 0, 0, NI_NOFQDN|NI_NAMEREQD);
if(err==0)
{
MutexLock l_(mutex);
- out_queue.push_back(Result(host, buf));
+ if(current)
+ out_queue.push_back(Result(current, buf));
}
}