]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socketengines/socketengine_poll.cpp
Merge pull request #1157 from SaberUK/insp20+fix-cron-restart
[user/henk/code/inspircd.git] / src / socketengines / socketengine_poll.cpp
index b84cbc5de40fa66b73ed4c9f5686a232f4efe4f6..e38e0fac1c4f67f537a921f428fcb48cb7063aa0 100644 (file)
@@ -1,22 +1,32 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2009 Uli Schlachter <psychon@znc.in>
+ *   Copyright (C) 2009 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
  *
- * This program is free but copyrighted software; see
- *    the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include "inspircd.h"
 #include "exitcodes.h"
 
 #ifndef SOCKETENGINE_POLL
 #define SOCKETENGINE_POLL
 
+#include <iostream>
 #include <vector>
 #include <string>
 #include <map>
 #include "inspircd.h"
 #include "socketengine.h"
 
-#ifndef WINDOWS
-       #ifndef __USE_XOPEN
-           #define __USE_XOPEN /* fuck every fucking OS ever made. needed by poll.h to work.*/
-       #endif
-       #include <poll.h>
-       #include <sys/poll.h>
+#ifndef _WIN32
+# ifndef __USE_XOPEN
+#  define __USE_XOPEN /* fuck every fucking OS ever made. needed by poll.h to work.*/
+# endif
+# include <poll.h>
+# include <sys/poll.h>
+# include <sys/resource.h>
 #else
-       /* *grumble* */
-       #define struct pollfd WSAPOLLFD
-       #define poll WSAPoll
+# define struct pollfd WSAPOLLFD
+# define poll WSAPoll
 #endif
 
 class InspIRCd;
@@ -66,35 +76,20 @@ public:
 
 #endif
 
-#include <ulimit.h>
-#ifdef __FreeBSD__
-       #include <sys/sysctl.h>
-#endif
-
 PollEngine::PollEngine()
 {
        CurrentSetSize = 0;
-#ifndef __FreeBSD__
-       int max = ulimit(4, 0);
-       if (max > 0)
+       struct rlimit limits;
+       if (!getrlimit(RLIMIT_NOFILE, &limits))
        {
-               MAX_DESCRIPTORS = max;
+               MAX_DESCRIPTORS = limits.rlim_cur;
        }
        else
        {
                ServerInstance->Logs->Log("SOCKET", DEFAULT, "ERROR: Can't determine maximum number of open sockets: %s", strerror(errno));
-               printf("ERROR: Can't determine maximum number of open sockets: %s\n", strerror(errno));
-               ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE);
+               std::cout << "ERROR: Can't determine maximum number of open sockets: " << strerror(errno) << std::endl;
+               ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE);
        }
-#else
-       int mib[2];
-       size_t len;
-
-       mib[0] = CTL_KERN;
-       mib[1] = KERN_MAXFILES;
-       len = sizeof(MAX_DESCRIPTORS);
-       sysctl(mib, 2, &MAX_DESCRIPTORS, &len, NULL, 0);
-#endif
 
        ref = new EventHandler* [GetMaxFds()];
        events = new struct pollfd[GetMaxFds()];
@@ -142,7 +137,7 @@ bool PollEngine::AddFd(EventHandler* eh, int event_mask)
        events[index].fd = fd;
        events[index].events = mask_to_poll(event_mask);
 
-       ServerInstance->Logs->Log("SOCKET", DEBUG,"New file descriptor: %d (%d; index %d)", fd, events[fd].events, index);
+       ServerInstance->Logs->Log("SOCKET", DEBUG,"New file descriptor: %d (%d; index %d)", fd, events[index].events, index);
        SocketEngine::SetEventMask(eh, event_mask);
        CurrentSetSize++;
        return true;