summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-12 12:44:43 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-12 12:44:43 +0000
commit280f52aeae72a3383e1e10b2f2a5952e7b1413b7 (patch)
treef2be3394b53fe6bb4fac93d5b74e2b839698d61c
parentb81c2e4c4eda2c7ae6fa5fbccfe40c94852fdf3b (diff)
*EXPERIMENTAL* Tied DNS into new socket engine
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2331 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/dns.cpp15
-rw-r--r--src/dnsqueue.cpp3
-rw-r--r--src/inspircd.cpp7
-rw-r--r--src/socketengine.cpp8
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++)
{