summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-29 14:03:14 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-29 14:03:14 +0000
commit024f972eb1ffc67bb32b2f083955199cbd6ecdde (patch)
treee5d0fe90854d116e93d1ce45849e0e8586d02f89
parentb0cb12952a378d4d3717d3a5556325a15be1de0a (diff)
Added counters for MAX_DESCRIPTORS etc which allows the socket engine to refuse new fd's once you hit the OS limit
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2696 e03df62e-2008-0410-955e-edbf42e46eb7
-rwxr-xr-xconfigure2
-rw-r--r--include/socketengine.h10
-rw-r--r--src/inspircd.cpp6
-rw-r--r--src/socketengine.cpp31
4 files changed, 43 insertions, 6 deletions
diff --git a/configure b/configure
index 7ac841dc7..44fa939c3 100755
--- a/configure
+++ b/configure
@@ -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;