]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Stop recreating hashmaps every hour, move garbage collection code related to local...
[user/henk/code/inspircd.git] / src / inspircd.cpp
index cb50595d227f81a6623e2ddf1178802dc3b77cba..c349083788e83977bd6190674cd50b0f800c5779 100644 (file)
@@ -119,7 +119,7 @@ void InspIRCd::Cleanup()
        ports.clear();
 
        /* Close all client sockets, or the new process inherits them */
-       std::vector<LocalUser*>::reverse_iterator i = Users->local_users.rbegin();
+       LocalUserList::reverse_iterator i = Users->local_users.rbegin();
        while (i != this->Users->local_users.rend())
        {
                User* u = *i++;
@@ -191,41 +191,6 @@ void InspIRCd::ResetMaxBans()
                i->second->ResetMaxBans();
 }
 
-/** Because hash_map doesn't free its buckets when we delete items, we occasionally
- * recreate the hash to free them up.
- * We do this by copying the entries from the old hash to a new hash, causing all
- * empty buckets to be weeded out of the hash.
- * Since this is quite expensive, it's not done very often.
- */
-void InspIRCd::RehashUsersAndChans()
-{
-       user_hash* old_users = Users->clientlist;
-       Users->clientlist = new user_hash;
-       for (user_hash::const_iterator n = old_users->begin(); n != old_users->end(); n++)
-               Users->clientlist->insert(*n);
-       delete old_users;
-
-       user_hash* old_uuid = Users->uuidlist;
-       Users->uuidlist = new user_hash;
-       for (user_hash::const_iterator n = old_uuid->begin(); n != old_uuid->end(); n++)
-               Users->uuidlist->insert(*n);
-       delete old_uuid;
-
-       chan_hash* old_chans = chanlist;
-       chanlist = new chan_hash;
-       for (chan_hash::const_iterator n = old_chans->begin(); n != old_chans->end(); n++)
-               chanlist->insert(*n);
-       delete old_chans;
-
-       // Reset the already_sent IDs so we don't wrap it around and drop a message
-       LocalUser::already_sent_id = 0;
-       for (std::vector<LocalUser*>::const_iterator i = Users->local_users.begin(); i != Users->local_users.end(); i++)
-       {
-               (**i).already_sent = 0;
-               (**i).RemoveExpiredInvites();
-       }
-}
-
 void InspIRCd::SetSignals()
 {
 #ifndef _WIN32
@@ -321,11 +286,9 @@ InspIRCd::InspIRCd(int argc, char** argv) :
         OperQuit("OperQuit", NULL),
         GenRandom(&HandleGenRandom),
         IsChannel(&HandleIsChannel),
-        IsSID(&HandleIsSID),
         Rehash(&HandleRehash),
         IsNick(&HandleIsNick),
         IsIdent(&HandleIsIdent),
-        FloodQuitUser(&HandleFloodQuitUser),
         OnCheckExemption(&HandleOnCheckExemption)
 {
        ServerInstance = this;
@@ -355,6 +318,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        this->Modes = 0;
        this->Res = 0;
        this->ConfigThread = NULL;
+       this->FakeClient = NULL;
 
        UpdateTime();
        this->startup_time = TIME.tv_sec;
@@ -426,7 +390,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        };
 
        int index;
-       while ((c = getopt_long(argc, argv, ":f:", longopts, &index)) != -1)
+       while ((c = getopt_long(argc, argv, ":c:f:", longopts, &index)) != -1)
        {
                switch (c)
                {
@@ -520,14 +484,14 @@ InspIRCd::InspIRCd(int argc, char** argv) :
                this->CheckRoot();
        else
        {
-               std::cout << "* WARNING * WARNING * WARNING * WARNING * WARNING *" << std::endl\r
-               << "YOU ARE RUNNING INSPIRCD AS ROOT. THIS IS UNSUPPORTED" << std::endl\r
-               << "AND IF YOU ARE HACKED, CRACKED, SPINDLED OR MUTILATED" << std::endl\r
-               << "OR ANYTHING ELSE UNEXPECTED HAPPENS TO YOU OR YOUR" << std::endl\r
-               << "SERVER, THEN IT IS YOUR OWN FAULT. IF YOU DID NOT MEAN" << std::endl\r
-               << "TO START INSPIRCD AS ROOT, HIT CTRL+C NOW AND RESTART" << std::endl\r
-               << "THE PROGRAM AS A NORMAL USER. YOU HAVE BEEN WARNED!" << std::endl << std::endl\r
-               << "InspIRCd starting in 20 seconds, ctrl+c to abort..." << std::endl;\r
+               std::cout << "* WARNING * WARNING * WARNING * WARNING * WARNING *" << std::endl
+               << "YOU ARE RUNNING INSPIRCD AS ROOT. THIS IS UNSUPPORTED" << std::endl
+               << "AND IF YOU ARE HACKED, CRACKED, SPINDLED OR MUTILATED" << std::endl
+               << "OR ANYTHING ELSE UNEXPECTED HAPPENS TO YOU OR YOUR" << std::endl
+               << "SERVER, THEN IT IS YOUR OWN FAULT. IF YOU DID NOT MEAN" << std::endl
+               << "TO START INSPIRCD AS ROOT, HIT CTRL+C NOW AND RESTART" << std::endl
+               << "THE PROGRAM AS A NORMAL USER. YOU HAVE BEEN WARNED!" << std::endl << std::endl
+               << "InspIRCd starting in 20 seconds, ctrl+c to abort..." << std::endl;
                sleep(20);
        }
 #endif
@@ -630,18 +594,17 @@ InspIRCd::InspIRCd(int argc, char** argv) :
         */
        if ((!do_nofork) && (!do_testsuite) && (!Config->cmdline.forcedebug))
        {
-               int fd;
+               int fd = open("/dev/null", O_RDWR);
 
                fclose(stdin);
                fclose(stderr);
                fclose(stdout);
 
-               fd = open("/dev/null", O_RDWR);
-               if (dup2(fd, 0) < 0)
+               if (dup2(fd, STDIN_FILENO) < 0)
                        Logs->Log("STARTUP", DEFAULT, "Failed to dup /dev/null to stdin.");
-               if (dup2(fd, 1) < 0)
+               if (dup2(fd, STDOUT_FILENO) < 0)
                        Logs->Log("STARTUP", DEFAULT, "Failed to dup /dev/null to stdout.");
-               if (dup2(fd, 2) < 0)
+               if (dup2(fd, STDERR_FILENO) < 0)
                        Logs->Log("STARTUP", DEFAULT, "Failed to dup /dev/null to stderr.");
                close(fd);
        }
@@ -789,7 +752,6 @@ int InspIRCd::Run()
                 */
                if (TIME.tv_sec != OLDTIME)
                {
-                       OLDTIME = TIME.tv_sec;
 #ifndef _WIN32
                        getrusage(RUSAGE_SELF, &ru);
                        stats->LastSampled = TIME;
@@ -817,9 +779,11 @@ int InspIRCd::Run()
                                SNO->WriteToSnoMask('d', "\002EH?!\002 -- Time is jumping FORWARDS! Clock skipped %lu secs.", (unsigned long)TIME.tv_sec - OLDTIME);
                        }
 
+                       OLDTIME = TIME.tv_sec;
+
                        if ((TIME.tv_sec % 3600) == 0)
                        {
-                               this->RehashUsersAndChans();
+                               Users->GarbageCollect();
                                FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
                        }