diff options
Diffstat (limited to 'src/socketengines')
-rw-r--r-- | src/socketengines/socketengine_epoll.cpp | 7 | ||||
-rw-r--r-- | src/socketengines/socketengine_kqueue.cpp | 15 | ||||
-rw-r--r-- | src/socketengines/socketengine_poll.cpp | 11 | ||||
-rw-r--r-- | src/socketengines/socketengine_select.cpp | 13 |
4 files changed, 13 insertions, 33 deletions
diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp index c442e340d..dc10a3613 100644 --- a/src/socketengines/socketengine_epoll.cpp +++ b/src/socketengines/socketengine_epoll.cpp @@ -38,12 +38,7 @@ namespace void SocketEngine::Init() { - // MAX_DESCRIPTORS is mainly used for display purposes, no problem if getrlimit() fails - struct rlimit limit; - if (!getrlimit(RLIMIT_NOFILE, &limit)) - { - MAX_DESCRIPTORS = limit.rlim_cur; - } + LookupMaxFds(); // 128 is not a maximum, just a hint at the eventual number of sockets that may be polled, // and it is completely ignored by 2.6.8 and later kernels, except it must be larger than zero. diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp index 9db902314..c969af1fd 100644 --- a/src/socketengines/socketengine_kqueue.cpp +++ b/src/socketengines/socketengine_kqueue.cpp @@ -46,20 +46,7 @@ namespace */ void SocketEngine::Init() { - MAX_DESCRIPTORS = 0; - 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); - // MAX_DESCRIPTORS is mainly used for display purposes, no problem if the sysctl() below fails - sysctl(mib, 2, &MAX_DESCRIPTORS, &len, NULL, 0); - + LookupMaxFds(); RecoverFromFork(); } diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp index a5e86ba82..c80593588 100644 --- a/src/socketengines/socketengine_poll.cpp +++ b/src/socketengines/socketengine_poll.cpp @@ -41,16 +41,7 @@ namespace void SocketEngine::Init() { - struct rlimit limits; - if (!getrlimit(RLIMIT_NOFILE, &limits)) - { - MAX_DESCRIPTORS = limits.rlim_cur; - } - else - { - // MAX_DESCRIPTORS is mainly used for display purposes, it's not a problem that getrlimit() failed - MAX_DESCRIPTORS = -1; - } + LookupMaxFds(); } void SocketEngine::Deinit() diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp index 42f634db1..03f0aca62 100644 --- a/src/socketengines/socketengine_select.cpp +++ b/src/socketengines/socketengine_select.cpp @@ -35,7 +35,7 @@ namespace void SocketEngine::Init() { - MAX_DESCRIPTORS = FD_SETSIZE; + MaxSetSize = FD_SETSIZE; FD_ZERO(&ReadSet); FD_ZERO(&WriteSet); @@ -53,7 +53,11 @@ void SocketEngine::RecoverFromFork() bool SocketEngine::AddFd(EventHandler* eh, int event_mask) { int fd = eh->GetFd(); - if ((fd < 0) || (fd > GetMaxFds() - 1)) + + if (fd < 0) + return false; + + if (static_cast<size_t>(fd) >= GetMaxFds()) return false; if (!SocketEngine::AddFdRef(eh)) @@ -73,7 +77,10 @@ void SocketEngine::DelFd(EventHandler* eh) { int fd = eh->GetFd(); - if ((fd < 0) || (fd > GetMaxFds() - 1)) + if (fd < 0) + return; + + if (static_cast<size_t>(fd) >= GetMaxFds()) return; SocketEngine::DelFdRef(eh); |