diff options
-rw-r--r-- | include/inspircd.h | 19 | ||||
-rw-r--r-- | src/inspircd.cpp | 3 | ||||
-rw-r--r-- | src/inspsocket.cpp | 43 | ||||
-rw-r--r-- | src/modules.cpp | 30 | ||||
-rw-r--r-- | src/modules/extra/m_mysql.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_httpd.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_ident.cpp | 24 | ||||
-rw-r--r-- | src/modules/m_spanningtree.cpp | 7 | ||||
-rw-r--r-- | src/userprocess.cpp | 23 |
9 files changed, 14 insertions, 146 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index c4a58e90e..965cf44fc 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -373,10 +373,6 @@ class InspIRCd : public classbase */ ServerConfig* Config; - /** Module sockets list, holds the active set of InspSocket classes - */ - std::vector<InspSocket*> module_sockets; - /** Client list, a hash_map containing all clients, local and remote */ user_hash clientlist; @@ -868,21 +864,6 @@ class InspIRCd : public classbase */ bool IsValidMask(const std::string &mask); - /** Add an InspSocket class to the active set - * @param sock A socket to add to the active set - */ - void AddSocket(InspSocket* sock); - - /** Remove an InspSocket class from the active set at next time around the loop - * @param sock A socket to remove from the active set - */ - void RemoveSocket(InspSocket* sock); - - /** Delete a socket immediately without waiting for the next iteration of the mainloop - * @param sock A socket to delete from the active set - */ - void DelSocket(InspSocket* sock); - /** Rehash the local server */ void RehashServer(); diff --git a/src/inspircd.cpp b/src/inspircd.cpp index dd111f9ba..79ae8b7bc 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -184,7 +184,6 @@ InspIRCd::InspIRCd(int argc, char** argv) this->Config = new ServerConfig(this); this->Start(); - this->module_sockets.clear(); this->TIME = this->OLDTIME = this->startup_time = time(NULL); srand(this->TIME); this->Log(DEBUG,"*** InspIRCd starting up!"); @@ -671,8 +670,6 @@ void InspIRCd::DoOneIteration(bool process_module_sockets) irc::whowas::MaintainWhoWas(TIME); } Timers->TickTimers(TIME); - if (process_module_sockets) - this->DoSocketTimeouts(TIME); this->DoBackgroundUserStuff(TIME); if ((TIME % 5) == 0) diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index c44ad130f..814517bf1 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -40,7 +40,6 @@ InspSocket::InspSocket(InspIRCd* SI) this->state = I_DISCONNECTED; this->fd = -1; this->WaitingForWriteEvent = false; - this->ClosePending = false; this->Instance = SI; } @@ -49,11 +48,10 @@ InspSocket::InspSocket(InspIRCd* SI, int newfd, const char* ip) this->fd = newfd; this->state = I_CONNECTED; strlcpy(this->IP,ip,MAXBUF); - this->ClosePending = false; this->WaitingForWriteEvent = false; this->Instance = SI; if (this->fd > -1) - this->ClosePending = (!this->Instance->SE->AddFd(this)); + this->Instance->SE->AddFd(this); } InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool listening, unsigned long maxtime) @@ -61,7 +59,6 @@ InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool this->fd = -1; this->Instance = SI; strlcpy(host,ipaddr.c_str(),MAXBUF); - this->ClosePending = false; this->WaitingForWriteEvent = false; if (listening) { @@ -70,7 +67,6 @@ InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool this->fd = -1; this->state = I_ERROR; this->OnError(I_ERR_SOCKET); - this->ClosePending = true; this->Instance->Log(DEBUG,"OpenTCPSocket() error"); return; } @@ -96,7 +92,6 @@ InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool this->Close(); this->state = I_ERROR; this->OnError(I_ERR_NOMOREFDS); - this->ClosePending = true; } } this->Instance->Log(DEBUG,"New socket now in I_LISTENING state"); @@ -116,7 +111,6 @@ InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool this->fd = -1; this->state = I_ERROR; this->OnError(I_ERR_RESOLVE); - this->ClosePending = true; return; } else @@ -149,7 +143,6 @@ void InspSocket::WantWrite() this->fd = -1; this->state = I_ERROR; this->OnError(I_ERR_NOMOREFDS); - this->ClosePending = true; } } @@ -226,7 +219,6 @@ bool InspSocket::DoConnect() this->Instance->Log(DEBUG,"Cant socket()"); this->state = I_ERROR; this->OnError(I_ERR_SOCKET); - this->fd = -1; return false; } @@ -260,8 +252,6 @@ bool InspSocket::DoConnect() this->OnError(I_ERR_CONNECT); this->Close(); this->state = I_ERROR; - this->fd = -1; - this->ClosePending = true; return false; } } @@ -272,9 +262,7 @@ bool InspSocket::DoConnect() { this->OnError(I_ERR_NOMOREFDS); this->Close(); - this->fd = -1; this->state = I_ERROR; - this->ClosePending = true; return false; } this->SetQueues(this->fd); @@ -286,13 +274,11 @@ bool InspSocket::DoConnect() void InspSocket::Close() { - if (this->fd != -1) + if (this->fd > -1) { this->OnClose(); shutdown(this->fd,2); close(this->fd); - this->ClosePending = true; - this->fd = -1; } } @@ -313,13 +299,17 @@ char* InspSocket::Read() } else { - if (errno == EAGAIN) + int err = errno; + if (err == EAGAIN) { return ""; } else { - this->Instance->Log(DEBUG,"EOF or error on socket: %s",strerror(errno)); + if (!n) + this->Instance->Log(DEBUG,"EOF or error on socket: EOF"); + else + this->Instance->Log(DEBUG,"EOF or error on socket: %s",strerror(err)); return NULL; } } @@ -328,7 +318,6 @@ char* InspSocket::Read() void InspSocket::MarkAsClosed() { this->Instance->Log(DEBUG,"Marked as closed"); - this->ClosePending = true; } // There are two possible outcomes to this function. @@ -337,14 +326,6 @@ void InspSocket::MarkAsClosed() // and should be aborted. int InspSocket::Write(const std::string &data) { - if (this->ClosePending) - return false; - - /*int result = write(this->fd,data.c_str(),data.length()); - if (result < 1) - return false; - return true;*/ - /* Try and append the data to the back of the queue, and send it on its way */ outbuffer.push_back(data); @@ -353,9 +334,6 @@ int InspSocket::Write(const std::string &data) bool InspSocket::FlushWriteBuffer() { - if (this->ClosePending) - return true; - if ((this->fd > -1) && (this->state == I_CONNECTED)) { if (outbuffer.size()) @@ -381,7 +359,6 @@ bool InspSocket::FlushWriteBuffer() this->Instance->Log(DEBUG,"Write error on socket: %s",strerror(errno)); this->OnError(I_ERR_WRITE); this->state = I_ERROR; - this->ClosePending = true; return true; } } @@ -414,7 +391,6 @@ bool InspSocket::Timeout(time_t current) this->OnError(I_ERR_TIMEOUT); timeout = true; this->state = I_ERROR; - this->ClosePending = true; return true; } return this->FlushWriteBuffer(); @@ -428,7 +404,7 @@ bool InspSocket::Poll() int incoming = -1; bool n = true; - if ((fd < 0) || (fd > MAX_DESCRIPTORS) || (this->ClosePending)) + if ((fd < 0) || (fd > MAX_DESCRIPTORS)) return false; switch (this->state) @@ -526,6 +502,7 @@ void InspSocket::HandleEvent(EventType et) if (!this->Poll()) { this->Instance->SE->DelFd(this); + this->Close(); delete this; } } diff --git a/src/modules.cpp b/src/modules.cpp index bb6092570..fe6db535c 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -211,24 +211,6 @@ void Module::OnSetAway(userrec* user) { }; void Module::OnCancelAway(userrec* user) { }; int Module::OnUserList(userrec* user, chanrec* Ptr) { return 0; }; -/* server is a wrapper class that provides methods to all of the C-style - * exports in the core - */ - -void InspIRCd::AddSocket(InspSocket* sock) -{ - this->module_sockets.push_back(sock); -} - -void InspIRCd::RemoveSocket(InspSocket* sock) -{ - for (std::vector<InspSocket*>::iterator a = this->module_sockets.begin(); a < this->module_sockets.end(); a++) - { - InspSocket* s = (InspSocket*)*a; - if (s == sock) - s->MarkAsClosed(); - } -} long InspIRCd::PriorityAfter(const std::string &modulename) { @@ -304,18 +286,6 @@ void InspIRCd::RehashServer() this->Config->Read(false,NULL); } -void InspIRCd::DelSocket(InspSocket* sock) -{ - for (std::vector<InspSocket*>::iterator a = this->module_sockets.begin(); a < this->module_sockets.end(); a++) - { - if (*a == sock) - { - this->module_sockets.erase(a); - return; - } - } -} - /* This is ugly, yes, but hash_map's arent designed to be * addressed in this manner, and this is a bit of a kludge. * Luckily its a specialist function and rarely used by diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index db68e17cd..8b6efb2c6 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -679,7 +679,7 @@ class Notifier : public InspSocket { Instance->Log(DEBUG,"Inbound connection on fd %d!",newsock); Notifier* n = new Notifier(this->Instance, newsock, ip); - this->Instance->AddSocket(n); + n = n; /* Stop bitching at me, GCC */ return true; } @@ -779,7 +779,6 @@ class ModuleSQL : public Module SQLModule = this; MessagePipe = new Notifier(ServerInstance); - ServerInstance->AddSocket(MessagePipe); ServerInstance->Log(DEBUG,"Bound notifier to 127.0.0.1:%d",MessagePipe->GetPort()); pthread_attr_t attribs; diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index feddae001..b1dc7b610 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -65,7 +65,7 @@ class HttpSocket : public InspSocket if (InternalState == HTTP_LISTEN) { HttpSocket* s = new HttpSocket(this->Instance, newsock, ip, index); - this->Instance->AddSocket(s); + s = s; /* Stop GCC whining */ } return true; } @@ -283,10 +283,6 @@ class ModuleHttp : public Module void CreateListener() { http = new HttpSocket(ServerInstance, this->bindip, this->port, true, 0, index); - if ((http) && (http->GetState() == I_LISTENING)) - { - ServerInstance->AddSocket(http); - } } ModuleHttp(InspIRCd* Me) : Module::Module(Me) @@ -317,7 +313,7 @@ class ModuleHttp : public Module virtual ~ModuleHttp() { - ServerInstance->DelSocket(http); + ServerInstance->SE->DelFd(http); } virtual Version GetVersion() diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index eab8f537a..669e9edbe 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -212,16 +212,7 @@ class ModuleIdent : public Module */ user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Looking up your ident..."); RFC1413* ident = new RFC1413(ServerInstance, user, IdentTimeout); - if (ident->GetState() != I_ERROR) - { - user->Extend("ident_data", (char*)ident); - ServerInstance->AddSocket(ident); - } - else - { - user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not find your ident, using "+std::string(user->ident)+" instead."); - DELETE(ident); - } + user->Extend("ident_data", (char*)ident); } virtual bool OnCheckReady(userrec* user) @@ -232,17 +223,6 @@ class ModuleIdent : public Module * have an ident field any more. */ RFC1413* ident; - if (user->GetExt("ident_data", ident)) - { - /*ServerInstance->Log(DEBUG,"TIMES: %lu %lu",ident->timeout_end, ServerInstance->Time());*/ - if (ServerInstance->Time() > ident->timeout_end) - { - ident->u = NULL; - ServerInstance->RemoveSocket(ident); - user->Shrink("ident_data"); - return true; - } - } return (!user->GetExt("ident_data", ident)); } @@ -259,7 +239,6 @@ class ModuleIdent : public Module // a user which has now vanished! To prevent this, set ident::u // to NULL and check it so that we dont write users who have gone away. ident->u = NULL; - ServerInstance->RemoveSocket(ident); } } } @@ -278,7 +257,6 @@ class ModuleIdent : public Module if (user->GetExt("ident_data", ident)) { ident->u = NULL; - ServerInstance->RemoveSocket(ident); } } diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index cceaeb70d..4db91a578 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -3021,7 +3021,6 @@ class TreeSocket : public InspSocket } } TreeSocket* s = new TreeSocket(this->Instance, newsock, ip); - this->Instance->AddSocket(s); return true; } }; @@ -3059,7 +3058,6 @@ class ServernameResolver : public Resolver if (newsocket->GetFd() > -1) { /* We're all OK */ - ServerInstance->AddSocket(newsocket); } else { @@ -3306,7 +3304,6 @@ void ReadConfiguration(bool rebind) TreeSocket* listener = new TreeSocket(ServerInstance, IP.c_str(),Port,true,10); if (listener->GetState() == I_LISTENING) { - ServerInstance->AddSocket(listener); Bindings.push_back(listener); } else @@ -3645,7 +3642,6 @@ class ModuleSpanningTree : public Module ServerInstance->Log(DEBUG,"Splitting server %s",s->GetName().c_str()); ServerInstance->WriteOpers("*** SQUIT: Server \002%s\002 removed from network by %s",parameters[0],user->nick); sock->Squit(s,"Server quit by "+std::string(user->nick)+"!"+std::string(user->ident)+"@"+std::string(user->host)); - ServerInstance->RemoveSocket(sock); } else { @@ -3725,7 +3721,6 @@ class ModuleSpanningTree : public Module // they didnt answer, boot them ServerInstance->WriteOpers("*** Server \002%s\002 pinged out",serv->GetName().c_str()); sock->Squit(serv,"Ping timeout"); - ServerInstance->RemoveSocket(sock); return; } } @@ -3755,7 +3750,6 @@ class ModuleSpanningTree : public Module TreeSocket* newsocket = new TreeSocket(ServerInstance, x->IPAddr,x->Port,false,10,x->Name.c_str()); if (newsocket->GetFd() > -1) { - ServerInstance->AddSocket(newsocket); } else { @@ -3836,7 +3830,6 @@ class ModuleSpanningTree : public Module TreeSocket* newsocket = new TreeSocket(ServerInstance,x->IPAddr,x->Port,false,10,x->Name.c_str()); if (newsocket->GetFd() > -1) { - ServerInstance->AddSocket(newsocket); } else { diff --git a/src/userprocess.cpp b/src/userprocess.cpp index aa16bd90e..ed5c4e7ae 100644 --- a/src/userprocess.cpp +++ b/src/userprocess.cpp @@ -260,29 +260,6 @@ void InspIRCd::ProcessUser(userrec* cu) } } -void InspIRCd::DoSocketTimeouts(time_t TIME) -{ - unsigned int numsockets = this->module_sockets.size(); - - for (std::vector<InspSocket*>::iterator a = this->module_sockets.begin(); a < this->module_sockets.end(); a++) - { - InspSocket* s = *a; - int fd = s->GetFd(); - if ((s) && (fd >= 0) && (fd < MAX_DESCRIPTORS) && (this->SE->GetRef(fd) == s) && (s->Timeout(TIME))) - { - this->Log(DEBUG,"userprocess.cpp: Socket poll returned false, close and bail"); - SE->DelFd(s); - this->module_sockets.erase(a); - s->Close(); - DELETE(s); - break; - } - - if (this->module_sockets.size() != numsockets) - break; - } -} - /** * This function is called once a second from the mainloop. * It is intended to do background checking on all the user structs, e.g. |