diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-09 15:36:51 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-09 15:36:51 +0000 |
commit | 89749a74402913d50bd5a9140757a383d6ff175e (patch) | |
tree | 99a06946f8959356374a5aea9d5ae39f70c653cd | |
parent | d50dddbb92036893b9188a5df9991a0d5eb80e03 (diff) |
Move fd_ref_table into class InspIRCd*
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4817 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/inspircd.h | 7 | ||||
-rw-r--r-- | include/userprocess.h | 4 | ||||
-rw-r--r-- | src/cmd_quit.cpp | 4 | ||||
-rw-r--r-- | src/command_parse.cpp | 5 | ||||
-rw-r--r-- | src/commands.cpp | 6 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 1 | ||||
-rw-r--r-- | src/inspircd.cpp | 24 | ||||
-rw-r--r-- | src/modules.cpp | 5 | ||||
-rw-r--r-- | src/userprocess.cpp | 48 | ||||
-rw-r--r-- | src/users.cpp | 11 |
10 files changed, 43 insertions, 72 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index 54500cd4d..a8ef3bf1d 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -97,6 +97,10 @@ class InspIRCd : public classbase void MoveAfter(std::string modulename, std::string after); void MoveBefore(std::string modulename, std::string before); + void ProcessUser(userrec* cu); + void DoSocketTimeouts(time_t TIME); + void DoBackgroundUserStuff(time_t TIME); + public: time_t startup_time; ModeParser* ModeGrok; @@ -105,7 +109,8 @@ class InspIRCd : public classbase serverstats* stats; ServerConfig* Config; std::vector<InspSocket*> module_sockets; - InspSocket* socket_ref[MAX_DESCRIPTORS]; + InspSocket* socket_ref[MAX_DESCRIPTORS]; /* XXX: This should probably be made private, with inline accessors */ + userrec* fd_ref_table[MAX_DESCRIPTORS]; /* XXX: Ditto */ DNS* Res; std::string GetRevision(); diff --git a/include/userprocess.h b/include/userprocess.h index 1a93e68cd..0e1b11976 100644 --- a/include/userprocess.h +++ b/include/userprocess.h @@ -8,8 +8,8 @@ void CheckDie(); void LoadAllModules(InspIRCd* ServerInstance); void CheckRoot(); void OpenLog(char** argv, int argc); -void DoBackgroundUserStuff(time_t TIME); +/*void DoBackgroundUserStuff(time_t TIME); void ProcessUser(userrec* cu); -void DoSocketTimeouts(time_t TIME, InspIRCd* SI); +void DoSocketTimeouts(time_t TIME, InspIRCd* SI);*/ #endif diff --git a/src/cmd_quit.cpp b/src/cmd_quit.cpp index d8447c1de..b9fcc9db5 100644 --- a/src/cmd_quit.cpp +++ b/src/cmd_quit.cpp @@ -36,7 +36,6 @@ #include "commands/cmd_quit.h" extern InspIRCd* ServerInstance; -extern InspIRCd* ServerInstance; extern int MODCOUNT; extern ModuleList modules; extern FactoryList factory; @@ -44,7 +43,6 @@ extern time_t TIME; extern user_hash clientlist; extern chan_hash chanlist; extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; void cmd_quit::Handle (const char** parameters, int pcnt, userrec *user) { @@ -112,6 +110,6 @@ void cmd_quit::Handle (const char** parameters, int pcnt, userrec *user) purge_empty_chans(user); } if (user->fd > -1) - fd_ref_table[user->fd] = NULL; + ServerInstance->fd_ref_table[user->fd] = NULL; DELETE(user); } diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 25a3ca192..a0097b924 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -58,11 +58,6 @@ extern std::vector<userrec*> local_users; extern int MODCOUNT; extern time_t TIME; -// This table references users by file descriptor. -// its an array to make it VERY fast, as all lookups are referenced -// by an integer, meaning there is no need for a scan/search operation. -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; - extern Server* MyServer; extern user_hash clientlist; diff --git a/src/commands.cpp b/src/commands.cpp index b8788864b..9a6be7206 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -69,12 +69,6 @@ extern chan_hash chanlist; extern std::vector<userrec*> all_opers; extern std::vector<userrec*> local_users; -// This table references users by file descriptor. -// its an array to make it VERY fast, as all lookups are referenced -// by an integer, meaning there is no need for a scan/search operation. -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; - - void split_chlist(userrec* user, userrec* dest, const std::string &cl) { std::string line; diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 5adc18650..be8c9ac67 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -49,7 +49,6 @@ extern ModuleList modules; extern InspIRCd* ServerInstance; extern time_t TIME; extern char lowermap[255]; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; extern std::vector<userrec*> all_opers; extern user_hash clientlist; extern chan_hash chanlist; diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 242183303..e272d4c6e 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -82,10 +82,6 @@ socklen_t length; time_t TIME = time(NULL), OLDTIME = time(NULL); -// This table references users by file descriptor. -// its an array to make it VERY fast, as all lookups are referenced -// by an integer, meaning there is no need for a scan/search operation. -userrec* fd_ref_table[MAX_DESCRIPTORS]; Server* MyServer = new Server; user_hash clientlist; chan_hash chanlist; @@ -708,18 +704,6 @@ void InspIRCd::DoOneIteration(bool process_module_sockets) expire_lines(); if (process_module_sockets) { - /* Fix by brain - the addition of DoOneIteration means that this - * can end up getting called recursively in the following pattern: - * - * m_spanningtree DoPingChecks - * (server pings out and is squit) - * (squit causes call to DoOneIteration) - * DoOneIteration enters here - * calls DoBackground timer - * enters m_spanningtree DoPingChecks... see step 1. - * - * This should do the job and fix the bug. - */ FOREACH_MOD(I_OnBackgroundTimer,OnBackgroundTimer(TIME)); } TickMissedTimers(TIME); @@ -734,7 +718,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets) if (iterations++ == 15) { iterations = 0; - DoBackgroundUserStuff(TIME); + this->DoBackgroundUserStuff(TIME); } /* Once a second, do the background processing */ @@ -754,7 +738,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets) * hit at all. */ if (process_module_sockets) - DoSocketTimeouts(TIME,this); + this->DoSocketTimeouts(TIME); TickTimers(TIME); @@ -783,9 +767,9 @@ void InspIRCd::DoOneIteration(bool process_module_sockets) case X_ESTAB_CLIENT: log(DEBUG,"Type: X_ESTAB_CLIENT: fd=%d",activefds[activefd]); - cu = fd_ref_table[activefds[activefd]]; + cu = this->fd_ref_table[activefds[activefd]]; if (cu) - ProcessUser(cu); + this->ProcessUser(cu); break; diff --git a/src/modules.cpp b/src/modules.cpp index 4b2d12cab..4eed4d781 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -51,7 +51,6 @@ extern ModuleList modules; extern FactoryList factory; extern std::vector<userrec*> local_users; extern time_t TIME; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; extern user_hash clientlist; extern chan_hash chanlist; extern command_table cmdlist; @@ -460,7 +459,7 @@ userrec* Server::FindNick(const std::string &nick) userrec* Server::FindDescriptor(int socket) { - return (socket < 65536 ? fd_ref_table[socket] : NULL); + return (socket < 65536 ? ServerInstance->fd_ref_table[socket] : NULL); } chanrec* Server::FindChannel(const std::string &channel) @@ -558,7 +557,7 @@ bool Server::PseudoToUser(userrec* alive, userrec* zombie, const std::string &me log(DEBUG,"Delete local user"); } // Fix by brain - cant write the user until their fd table entry is updated - fd_ref_table[zombie->fd] = zombie; + ServerInstance->fd_ref_table[zombie->fd] = zombie; zombie->Write(":%s!%s@%s NICK %s",oldnick.c_str(),oldident.c_str(),oldhost.c_str(),zombie->nick); for (std::vector<ucrec*>::const_iterator i = zombie->chans.begin(); i != zombie->chans.end(); i++) { diff --git a/src/userprocess.cpp b/src/userprocess.cpp index 7d4ce9442..b2c8034a3 100644 --- a/src/userprocess.cpp +++ b/src/userprocess.cpp @@ -59,14 +59,12 @@ extern std::vector<ircd_module*> factory; extern time_t TIME; extern time_t OLDTIME; extern std::vector<userrec*> local_users; -extern InspIRCd* ServerInstance; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; char data[65536]; extern user_hash clientlist; extern chan_hash chanlist; -void ProcessUser(userrec* cu) +void InspIRCd::ProcessUser(userrec* cu) { int result = EAGAIN; @@ -75,14 +73,14 @@ void ProcessUser(userrec* cu) log(DEBUG,"Processing user with fd %d",cu->fd); - if (ServerInstance->Config->GetIOHook(cu->GetPort())) + if (this->Config->GetIOHook(cu->GetPort())) { int result2 = 0; int MOD_RESULT = 0; try { - MOD_RESULT = ServerInstance->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->fd,data,65535,result2); + MOD_RESULT = this->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->fd,data,65535,result2); log(DEBUG,"Data result returned by module: %d",MOD_RESULT); } catch (ModuleException& modexcept) @@ -112,7 +110,7 @@ void ProcessUser(userrec* cu) int currfd; int floodlines = 0; - ServerInstance->stats->statsRecv += result; + this->stats->statsRecv += result; /* * perform a check on the raw buffer as an array (not a string!) to remove * character 0 which is illegal in the RFC - replace them with spaces. @@ -166,14 +164,14 @@ void ProcessUser(userrec* cu) { WriteOpers("*** Excess flood from %s",current->GetIPString()); log(DEFAULT,"Excess flood from: %s",current->GetIPString()); - add_zline(120,ServerInstance->Config->ServerName,"Flood from unregistered connection",current->GetIPString()); + add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString()); apply_lines(APPLY_ZLINES); } return; } - if (current->recvq.length() > (unsigned)ServerInstance->Config->NetBufferSize) + if (current->recvq.length() > (unsigned)this->Config->NetBufferSize) { if (current->registered == REG_ALL) { @@ -183,7 +181,7 @@ void ProcessUser(userrec* cu) { WriteOpers("*** Excess flood from %s",current->GetIPString()); log(DEFAULT,"Excess flood from: %s",current->GetIPString()); - add_zline(120,ServerInstance->Config->ServerName,"Flood from unregistered connection",current->GetIPString()); + add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString()); apply_lines(APPLY_ZLINES); } @@ -217,7 +215,7 @@ void ProcessUser(userrec* cu) } else { - add_zline(120,ServerInstance->Config->ServerName,"Flood from unregistered connection",current->GetIPString()); + add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString()); apply_lines(APPLY_ZLINES); } @@ -231,17 +229,17 @@ void ProcessUser(userrec* cu) if (single_line.length() > 512) single_line.resize(512); - userrec* old_comp = fd_ref_table[currfd]; + userrec* old_comp = this->fd_ref_table[currfd]; - ServerInstance->Parser->ProcessBuffer(single_line,current); + this->Parser->ProcessBuffer(single_line,current); /* * look for the user's record in case it's changed... if theyve quit, * we cant do anything more with their buffer, so bail. * there used to be an ugly, slow loop here. Now we have a reference * table, life is much easier (and FASTER) */ - userrec* new_comp = fd_ref_table[currfd]; - if ((currfd < 0) || (!fd_ref_table[currfd]) || (old_comp != new_comp)) + userrec* new_comp = this->fd_ref_table[currfd]; + if ((currfd < 0) || (!this->fd_ref_table[currfd]) || (old_comp != new_comp)) { return; } @@ -277,26 +275,26 @@ void ProcessUser(userrec* cu) } } -void DoSocketTimeouts(time_t TIME, InspIRCd* SI) +void InspIRCd::DoSocketTimeouts(time_t TIME) { - unsigned int numsockets = SI->module_sockets.size(); - SocketEngine* SE = SI->SE; + unsigned int numsockets = this->module_sockets.size(); + SocketEngine* SE = this->SE; - for (std::vector<InspSocket*>::iterator a = SI->module_sockets.begin(); a < SI->module_sockets.end(); a++) + for (std::vector<InspSocket*>::iterator a = this->module_sockets.begin(); a < this->module_sockets.end(); a++) { InspSocket* s = (InspSocket*)*a; - if ((s) && (s->GetFd() >= 0) && (s->GetFd() < MAX_DESCRIPTORS) && (SI->socket_ref[s->GetFd()] != NULL) && (s->Timeout(TIME))) + if ((s) && (s->GetFd() >= 0) && (s->GetFd() < MAX_DESCRIPTORS) && (this->socket_ref[s->GetFd()] != NULL) && (s->Timeout(TIME))) { log(DEBUG,"userprocess.cpp: Socket poll returned false, close and bail"); - SI->socket_ref[s->GetFd()] = NULL; + this->socket_ref[s->GetFd()] = NULL; SE->DelFd(s->GetFd()); - SI->module_sockets.erase(a); + this->module_sockets.erase(a); s->Close(); DELETE(s); break; } - if (SI->module_sockets.size() != numsockets) + if (this->module_sockets.size() != numsockets) break; } } @@ -307,7 +305,7 @@ void DoSocketTimeouts(time_t TIME, InspIRCd* SI) * stuff like ping checks, registration timeouts, etc. This function is * also responsible for checking if InspSocket derived classes are timed out. */ -void DoBackgroundUserStuff(time_t TIME) +void InspIRCd::DoBackgroundUserStuff(time_t TIME) { CullList GlobalGoners; @@ -340,7 +338,7 @@ void DoBackgroundUserStuff(time_t TIME) { curr->dns_done = true; //ZapThisDns(curr->fd); - ServerInstance->stats->statsDnsBad++; + this->stats->statsDnsBad++; curr->FullConnect(&GlobalGoners); continue; } @@ -362,7 +360,7 @@ void DoBackgroundUserStuff(time_t TIME) curr->nping = TIME+curr->pingmax; continue; } - curr->Write("PING :%s",ServerInstance->Config->ServerName); + curr->Write("PING :%s",this->Config->ServerName); curr->lastping = 0; curr->nping = TIME+curr->pingmax; } diff --git a/src/users.cpp b/src/users.cpp index 53e4695f6..6faea40ce 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -38,7 +38,6 @@ extern std::vector<ircd_module*> factory; extern std::vector<InspSocket*> module_sockets; extern int MODCOUNT; extern time_t TIME; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; extern user_hash clientlist; extern Server* MyServer; extern std::vector<userrec*> local_users; @@ -154,7 +153,7 @@ UserResolver::UserResolver(userrec* user, std::string to_resolve, bool forward) void UserResolver::OnLookupComplete(const std::string &result) { - if ((!this->fwd) && (fd_ref_table[this->bound_fd] == this->bound_user)) + if ((!this->fwd) && (ServerInstance->fd_ref_table[this->bound_fd] == this->bound_user)) { log(DEBUG,"Commencing forward lookup"); this->bound_user->stored_host = result; @@ -168,7 +167,7 @@ void UserResolver::OnLookupComplete(const std::string &result) log(DEBUG,"Error in resolver: %s",e.GetReason()); } } - else if ((this->fwd) && (fd_ref_table[this->bound_fd] == this->bound_user)) + else if ((this->fwd) && (ServerInstance->fd_ref_table[this->bound_fd] == this->bound_user)) { /* Both lookups completed */ if (this->bound_user->GetIPString() == result) @@ -199,7 +198,7 @@ void UserResolver::OnLookupComplete(const std::string &result) void UserResolver::OnError(ResolverError e, const std::string &errormessage) { - if (fd_ref_table[this->bound_fd] == this->bound_user) + if (ServerInstance->fd_ref_table[this->bound_fd] == this->bound_user) { /* Error message here */ this->bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname, using your IP address (%s) instead.", this->bound_user->GetIPString()); @@ -714,7 +713,7 @@ void userrec::QuitUser(userrec *user,const std::string &quitreason) log(DEBUG,"deleting user hash value %lx",(unsigned long)user); if (IS_LOCAL(user)) { - fd_ref_table[user->fd] = NULL; + ServerInstance->fd_ref_table[user->fd] = NULL; if (find(local_users.begin(),local_users.end(),user) != local_users.end()) local_users.erase(find(local_users.begin(),local_users.end(),user)); } @@ -874,7 +873,7 @@ void userrec::AddClient(int socket, int port, bool iscached, insp_inaddr ip) _new->sendqmax = class_sqmax; _new->recvqmax = class_rqmax; - fd_ref_table[socket] = _new; + ServerInstance->fd_ref_table[socket] = _new; local_users.push_back(_new); if (local_users.size() > ServerInstance->Config->SoftLimit) |