From: Peter Powell Date: Sun, 7 Jul 2013 15:33:31 +0000 (+0100) Subject: Fix the Poll socket engine on BSD. X-Git-Tag: v2.0.23~275^2 X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=525a104ef8a639c254d8960b620fe3eb22b34667;p=user%2Fhenk%2Fcode%2Finspircd.git Fix the Poll socket engine on BSD. --- diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp index 4f4f60b4e..ea7780686 100644 --- a/src/socketengines/socketengine_poll.cpp +++ b/src/socketengines/socketengine_poll.cpp @@ -35,15 +35,15 @@ #include "socketengine.h" #ifndef _WIN32 - #ifndef __USE_XOPEN - #define __USE_XOPEN /* fuck every fucking OS ever made. needed by poll.h to work.*/ - #endif - #include - #include +# ifndef __USE_XOPEN +# define __USE_XOPEN /* fuck every fucking OS ever made. needed by poll.h to work.*/ +# endif +# include +# include +# include #else - /* *grumble* */ - #define struct pollfd WSAPOLLFD - #define poll WSAPoll +# define struct pollfd WSAPOLLFD +# define poll WSAPoll #endif class InspIRCd; @@ -76,32 +76,13 @@ public: #endif -#ifdef BSD - #include -#else - #include -#endif - PollEngine::PollEngine() { CurrentSetSize = 0; -#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) + struct rlimit limits; + if (!getrlimit(RLIMIT_NOFILE, &limits)) { - MAX_DESCRIPTORS = max; + MAX_DESCRIPTORS = limits.rlim_cur; } else { @@ -109,7 +90,6 @@ PollEngine::PollEngine() std::cout << "ERROR: Can't determine maximum number of open sockets: " << strerror(errno) << std::endl; ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); } -#endif ref = new EventHandler* [GetMaxFds()]; events = new struct pollfd[GetMaxFds()];