diff options
-rw-r--r-- | src/dns.cpp | 15 | ||||
-rw-r--r-- | src/dnsqueue.cpp | 3 | ||||
-rw-r--r-- | src/inspircd.cpp | 7 | ||||
-rw-r--r-- | src/socketengine.cpp | 8 |
4 files changed, 29 insertions, 4 deletions
diff --git a/src/dns.cpp b/src/dns.cpp index 88b5d399c..a0e36e600 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -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; @@ -664,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; } @@ -676,6 +682,9 @@ 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; } @@ -699,6 +708,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); @@ -720,6 +732,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) diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp index 99f32988e..e237de677 100644 --- a/src/dnsqueue.cpp +++ b/src/dnsqueue.cpp @@ -60,6 +60,9 @@ using namespace std; #include "dns.h" #include "helperfuncs.h" #include "hashcomp.h" +#include "socketengine.h" + +extern SocketEngine* SE; extern int MaxWhoResults; diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 76c091cac..5a9493b0c 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -2656,10 +2656,6 @@ int InspIRCd(char** argv, int argc) OLDTIME = TIME; TIME = time(NULL); -#ifndef THREADED_DNS - dns_poll(); -#endif - // *FIX* Instead of closing sockets in kill_link when they receive the ERROR :blah line, we should queue // them in a list, then reap the list every second or so. if (((TIME % 5) == 0) && (!expire_run)) @@ -2713,6 +2709,9 @@ int InspIRCd(char** argv, int argc) else if (SE->GetType(activefds[activefd]) == X_ESTAB_DNS) { log(DEBUG,"Got a ready socket of type X_ESTAB_DNS"); +#ifndef THREADED_DNS + dns_poll(); +#endif } else if (SE->GetType(activefds[activefd]) == X_LISTEN) { diff --git a/src/socketengine.cpp b/src/socketengine.cpp index 23088edb9..f19a8d082 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -40,12 +40,16 @@ SocketEngine::~SocketEngine() char SocketEngine::GetType(int fd) { + if ((fd < 0) || (fd > 65535)) + return X_EMPTY_SLOT; /* Mask off the top bit used for 'read/write' state */ return (ref[fd] & ~0x80); } bool SocketEngine::AddFd(int fd, bool readable, char type) { + if ((fd < 0) || (fd > 65535)) + return false; this->fds.push_back(fd); ref[fd] = type; if (readable) @@ -79,6 +83,10 @@ return true; bool SocketEngine::DelFd(int fd) { log(DEBUG,"SocketEngine::DelFd(%d)",fd); + + if ((fd < 0) || (fd > 65535)) + return false; + bool found = false; for (std::vector<int>::iterator i = fds.begin(); i != fds.end(); i++) { |