EpcTools
An event based multi-threaded C++ development framework.
|
Go to the documentation of this file.
37 typedef int namedserverid_t;
42 const namedserverid_t NS_DEFAULT = 0;
49 friend QueryProcessor;
52 QueryProcessorThread(QueryProcessor &qp);
54 Void incActiveQueries() { m_activequeries.Increment(); }
55 Void decActiveQueries() { m_activequeries.Decrement(); }
56 int getActiveQueries() {
return m_activequeries.currCount(); }
58 virtual Dword threadProc(Void *arg);
63 static Void ares_callback( Void *arg,
int status,
int timeouts,
unsigned char *abuf,
int alen );
66 QueryProcessorThread();
67 Void wait_for_completion();
91 friend QueryProcessorThread;
94 QueryProcessor(
Cache &cache );
97 Cache &getCache() {
return m_cache; }
101 QueryProcessorThread *getQueryProcessorThread() {
return &m_qpt; }
103 Void addNamedServer(
const char *address,
int udp_port,
int tcp_port);
104 Void removeNamedServer(
const char *address);
105 Void applyNamedServers();
110 ares_channel getChannel() {
return m_channel; }
120 QueryProcessorThread m_qpt;
121 ares_channel m_channel;
122 std::map<const char *,NamedServer> m_servers;
129 #define SAVED_QUERY_TYPE "type"
130 #define SAVED_QUERY_DOMAIN "domain"
132 const uint16_t CR_SAVEQUERIES =
EM_USER + 1;
133 const uint16_t CR_FORCEREFRESH =
EM_USER + 2;
140 CacheRefresher(
Cache &cache,
unsigned int maxconcur,
int percent,
long interval);
142 virtual Void onInit();
143 virtual Void onQuit();
148 const EString &queryFileName() {
return m_qfn; }
149 long querySaveFrequency() {
return m_qsf; }
151 Void loadQueries(
const char *qfn);
152 Void loadQueries(
const std::string &qfn) { loadQueries(qfn.c_str()); }
153 Void initSaveQueries(
const char *qfn,
long qsf);
154 Void saveQueries() { sendMessage(CR_SAVEQUERIES); }
155 Void forceRefresh() { sendMessage(CR_FORCEREFRESH); }
161 static Void callback(
QueryPtr q, Bool cacheHit,
const Void *data );
162 Void _submitQueries( std::list<QueryCacheKey> &keys );
163 Void _refreshQueries();
165 Void _forceRefresh();
186 friend QueryProcessor;
187 friend QueryProcessorThread;
189 friend CacheRefresher;
234 Void
addNamedServer(
const char *address,
int udp_port=53,
int tcp_port=53);
247 QueryPtr query( ns_type rtype,
const std::string &domain, Bool &cacheHit, Bool ignorecache=
false );
254 Void
query( ns_type rtype,
const std::string &domain, CachedDNSQueryCallback cb,
const Void *data=NULL, Bool ignorecache=
false );
282 QueryPtr lookupQuery( ns_type rtype,
const std::string &domain );
283 QueryPtr lookupQuery( QueryCacheKey &qck );
285 Void identifyExpired( std::list<QueryCacheKey> &keys,
int percent );
286 Void getCacheKeys( std::list<QueryCacheKey> &keys );
292 static unsigned int m_concur;
293 static int m_percent;
294 static long m_interval;
297 CacheRefresher m_refresher;
299 namedserverid_t m_nsid;
305 #endif // #ifndef __DNSCACHE_H
Thread timer class.
Definition: etevent.h:852
Void forceRefresh()
Forces a refresh of the DNS cache.
Definition: dnscache.cpp:518
Void applyNamedServers()
Updates the named servers as a set in the underlying c-ares library.
Definition: dnscache.cpp:461
An event message that is to be sent to a thread.
Definition: etevent.h:266
static Cache & getInstance()
Retrieves/creates the default Cache instance.
Definition: dnscache.h:203
Void loadQueries(const std::string &qfn)
Executes the DNS queries at startup from the suppoied file.
Definition: dnscache.h:261
static long setRefreshInterval(long interval)
Assigns the refresh interval.
Definition: dnscache.h:228
Contains the definition of the DNS query related classes.
static unsigned int getRefreshConcurrent()
Retrieves the current setting of the maximum number of conncurrent DNS queries that can be performed ...
Definition: dnscache.h:207
static int setRefreshPercent(int percent)
Assigns the refresh percentage value.
Definition: dnscache.h:220
A private mutex (the mutex data is allocated from either the heap or stack).
Definition: esynch.h:175
base class for EThreadPrivate and EThreadPublic
Definition: etevent.h:1040
#define atomic_swap(a, b)
atomic swap - replaces a with b
Definition: eatomic.h:39
Contains definitions for synchronization objects.
Void saveQueries()
Saves the DNS queries that are part of the cache.
Definition: dnscache.cpp:513
Macros for performing CPU atomic/interlaced operations.
Encapsulates a read-write lock object.
Definition: esynch.h:507
namedserverid_t getNamedServerId()
Retrieves the named server ID associated with this DNS cache.
Definition: dnscache.h:273
Cache()
Default constructor.
Definition: dnscache.cpp:372
#define EM_USER
beginning of user events
Definition: etevent.h:786
long resetNewQueryCount()
Resets the number of new queries (not saved) to zero.
Definition: dnscache.h:277
Represents a private semaphore, the semaphore data is allocated from either the stack or heap.
Definition: esynch.h:382
Defines the functionality associated with a DNS cache.
Definition: dnscache.h:184
Void addNamedServer(const char *address, int udp_port=53, int tcp_port=53)
Adds a named server to this DNS cache object.
Definition: dnscache.cpp:451
QueryPtr query(ns_type rtype, const std::string &domain, Bool &cacheHit, Bool ignorecache=false)
Performs a DNS query synchronously.
Definition: dnscache.cpp:466
Void initSaveQueries(const char *qfn, long qsf)
Initializes the settings used to save queries.
Definition: dnscache.cpp:508
An abstract class that represents contains the threadProc() that will be run in a separate thread.
Definition: etbasic.h:53
#define DECLARE_MESSAGE_MAP()
Inserts message map declarations into the thread class.
Definition: etevent.h:793
static long getRefeshInterval()
Retrieves the refresh interval.
Definition: dnscache.h:224
Void loadQueries(const char *qfn)
Executes the DNS queries at startup from the suppoied file.
Definition: dnscache.cpp:503
static unsigned int setRefreshConcurrent(unsigned int concur)
Sets the maximum number of conncurrent DNS queries that can be performed while refreshing the DNS cac...
Definition: dnscache.h:212
Definition: dnscache.h:33
~Cache()
Class destructor.
Definition: dnscache.cpp:395
String class.
Definition: estring.h:30
std::shared_ptr< Query > QueryPtr
A typedef to std::shared_ptr<Query>.
Definition: dnsquery.h:40
Void removeNamedServer(const char *address)
Removes the specified named server from this DNS cache.
Definition: dnscache.cpp:456
static int getRefreshPercent()
Retrieves the current refresh percentage value.
Definition: dnscache.h:216