diff options
author | Treeki <treeki@gmail.com> | 2014-02-12 13:27:17 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2014-02-12 13:27:17 +0100 |
commit | d3856992710194330bae59210c4ca6154259ecdc (patch) | |
tree | 3f76efe91f2b76c68675070de442c49bd19a2181 /bouncer/dns.cpp | |
parent | ab96a4a6708a58109154fb3e0959c1b03c3ce302 (diff) | |
download | bounce4-d3856992710194330bae59210c4ca6154259ecdc.tar.gz bounce4-d3856992710194330bae59210c4ca6154259ecdc.zip |
stop DNS thread cleanly when exiting
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]; |