]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dns.cpp
Comment and tidyup
[user/henk/code/inspircd.git] / src / dns.cpp
index fbe512b9f113a5e9fc663da8279a56435c75d3a7..9d67d5c12e2b990a14db595484460bd05991bb01 100644 (file)
@@ -37,6 +37,9 @@ using namespace std;
 #include <arpa/inet.h>
 #include "dns.h"
 #include "helperfuncs.h"
+#include "socketengine.h"
+
+extern SocketEngine* SE;
 
 extern int statsAccept,statsRefused,statsUnknown,statsCollisions,statsDns,statsDnsGood,statsDnsBad,statsConnects,statsSent,statsRecv;
 
@@ -648,7 +651,6 @@ void DNS::SetNS(std::string dnsserver)
 
 DNS::~DNS()
 {
-       log(DEBUG,"Delete DNS fd=%d",this->myfd);
 }
 
 bool DNS::ReverseLookup(std::string ip)
@@ -665,6 +667,9 @@ bool DNS::ReverseLookup(std::string ip)
                return false;
        }
        log(DEBUG,"DNS: ReverseLookup, fd=%d",this->myfd);
+#ifndef THREADED_DNS
+       SE->AddFd(this->myfd,true,X_ESTAB_DNS);
+#endif
        return true;
 }
 
@@ -677,9 +682,21 @@ bool DNS::ForwardLookup(std::string host)
                return false;
        }
        log(DEBUG,"DNS: ForwardLookup, fd=%d",this->myfd);
+#ifndef THREADED_DNS
+       SE->AddFd(this->myfd,true,X_ESTAB_DNS);
+#endif
        return true;
 }
 
+bool DNS::HasResult(int fd)
+{
+       return (fd == this->myfd);
+}
+
+/* Only the multithreaded dns uses this poll() based
+ * check now. As its in another thread we dont have
+ * to worry about its performance that much.
+ */
 bool DNS::HasResult()
 {
        log(DEBUG,"DNS: HasResult, fd=%d",this->myfd);
@@ -700,6 +717,9 @@ std::string DNS::GetResult()
 {
        log(DEBUG,"DNS: GetResult()");
         result = dns_getresult(this->myfd);
+#ifndef THREADED_DNS
+       SE->DelFd(this->myfd);
+#endif
         if (result) {
                statsDnsGood++;
                dns_close(this->myfd);
@@ -721,6 +741,9 @@ std::string DNS::GetResultIP()
        result = dns_getresult(this->myfd);
        if (this->myfd != -1)
        {
+#ifndef THREADED_DNS
+               SE->DelFd(this->myfd);
+#endif
                dns_close(this->myfd);
        }
        if (result)