diff options
author | Peter Powell <petpow@saberuk.com> | 2017-10-22 02:27:25 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2017-10-22 19:44:45 +0100 |
commit | b1098712771ab823042fcf8614a706c76c2ff401 (patch) | |
tree | 7feb35687035b5ac6e1dd4181501400c31a54efc /src/socketengine.cpp | |
parent | d4414f54910aeaa4809a7eacea75a089a0820f40 (diff) |
Convert GetMaxFds() to size_t and deduplicate setting code.
Diffstat (limited to 'src/socketengine.cpp')
-rw-r--r-- | src/socketengine.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/socketengine.cpp b/src/socketengine.cpp index 3735e7530..bac97a6dc 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -23,7 +23,6 @@ #include "inspircd.h" - /** Reference table, contains all current handlers **/ std::vector<EventHandler*> SocketEngine::ref; @@ -36,7 +35,7 @@ size_t SocketEngine::CurrentSetSize = 0; */ std::set<int> SocketEngine::trials; -int SocketEngine::MAX_DESCRIPTORS; +size_t SocketEngine::MaxSetSize = 0; /** Socket engine statistics: count of various events, bandwidth usage */ @@ -61,6 +60,21 @@ void EventHandler::OnEventHandlerError(int errornum) { } +void SocketEngine::LookupMaxFds() +{ + struct rlimit limits; + if (!getrlimit(RLIMIT_NOFILE, &limits)) + MaxSetSize = limits.rlim_cur; + +#if defined __APPLE__ + limits.rlim_cur = limits.rlim_max == RLIM_INFINITY ? OPEN_MAX : limits.rlim_max; +#else + limits.rlim_cur = limits.rlim_max; +#endif + if (!setrlimit(RLIMIT_NOFILE, &limits)) + MaxSetSize = limits.rlim_cur; +} + void SocketEngine::ChangeEventMask(EventHandler* eh, int change) { int old_m = eh->event_mask; |