summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-02 20:54:39 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-02 20:54:39 +0000
commitc47d3335e75a11904a96f086db7bd113dfb15196 (patch)
tree5b53232f34b0c706540c37623c1d68702dc3dafd
parentacff2ca6dccce9ed309fe1ca3df5d89791eedb74 (diff)
Absolutely everything is now part of class DNS, or class Resolver.
This means our dns code is totally encapsulated and we know that changing it wont effect anything else so long as the interface stays the same. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4656 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/dns.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/dns.cpp b/src/dns.cpp
index b82e705cd..eed8095ce 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -596,12 +596,14 @@ DNSInfo DNSRequest::ResultIsReady(DNSHeader &header, int length)
return std::make_pair(res,"No error");;
}
+/* Close the master socket */
DNS::~DNS()
{
shutdown(MasterSocket, 2);
close(MasterSocket);
}
+/* High level abstraction of dns used by application at large */
Resolver::Resolver(const std::string &source, bool forward) : input(source), fwd(forward)
{
if (forward)
@@ -639,30 +641,38 @@ Resolver::Resolver(const std::string &source, bool forward) : input(source), fwd
void Resolver::OnError(ResolverError e, const std::string &errormessage)
{
+ /* Nothing in here */
}
Resolver::~Resolver()
{
- log(DEBUG,"Resolver::~Resolver");
+ /* Nothing here (yet) either */
}
+/* Get the request id associated with this class */
int Resolver::GetId()
{
return this->myid;
}
+/* Process a socket read event */
void DNS::MarshallReads(int fd)
{
- log(DEBUG,"dns_deal_with_classes(%d)",fd);
+ /* We are only intrested in our single fd */
if (fd == GetMasterSocket())
{
+ /* Fetch the id and result of the next available packet */
DNSResult res = this->GetResult();
+ /* Is there a usable request id? */
if (res.first != -1)
{
+ /* Its an error reply */
if (res.first & ERROR_MASK)
{
+ /* Mask off the error bit */
res.first -= ERROR_MASK;
+ /* Marshall the error to the correct class */
log(DEBUG,"Error available, id=%d",res.first);
if (Classes[res.first])
{
@@ -673,7 +683,9 @@ void DNS::MarshallReads(int fd)
}
else
{
+ /* It is a non-error result */
log(DEBUG,"Result available, id=%d",res.first);
+ /* Marshall the result to the correct class */
if (Classes[res.first])
{
Classes[res.first]->OnLookupComplete(res.second);
@@ -685,23 +697,35 @@ void DNS::MarshallReads(int fd)
}
}
+/* Add a derived Resolver to the working set */
bool DNS::AddResolverClass(Resolver* r)
{
+ /* Check the pointers validity and the id's validity */
if ((r) && (r->GetId() > -1))
{
+ /* Check the slot isnt already occupied -
+ * This should NEVER happen unless we have
+ * a severely broken DNS server somewhere
+ */
if (!Classes[r->GetId()])
{
+ /* Set up the pointer to the class */
Classes[r->GetId()] = r;
return true;
}
else
+ /* Duplicate id */
return false;
}
else
{
- delete r;
- return true;
+ /* Pointer or id not valid.
+ * Free the item and return
+ */
+ if (r)
+ delete r;
+
+ return false;
}
}
-