]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socketengines/socketengine_poll.cpp
Fix the Poll socket engine on BSD.
[user/henk/code/inspircd.git] / src / socketengines / socketengine_poll.cpp
index 7a026891bb8352d3112cc198af2320d82fac7ab8..ea7780686572405a54f5f92baab1a17df225bf63 100644 (file)
@@ -26,6 +26,7 @@
 #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;
@@ -75,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()];