*EXPERIMENTAL* Tied DNS into new socket engine

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2331 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2005-12-12 12:44:43 +00:00
parent b81c2e4c4e
commit 280f52aeae
4 changed files with 29 additions and 4 deletions

View 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;
@ -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)

View File

@ -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;

View File

@ -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)
{

View File

@ -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++)
{