diff options
Diffstat (limited to '')
-rw-r--r-- | bouncer/dns.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/bouncer/dns.cpp b/bouncer/dns.cpp index 056bb09..f5bb75b 100644 --- a/bouncer/dns.cpp +++ b/bouncer/dns.cpp @@ -22,6 +22,7 @@ struct DNSQuery { }; static DNSQuery dnsQueue[DNS_QUERY_COUNT]; +static bool dnsQuit = false; static pthread_t dnsThread; static pthread_mutex_t dnsQueueMutex; static pthread_cond_t dnsQueueCond; @@ -41,6 +42,16 @@ void DNS::start() { } } +void DNS::stop() { + pthread_mutex_lock(&dnsQueueMutex); + dnsQuit = true; + pthread_mutex_unlock(&dnsQueueMutex); + pthread_cond_signal(&dnsQueueCond); + + pthread_join(dnsThread, NULL); + +} + int DNS::makeQuery(const char *name) { int id = -1; @@ -102,7 +113,9 @@ bool DNS::checkQuery(int id, in_addr *pResult, bool *pIsError) { void *dnsThreadProc(void *) { pthread_mutex_lock(&dnsQueueMutex); - for (;;) { + dnsQuit = false; + + while (!dnsQuit) { for (int i = 0; i < DNS_QUERY_COUNT; i++) { if (dnsQueue[i].status == DQS_WAITING) { char nameCopy[DNS_QUERY_NAME_SIZE]; |