summaryrefslogtreecommitdiff
path: root/bouncer
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2014-02-12 13:27:17 +0100
committerTreeki <treeki@gmail.com>2014-02-12 13:27:17 +0100
commitd3856992710194330bae59210c4ca6154259ecdc (patch)
tree3f76efe91f2b76c68675070de442c49bd19a2181 /bouncer
parentab96a4a6708a58109154fb3e0959c1b03c3ce302 (diff)
downloadbounce4-d3856992710194330bae59210c4ca6154259ecdc.tar.gz
bounce4-d3856992710194330bae59210c4ca6154259ecdc.zip
stop DNS thread cleanly when exiting
Diffstat (limited to 'bouncer')
-rw-r--r--bouncer/dns.cpp15
-rw-r--r--bouncer/dns.h1
-rw-r--r--bouncer/main.cpp2
3 files changed, 17 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];
diff --git a/bouncer/dns.h b/bouncer/dns.h
index 78ec75f..90ba7dc 100644
--- a/bouncer/dns.h
+++ b/bouncer/dns.h
@@ -7,6 +7,7 @@
namespace DNS {
void start();
+ void stop();
int makeQuery(const char *name);
void closeQuery(int id);
bool checkQuery(int id, in_addr *pResult, bool *pIsError);
diff --git a/bouncer/main.cpp b/bouncer/main.cpp
index 6c248c8..b021120 100644
--- a/bouncer/main.cpp
+++ b/bouncer/main.cpp
@@ -53,6 +53,8 @@ int main(int argc, char **argv) {
bounce.loadConfig();
int errcode = bounce.execute();
+
+ DNS::stop();
if (errcode < 0) {
printf("(Bouncer::execute failed with %d)\n", errcode);
return EXIT_FAILURE;