]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Regressed buffering code
[user/henk/code/inspircd.git] / src / inspircd.cpp
index a7ce18f4aa2eabdb3857a1e574a836c205f29c4c..73b27dbe89aee09193aa1f0222151a758ec666a1 100644 (file)
@@ -26,6 +26,9 @@ using namespace std;
 #include <sys/ioctl.h>
 #include <time.h>
 #include <string>
+#include <exception>
+#include <stdexcept>
+#include <new>
 #ifdef GCC3
 #include <ext/hash_map>
 #else
@@ -71,7 +74,7 @@ std::vector<userrec*> local_users;
 
 extern int MODCOUNT;
 extern char LOG_FILE[MAXBUF];
-int openSockfd[MAXSOCKS];
+int openSockfd[MAX_DESCRIPTORS];
 int yield_depth;
 int iterations = 0;
 sockaddr_in client,server;
@@ -193,15 +196,15 @@ InspIRCd::InspIRCd(int argc, char** argv)
        this->MakeLowerMap();
 
         OpenLog(argv, argc);
+       this->stats = new serverstats();
         Config->ClearStack();
         Config->Read(true,NULL);
         CheckRoot();
        this->ModeGrok = new ModeParser();
        this->Parser = new CommandParser();
-       this->stats = new serverstats();
         AddServerName(Config->ServerName);
         CheckDie();
-        stats->BoundPortCount = BindPorts();
+        stats->BoundPortCount = BindPorts(true);
 
        for(int t = 0; t < 255; t++)
                Config->global_implementation[t] = 0;
@@ -212,7 +215,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
        SetSignals();
         if (!Config->nofork)
         {
-                if (DaemonSeed() == ERROR)
+               if (!DaemonSeed())
                 {
                         printf("ERROR: could not go into daemon mode. Shutting down.\n");
                         Exit(ERROR);
@@ -586,7 +589,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
         sockaddr_in sock_us;     // our port number
         socklen_t uslen;         // length of our port number
 
-       if (yield_depth > 3)
+       if (yield_depth > 100)
                return;
 
        yield_depth++;
@@ -702,7 +705,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
               
                                 if ((s) && (!s->Poll()))
                                 {
-                                        log(DEBUG,"Socket poll returned false, close and bail");
+                                        log(DEBUG,"inspircd.cpp: Socket poll returned false, close and bail");
                                         SE->DelFd(s->GetFd());
                                        socket_ref[activefds[activefd]] = NULL;
                                         for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
@@ -791,6 +794,9 @@ int InspIRCd::Run()
        
         LoadAllModules(this);
 
+       /* Just in case no modules were loaded - fix for bug #101 */
+       this->BuildISupport();
+
         printf("\nInspIRCd is now running!\n");
        
        if (!Config->nofork)
@@ -829,9 +835,18 @@ int InspIRCd::Run()
 
 int main(int argc, char** argv)
 {
-        ServerInstance = new InspIRCd(argc, argv);
-        ServerInstance->Run();
-        delete ServerInstance;
-        return 0;
+       try
+       {
+               ServerInstance = new InspIRCd(argc, argv);
+               ServerInstance->Run();
+               delete ServerInstance;
+       }
+       catch (std::bad_alloc)
+       {
+               log(DEFAULT,"You are out of memory! (got exception std::bad_alloc!)");
+               send_error("**** OUT OF MEMORY **** We're gonna need a bigger boat!");
+               printf("Out of memory! (got exception std::bad_alloc!");
+       }
+       return 0;
 }