diff options
author | Adam <Adam@anope.org> | 2011-05-21 04:57:27 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-05-21 04:57:27 -0400 |
commit | 115f94bfc23c481eab50298895f76bd494179cd8 (patch) | |
tree | eeda28c466e9f2f532b2dee75cb817eba9066357 /src/dns.cpp | |
parent | 7e5727288d9b2da5b53476b91f8cb9fe96e14d53 (diff) |
Made Anope able to process normally when disconnected from the uplink and not sleep(), enable usage of non-blocking connect() and default all sockets to non blocking mode. Some cleanup to m_ssl and some cleanup to main.cpp.
Diffstat (limited to 'src/dns.cpp')
-rw-r--r-- | src/dns.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/dns.cpp b/src/dns.cpp index 7475545c0..4c1178865 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -42,6 +42,11 @@ void DNSRequest::Process() { Log(LOG_DEBUG_2) << "Resolver: Processing request to lookup " << this->address << ", of type " << this->QT; + if (!DNSEngine) + throw SocketException("DNSEngine has not been initialized"); + else if (!DNSEngine->sock || !DNSEngine->sock->connected) + throw SocketException("Connection to nameserver has not been established"); + if (this->use_cache && DNSEngine->CheckCache(this)) { Log(LOG_DEBUG_2) << "Resolver: Using cached result"; @@ -236,7 +241,8 @@ DNSSocket::~DNSSocket() delete DNSEngine->packets[i - 1]; DNSEngine->packets.clear(); Log(LOG_NORMAL, "dns") << "Resolver: Lost connection to nameserver"; - DNSEngine->sock = NULL; + if (DNSEngine) + DNSEngine->sock = NULL; } int DNSSocket::SendTo(const unsigned char *buf, size_t len) const @@ -497,7 +503,10 @@ bool DNSSocket::ProcessRead() bool DNSSocket::ProcessWrite() { - Log(LOG_DEBUG_2) << "Resolver: Writing to UDP socket"; + if (!this->connected) + return ConnectionSocket::ProcessWrite(); + + Log(LOG_DEBUG_2) << "Resolver: Writing to DNS socket"; bool cont = true; for (unsigned i = DNSEngine->packets.size(); cont && i > 0; --i) @@ -517,6 +526,16 @@ bool DNSSocket::ProcessWrite() return cont; } +void DNSSocket::OnConnect() +{ + Log(LOG_DEBUG_2) << "Resolver: Successfully connected to nameserver"; +} + +void DNSSocket::OnError(const Anope::string &error) +{ + Log() << "Resolver: Error connecting to nameserver: " << error; +} + DNSManager::DNSManager() : Timer(300, Anope::CurTime, true) { this->sock = NULL; |