diff options
author | Sadie Powell <sadie@witchery.services> | 2021-01-19 01:43:24 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2021-01-19 01:43:52 +0000 |
commit | da7cba69389c3c90cb9e02ac2d18f62d3e83a944 (patch) | |
tree | 1dbcef102df9a9629f29453bf4bfb3c9d6741bc5 /src | |
parent | c2369968bcc2a6e919cca9fc688bdd4166b59845 (diff) |
Fix the DNS socket not being closed when core_dns is unloaded.
Diffstat (limited to 'src')
-rw-r--r-- | src/coremods/core_dns.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/coremods/core_dns.cpp b/src/coremods/core_dns.cpp index 11c2c823c..aec413207 100644 --- a/src/coremods/core_dns.cpp +++ b/src/coremods/core_dns.cpp @@ -409,6 +409,19 @@ class MyManager : public Manager, public Timer, public EventHandler this->cache[r.question] = r; } + void Close() + { + // Shutdown the socket if it exists. + if (HasFd()) + { + SocketEngine::Shutdown(this, 2); + SocketEngine::Close(this); + } + + // Remove all entries from the cache. + cache.clear(); + } + public: DNS::Request* requests[MAX_REQUEST_ID+1]; @@ -423,6 +436,7 @@ class MyManager : public Manager, public Timer, public EventHandler ~MyManager() { // Ensure Process() will fail for new requests + Close(); unloading = true; for (unsigned int i = 0; i <= MAX_REQUEST_ID; ++i) @@ -703,23 +717,15 @@ class MyManager : public Manager, public Timer, public EventHandler void Rehash(const std::string& dnsserver, std::string sourceaddr, unsigned int sourceport) { - if (this->HasFd()) - { - SocketEngine::Shutdown(this, 2); - SocketEngine::Close(this); - - // Remove all entries from the cache. - cache.clear(); - } - irc::sockets::aptosa(dnsserver, DNS::PORT, myserver); /* Initialize mastersocket */ + Close(); int s = socket(myserver.family(), SOCK_DGRAM, 0); this->SetFd(s); /* Have we got a socket? */ - if (this->GetFd() != -1) + if (this->HasFd()) { SocketEngine::SetReuse(s); SocketEngine::NonBlocking(s); |