From cb16da88946f7f75a438b471734fa22c33f94461 Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 2 Feb 2006 17:24:15 +0000 Subject: More nonblocking dns stuffs git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3020 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_ident.cpp | 5 +++++ src/socket.cpp | 23 +++++++++++++++++++---- 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. -- cgit v1.2.3