]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socketengines/socketengine_poll.cpp
Do not enable SO_LINGER on our sockets
[user/henk/code/inspircd.git] / src / socketengines / socketengine_poll.cpp
index dd38c32b978c200c6ef980819dc3d4b27e190262..5c361a0cbded453bd9a913f957f4ff31ff02ad73 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef SOCKETENGINE_POLL
 #define SOCKETENGINE_POLL
 
+#include <iostream>
 #include <vector>
 #include <string>
 #include <map>
@@ -75,15 +76,28 @@ public:
 
 #endif
 
-#include <ulimit.h>
-#ifdef __FreeBSD__
+#ifdef BSD
        #include <sys/sysctl.h>
+#else
+       #include <ulimit.h>
 #endif
 
 PollEngine::PollEngine()
 {
        CurrentSetSize = 0;
-#ifndef __FreeBSD__
+#ifdef BSD
+       int mib[2];
+       size_t len;
+
+       mib[0] = CTL_KERN;
+#ifdef KERN_MAXFILESPERPROC
+       mib[1] = KERN_MAXFILESPERPROC;
+#else
+       mib[1] = KERN_MAXFILES;
+#endif
+       len = sizeof(MAX_DESCRIPTORS);
+       sysctl(mib, 2, &MAX_DESCRIPTORS, &len, NULL, 0);
+#else
        int max = ulimit(4, 0);
        if (max > 0)
        {
@@ -92,17 +106,9 @@ PollEngine::PollEngine()
        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));
+               std::cout << "ERROR: Can't determine maximum number of open sockets: " << strerror(errno) << std::endl;
                ServerInstance->Exit(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()];