summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/socketengine.h5
-rw-r--r--src/dnsqueue.cpp3
-rw-r--r--src/helperfuncs.cpp11
-rw-r--r--src/inspircd.cpp18
-rw-r--r--src/socketengine.cpp45
5 files changed, 47 insertions, 35 deletions
diff --git a/include/socketengine.h b/include/socketengine.h
index caccd9b3f..d02ec671a 100644
--- a/include/socketengine.h
+++ b/include/socketengine.h
@@ -19,6 +19,7 @@
#include <vector>
#include <string>
+#include <map>
#include "inspircd_config.h"
#include "globals.h"
#include "inspircd.h"
@@ -65,9 +66,9 @@ const char X_READBIT = 0x80;
*/
class SocketEngine {
- std::vector<int> fds; /* List of file descriptors being monitored */
int EngineHandle; /* Handle to the socket engine if needed */
#ifdef USE_SELECT
+ std::map<int,int> fds; /* List of file descriptors being monitored */
fd_set wfdset, rfdset; /* Readable and writeable sets for select() */
#endif
#ifdef USE_KQUEUE
@@ -132,7 +133,7 @@ public:
* of active file descriptors in the vector
* fdlist which the core may then act upon.
*/
- bool Wait(std::vector<int> &fdlist);
+ int Wait(int* fdlist);
/** Returns the socket engines name
* This returns the name of the engine for use
diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp
index 3b6bd2103..c0f516e74 100644
--- a/src/dnsqueue.cpp
+++ b/src/dnsqueue.cpp
@@ -264,6 +264,7 @@ void dns_poll(int fdcheck)
* just to be safe so we dont get any more events
* about it.
*/
- SE->DelFd(fdcheck);
+ if (SE)
+ SE->DelFd(fdcheck);
}
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 71840a22a..57f81a044 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -1093,11 +1093,16 @@ void ShowRULES(userrec *user)
// registration timeout maximum seconds)
bool AllModulesReportReady(userrec* user)
{
+ if (!Config->global_implementation[I_OnCheckReady])
+ return true;
for (int i = 0; i <= MODCOUNT; i++)
{
- int res = modules[i]->OnCheckReady(user);
- if (!res)
- return false;
+ if (Config->implement_lists[i][I_OnCheckReady])
+ {
+ int res = modules[i]->OnCheckReady(user);
+ if (!res)
+ return false;
+ }
}
return true;
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 6d21e3677..993348aff 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -410,7 +410,7 @@ bool InspIRCd::LoadModule(const char* filename)
int InspIRCd::Run()
{
bool expire_run = false;
- std::vector<int> activefds;
+ int activefds[65535];
int incomingSockfd;
int in_port;
userrec* cu = NULL;
@@ -462,19 +462,26 @@ int InspIRCd::Run()
expire_run = true;
continue;
}
- if ((TIME % 8) == 1)
+ else if ((TIME % 8) == 1)
+ {
expire_run = false;
+ }
/* Once a second, do the background processing */
- if (TIME != OLDTIME)
- while (DoBackgroundUserStuff(TIME));
+ if ((TIME != OLDTIME) && ((TIME % 2) == 0))
+ DoBackgroundUserStuff(TIME);
/* Call the socket engine to wait on the active
* file descriptors. The socket engine has everything's
* descriptors in its list... dns, modules, users,
* servers... so its nice and easy, just one call.
*/
- SE->Wait(activefds);
+ numberactive = SE->Wait(activefds);
+
+ if (!numberactive)
+ continue;
+
+ log(DEBUG,"%d active fds this time around",numberactive);
/**
* Now process each of the fd's. For users, we have a fast
@@ -483,7 +490,6 @@ int InspIRCd::Run()
* listening ports or module sockets though, things could get
* ugly.
*/
- numberactive = activefds.size();
for (unsigned int activefd = 0; activefd < numberactive; activefd++)
{
int socket_type = SE->GetType(activefds[activefd]);
diff --git a/src/socketengine.cpp b/src/socketengine.cpp
index 82e79ece3..f910802bb 100644
--- a/src/socketengine.cpp
+++ b/src/socketengine.cpp
@@ -66,7 +66,9 @@ bool SocketEngine::AddFd(int fd, bool readable, char type)
{
if ((fd < 0) || (fd > 65535))
return false;
- this->fds.push_back(fd);
+#ifdef USE_SELECT
+ fds[fd] = fd;
+#endif
ref[fd] = type;
if (readable)
{
@@ -107,17 +109,14 @@ bool SocketEngine::DelFd(int fd)
if ((fd < 0) || (fd > 65535))
return false;
- bool found = false;
- for (std::vector<int>::iterator i = fds.begin(); i != fds.end(); i++)
+#ifdef USE_SELECT
+ std::map<int,int>::iterator t = fds.find(fd);
+ if (t != fds.end())
{
- if (*i == fd)
- {
- fds.erase(i);
- log(DEBUG,"Deleted fd %d",fd);
- found = true;
- break;
- }
+ fds.erase(t);
+ log(DEBUG,"Deleted fd %d",fd);
}
+#endif
#ifdef USE_KQUEUE
struct kevent ke;
EV_SET(&ke, fd, ref[fd] & X_READBIT ? EVFILT_READ : EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
@@ -140,26 +139,26 @@ bool SocketEngine::DelFd(int fd)
}
#endif
ref[fd] = 0;
- return found;
+ return true;
}
-bool SocketEngine::Wait(std::vector<int> &fdlist)
+int SocketEngine::Wait(int* fdlist)
{
- fdlist.clear();
+ int result = 0;
#ifdef USE_SELECT
FD_ZERO(&wfdset);
FD_ZERO(&rfdset);
timeval tval;
int sresult;
- for (unsigned int a = 0; a < fds.size(); a++)
+ for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
{
- if (ref[fds[a]] & X_READBIT)
+ if (ref[a->second] & X_READBIT)
{
- FD_SET (fds[a], &rfdset);
+ FD_SET (a->second, &rfdset);
}
else
{
- FD_SET (fds[a], &wfdset);
+ FD_SET (a->second, &wfdset);
}
}
@@ -168,10 +167,10 @@ bool SocketEngine::Wait(std::vector<int> &fdlist)
sresult = select(FD_SETSIZE, &rfdset, &wfdset, NULL, &tval);
if (sresult > 0)
{
- for (unsigned int a = 0; a < fds.size(); a++)
+ for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
{
- if ((FD_ISSET (fds[a], &rfdset)) || (FD_ISSET (fds[a], &wfdset)))
- fdlist.push_back(fds[a]);
+ if ((FD_ISSET (a->second, &rfdset)) || (FD_ISSET (a->second, &wfdset)))
+ fdlist[result++] = a->second;
}
}
#endif
@@ -180,14 +179,14 @@ bool SocketEngine::Wait(std::vector<int> &fdlist)
ts.tv_sec = 0;
int i = kevent(EngineHandle, NULL, 0, &ke_list[0], 65535, &ts);
for (int j = 0; j < i; j++)
- fdlist.push_back(ke_list[j].ident);
+ fdlist[result++] = ke_list[j].ident;
#endif
#ifdef USE_EPOLL
int i = epoll_wait(EngineHandle, events, 65535, 100);
for (int j = 0; j < i; j++)
- fdlist.push_back(events[j].data.fd);
+ fdlist[result++] = events[j].data.fd;
#endif
- return true;
+ return result;
}
std::string SocketEngine::GetName()