/*----------------------------------------------------------------------------- * dnslookupworker.cpp * Copyright (C) 2003, 2004, 2005 Akito Nozaki * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include #include #include #include #include #include #include #include NAMESPACE_TANOSHI { DnsLookupWorker::DnsLookupWorker(DnsLookup *dnslookup, const std::string &domain) : Thread() { _dnslookup = dnslookup; _domain = domain; } DnsLookupWorker::~DnsLookupWorker() { } HostAddress DnsLookupWorker::getHostAddress() { return _addr; } void DnsLookupWorker::run() { // MacOS X's getaddrinfo isn't thread safe. All others is thread safe // and should be ok. // // Ok more note... glibc had a bug with getaddrinfo that was causing // memory leak. glibc-2.3.3-84 has the fix and should be free from // memory leak. addrinfo *resdata = 0; if(getaddrinfo(_domain.c_str(), 0, 0, &resdata) != 0) { if(resdata) freeaddrinfo(resdata); _dnslookup->wakeup.wakeup(); return; } _addr.setAddress(ntohl(((sockaddr_in *)resdata->ai_addr)->sin_addr.s_addr)); freeaddrinfo(resdata); _dnslookup->wakeup.wakeup(); } }