14 #include "asyncdnshandler.h"
16 #include "mutexguard.h"
23 #if ( defined( _WIN32 ) && !defined( __SYMBIAN32__ ) ) || defined( HAVE_PTHREAD )
25 class AsyncDNSWorker :
public util::Thread
36 AsyncDNSWorker( AsyncDNSHandler* adh,
const std::string& service,
const std::string& proto,
37 const std::string& domain,
const LogSink& logInstance );
46 AsyncDNSWorker( AsyncDNSHandler* adh,
const std::string& host,
47 const LogSink& logInstance );
57 AsyncDNSWorker( AsyncDNSHandler* adh,
const std::string& host,
int port,
58 const LogSink& logInstance );
63 virtual ~AsyncDNSWorker();
78 AsyncDNSHandler* m_adh;
79 std::string m_service;
84 const LogSink& m_logInstance;
90 AsyncDNSWorker::AsyncDNSWorker( AsyncDNSHandler* adh,
const std::string& service,
91 const std::string& proto,
const std::string& domain,
92 const LogSink& logInstance )
93 : m_adh( adh ), m_service( service ), m_proto( proto ), m_domain( domain ), m_port( -1 ),
94 m_logInstance( logInstance ), m_type( Resolve )
98 AsyncDNSWorker::AsyncDNSWorker( AsyncDNSHandler* adh,
const std::string& host,
99 const LogSink& logInstance )
100 : m_adh( adh ), m_host( host ), m_port( -1 ), m_logInstance( logInstance ),
101 m_type( ConnectResolve )
105 AsyncDNSWorker::AsyncDNSWorker( AsyncDNSHandler* adh,
const std::string& host,
int port,
106 const LogSink& logInstance )
107 : m_adh( adh ), m_host( host ), m_port( port ), m_logInstance( logInstance ),
112 AsyncDNSWorker::~AsyncDNSWorker()
116 void AsyncDNSWorker::run()
123 m_adh->handleAsyncResolveResult( hm,
this );
129 m_adh->handleAsyncConnectResult( fd,
this );
135 m_adh->handleAsyncConnectResult( fd,
this );
149 WorkerMap::iterator it = m_workers.begin();
150 for( ; it != m_workers.end(); ++it )
159 const std::string& domain,
const LogSink& logInstance,
void* context )
161 m_obsoleteWorkerMutex.
lock();
163 m_obsoleteWorkerMutex.
unlock();
165 AsyncDNSWorker* adw =
new AsyncDNSWorker(
this, service, proto, domain, logInstance );
166 AsyncContext ac( adh, context );
167 m_workerMutex.
lock();
168 m_workers.insert( std::make_pair( adw, ac ) );
174 const LogSink& logInstance,
void* context )
176 m_obsoleteWorkerMutex.
lock();
178 m_obsoleteWorkerMutex.
unlock();
180 AsyncDNSWorker* adw =
new AsyncDNSWorker(
this, host, logInstance );
181 AsyncContext ac( adh, context );
182 m_workerMutex.
lock();
183 m_workers.insert( std::make_pair( adw, ac ) );
189 const LogSink& logInstance,
void* context )
191 m_obsoleteWorkerMutex.
lock();
193 m_obsoleteWorkerMutex.
unlock();
195 AsyncDNSWorker* adw =
new AsyncDNSWorker(
this, host, port, logInstance );
196 AsyncContext ac( adh, context );
197 m_workerMutex.
lock();
198 m_workers.insert( std::make_pair( adw, ac ) );
205 AsyncDNSWorker* adw =
static_cast<AsyncDNSWorker*
>( context );
208 WorkerMap::iterator it = m_workers.begin();
209 for( ; it != m_workers.end(); ++it )
211 if( (*it).first == adw )
214 void* ctx = (*it).second.context;
215 m_obsoleteWorkerMutex.
lock();
216 m_obsoleteWorkers.push_back( (*it).first );
217 m_obsoleteWorkerMutex.
unlock();
218 m_workers.erase( it );
227 AsyncDNSWorker* adw =
static_cast<AsyncDNSWorker*
>( context );
230 WorkerMap::iterator it = m_workers.begin();
231 for( ; it != m_workers.end(); ++it )
233 if( (*it).first == adw )
236 void* ctx = (*it).second.context;
237 m_obsoleteWorkerMutex.
lock();
238 m_obsoleteWorkers.push_back( (*it).first );
239 m_obsoleteWorkerMutex.
unlock();
240 m_workers.erase( it );
249 #endif // WANT_ASYNC_DNS