gloox  1.1-svn
asyncdns.h
1 /*
2  Copyright (c) 2009 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 #ifndef ASYNCDNS_H__
14 #define ASYNCDNS_H__
15 
16 #include "asyncdnshandler.h"
17 #include "config.h"
18 #include "macros.h"
19 #include "mutex.h"
20 
21 #include <list>
22 #include <map>
23 #include <string>
24 
25 namespace gloox
26 {
27 
28  class AsyncDNSWorker;
29  class LogSink;
30 
37  class GLOOX_API AsyncDNS : public AsyncDNSHandler
38  {
39  public:
43  AsyncDNS();
44 
48  ~AsyncDNS();
49 
59  void resolve( AsyncDNSHandler* adh, const std::string& service, const std::string& proto,
60  const std::string& domain, const LogSink& logInstance, void* context );
61 
70  void resolve( AsyncDNSHandler* adh, const std::string& domain,
71  const LogSink& logInstance, void* context )
72  { resolve( adh, "xmpp-client", "tcp", domain, logInstance, context ); }
73 
82  void connect( AsyncDNSHandler* adh, const std::string& host,
83  const LogSink& logInstance, void* context );
84 
94  void connect( AsyncDNSHandler* adh, const std::string& host, int port,
95  const LogSink& logInstance, void* context );
96 
97  protected:
98  // reimplemented from AsyncDNSHandler
99  virtual void handleAsyncResolveResult( const DNS::HostMap& hosts, void* context );
100 
101  // reimplemented from AsyncDNSHandler
102  virtual void handleAsyncConnectResult( int fd, void* context );
103 
104  private:
105  struct AsyncContext
106  {
107  AsyncContext( AsyncDNSHandler* adh, void* ctx ) : handler( adh ), context( ctx ) {}
108  AsyncDNSHandler* handler;
109  void* context;
110  };
111 
112  typedef std::map<AsyncDNSWorker*, AsyncContext> WorkerMap;
113  typedef std::list<AsyncDNSWorker*> WorkerList;
114  WorkerMap m_workers;
115  WorkerList m_obsoleteWorkers;
116 
117  util::Mutex m_workerMutex;
118  util::Mutex m_obsoleteWorkerMutex;
119 
120  };
121 
122 }
123 
124 #endif // ASYNCDNS_H__