diff options
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | include/socketengine.h | 10 | ||||
-rw-r--r-- | src/inspircd.cpp | 6 | ||||
-rw-r--r-- | src/socketengine.cpp | 31 |
4 files changed, 43 insertions, 6 deletions
@@ -34,6 +34,7 @@ $config{USE_EPOLL} = "y"; # epoll enabled $config{THREADED_DNS} = "n"; # threaded dns (experimental) $config{STATIC_LINK} = "no"; # are doing static modules? chomp($config{MAX_CLIENT_T} = `sh -c \"ulimit -n\"`); # FD Limit +chomp($config{MAX_DESCRIPTORS} = `sh -c \"ulimit -n\"`); # Hard FD Limit chomp($config{GCCVER} = `gcc -dumpversion | cut -c 1`); # Major GCC Version chomp($config{GCC34} = `gcc -dumpversion | cut -c 3`); # Minor GCC Version chomp($config{OSNAME} = `/bin/uname`); # Operating System Name @@ -719,6 +720,7 @@ sub writefiles { #define MOD_PATH "$config{MODULE_DIR}" #define VERSION "$version" #define MAXCLIENTS $config{MAX_CLIENT} +#define MAX_DESCRIPTORS $config{MAX_DESCRIPTORS} #define NICKMAX $NL #define CHANMAX $CL #define MAXCHANS $config{MAX_CHANNE} diff --git a/include/socketengine.h b/include/socketengine.h index d02ec671a..ecb8fa96e 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -120,6 +120,16 @@ public: */ char GetType(int fd); + /** Returns the maximum number of file descriptors + * you may store in the socket engine at any one time. + */ + int GetMaxFds(); + + /** Returns the number of file descriptor slots + * which are available for storing fds. + */ + int GetRemainingFds(); + /** Delete a file descriptor f rom the engine * This function call deletes a file descriptor * from the engine, returning true if it succeeded diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 6f1889bbf..fbcfc12d1 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -474,13 +474,9 @@ int InspIRCd::Run() * descriptors in its list... dns, modules, users, * servers... so its nice and easy, just one call. */ - numberactive = SE->Wait(activefds); - - if (!numberactive) + if (!(numberactive = SE->Wait(activefds))) continue; - log(DEBUG,"%d active fds this time around",numberactive); - /** * Now process each of the fd's. For users, we have a fast * lookup table which can find a user by file descriptor, so diff --git a/src/socketengine.cpp b/src/socketengine.cpp index f910802bb..3e0b3814d 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -41,6 +41,7 @@ SocketEngine::SocketEngine() #ifdef USE_KQUEUE EngineHandle = kqueue(); #endif + CurrentSetSize = 0; } SocketEngine::~SocketEngine() @@ -99,7 +100,8 @@ bool SocketEngine::AddFd(int fd, bool readable, char type) return false; } #endif -return true; + CurrentSetSize++; + return true; } bool SocketEngine::DelFd(int fd) @@ -138,10 +140,37 @@ bool SocketEngine::DelFd(int fd) return false; } #endif + CurrentSetSize--; ref[fd] = 0; return true; } +int SocketEngine::GetMaxFds() +{ +#ifdef USE_SELECT + return FD_SETSIZE; +#endif +#ifdef USE_KQUEUE + return MAX_DESCRIPTORS; +#endif +#ifdef USE_EPOLL + return MAX_DESCRIPTORS; +#endif +} + +int SocketEngine::GetRemainingFds() +{ +#ifdef USE_SELECT + return FD_SETSIZE - CurrentSetSize; +#endif +#ifdef USE_KQUEUE + return MAX_DESCRIPTORS - CurrentSetSize; +#endif +#ifdef USE_EPOLL + return MAX_DESCRIPTORS - CurrentSetSize; +#endif +} + int SocketEngine::Wait(int* fdlist) { int result = 0; |