summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-02-02 17:24:15 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-02-02 17:24:15 +0000
commitcb16da88946f7f75a438b471734fa22c33f94461 (patch)
tree118fef6adfae1c2557940b59a191f0d9e6db7a6e /src
parent9bc4f0e2e430de5fff576ba456f7485b6cfe529d (diff)
More nonblocking dns stuffs
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3020 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/modules/m_ident.cpp5
-rw-r--r--src/socket.cpp23
2 files changed, 24 insertions, 4 deletions
diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp
index 1b92b07db..93fe115a2 100644
--- a/src/modules/m_ident.cpp
+++ b/src/modules/m_ident.cpp
@@ -98,6 +98,11 @@ class RFC1413 : public InspSocket
u->Shrink("ident_data");
}
+ virtual void OnError(InspSocketError e)
+ {
+ u->Shrink("ident_data");
+ }
+
virtual bool OnConnected()
{
uslen = sizeof(sock_us);
diff --git a/src/socket.cpp b/src/socket.cpp
index f42a4691f..7b85f7f6b 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -92,18 +92,22 @@ InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long
else
{
this->host = host;
+ this->port = port;
if (!inet_aton(host.c_str(),&addy))
{
+ log(DEBUG,"Attempting to resolve %s",this->host.c_str());
/* Its not an ip, spawn the resolver */
this->dns.SetNS(std::string(Config->DNSServer));
this->dns.ForwardLookupWithFD(host,fd);
- timeout_end = time(NULL)+maxtime;
+ timeout_end = time(NULL)+maxtime;
timeout = false;
this->state = I_RESOLVING;
+ socket_ref[this->fd] = this;
}
else
{
+ log(DEBUG,"No need to resolve %s",this->host.c_str());
this->IP = host;
this->DoConnect();
}
@@ -112,15 +116,20 @@ InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long
bool InspSocket::DoResolve()
{
+ log(DEBUG,"In DoResolve(), trying to resolve IP");
if (this->dns.HasResult())
{
+ log(DEBUG,"Socket has result");
std::string res_ip = dns.GetResultIP();
if (res_ip != "")
{
+ log(DEBUG,"Socket result set to %s",res_ip.c_str());
this->IP = res_ip;
+ socket_ref[this->fd] = NULL;
}
else
{
+ log(DEBUG,"Socket DNS failure");
this->Close();
this->state = I_ERROR;
this->OnError(I_ERR_RESOLVE);
@@ -128,19 +137,22 @@ bool InspSocket::DoResolve()
}
return this->DoConnect();
}
- else return true;
+ log(DEBUG,"No result for socket yet!");
+ return true;
}
bool InspSocket::DoConnect()
{
+ log(DEBUG,"In DoConnect()");
if ((this->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
+ log(DEBUG,"Cant socket()");
this->state = I_ERROR;
this->OnError(I_ERR_SOCKET);
return false;
}
- this->port = port;
+ log(DEBUG,"Part 2 DoConnect() %s",this->IP.c_str());
inet_aton(this->IP.c_str(),&addy);
addr.sin_family = AF_INET;
addr.sin_addr = addy;
@@ -154,9 +166,10 @@ bool InspSocket::DoConnect()
{
if (errno != EINPROGRESS)
{
- this->Close();
+ log(DEBUG,"Error connect() %d: %s",this->fd,strerror(errno));
this->OnError(I_ERR_CONNECT);
this->state = I_ERROR;
+ this->Close();
return false;
}
}
@@ -259,9 +272,11 @@ bool InspSocket::Poll()
switch (this->state)
{
case I_RESOLVING:
+ log(DEBUG,"State = I_RESOLVING, calling DoResolve()");
return this->DoResolve();
break;
case I_CONNECTING:
+ log(DEBUG,"State = I_CONNECTED");
this->SetState(I_CONNECTED);
/* Our socket was in write-state, so delete it and re-add it
* in read-state.