summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--data/example.conf12
-rw-r--r--docs/Changes.conf1
-rw-r--r--include/extern.h1
-rw-r--r--include/modules.h2
-rw-r--r--include/services.h3
-rw-r--r--include/socketengine.h26
-rw-r--r--include/sysconf.h.cmake3
-rw-r--r--modules/core/os_modlist.cpp21
-rw-r--r--modules/extra/m_xmlrpc.cpp2
-rw-r--r--modules/socketengines/m_socketengine_epoll.cpp178
-rw-r--r--modules/socketengines/m_socketengine_poll.cpp198
-rw-r--r--modules/socketengines/m_socketengine_select.cpp129
-rw-r--r--src/CMakeLists.txt16
-rw-r--r--src/dns.cpp5
-rw-r--r--src/init.cpp7
-rw-r--r--src/main.cpp19
-rw-r--r--src/socketengines/pipeengine_eventfd.cpp (renamed from src/socketengines/socketengine_eventfd.cpp)2
-rw-r--r--src/socketengines/pipeengine_pipe.cpp (renamed from src/socketengines/socketengine_pipe.cpp)0
-rw-r--r--src/socketengines/pipeengine_win32.cpp (renamed from src/socketengines/socketengine_win32.cpp)2
-rw-r--r--src/socketengines/socketengine_epoll.cpp154
-rw-r--r--src/socketengines/socketengine_poll.cpp176
-rw-r--r--src/socketengines/socketengine_select.cpp105
-rw-r--r--src/sockets.cpp34
-rw-r--r--src/win32/anope_windows.h2
-rw-r--r--src/win32/windows.cpp13
26 files changed, 509 insertions, 605 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index db6bbf837..c2106b9da 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -338,8 +338,9 @@ check_function_exists(setgrent HAVE_SETGRENT)
check_function_exists(strcasecmp HAVE_STRCASECMP)
check_function_exists(stricmp HAVE_STRICMP)
check_function_exists(umask HAVE_UMASK)
-check_function_exists(backtrace HAVE_BACKTRACE)
check_function_exists(eventfd HAVE_EVENTFD)
+check_function_exists(epoll HAVE_EPOLL)
+check_function_exists(poll HAVE_POLL)
# Check for the existance of the following types
check_type_size(uint8_t UINT8_T)
diff --git a/data/example.conf b/data/example.conf
index 66588cdee..709a7a310 100644
--- a/data/example.conf
+++ b/data/example.conf
@@ -296,18 +296,6 @@ options
database = "db_plain"
/*
- * The socket engine modules are used for managing connections to and from Anope
- *
- * Supported:
- * - m_socketengine_select
- * - m_socketengine_poll
- * - m_socketengine_epoll
- *
- * We recommend using epoll if your operating system supports it (Linux 2.6+).
- */
- socketengine = "m_socketengine_poll"
-
- /*
* The maximum length of passwords
*/
passlen = 32
diff --git a/docs/Changes.conf b/docs/Changes.conf
index aae4b6658..bf4da4ea4 100644
--- a/docs/Changes.conf
+++ b/docs/Changes.conf
@@ -17,6 +17,7 @@ options:globaloncycle
options:globaloncycledown
options:globaloncycleup
options:anonymousglobal
+options:socketengine
Anope Version 1.9.4
-------------------
diff --git a/include/extern.h b/include/extern.h
index 67bb72220..555292712 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -224,7 +224,6 @@ E void notice_server(const Anope::string &source, const Server *s, const char *f
/**** sockets.cpp ****/
-E SocketEngineBase *SocketEngine;
E int32 TotalRead;
E int32 TotalWritten;
E SocketIO normalSocketIO;
diff --git a/include/modules.h b/include/modules.h
index b03fca8b1..415808def 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -154,7 +154,7 @@ enum ModuleReturn
*/
enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER };
/* Module types, in the order in which they are unloaded. The order these are in is IMPORTANT */
-enum MODType { MT_BEGIN, THIRD, QATESTED, SUPPORTED, CORE, DATABASE, ENCRYPTION, PROTOCOL, SOCKETENGINE, MT_END };
+enum MODType { MT_BEGIN, THIRD, QATESTED, SUPPORTED, CORE, DATABASE, ENCRYPTION, PROTOCOL, MT_END };
typedef std::multimap<Anope::string, Message *> message_map;
extern CoreExport message_map MessageMap;
diff --git a/include/services.h b/include/services.h
index 57cf0972b..9bb49dba2 100644
--- a/include/services.h
+++ b/include/services.h
@@ -59,9 +59,6 @@
# include <sys/socket.h>
# include <sys/time.h>
# include <dirent.h>
-# ifdef HAVE_BACKTRACE
-# include <execinfo.h>
-# endif
# define DllExport
# define CoreExport
# define MARK_DEPRECATED __attribute((deprecated))
diff --git a/include/socketengine.h b/include/socketengine.h
index 9ee94f399..05859eedb 100644
--- a/include/socketengine.h
+++ b/include/socketengine.h
@@ -12,47 +12,47 @@
#ifndef SOCKETENGINE_H
#define SOCKETENGINE_H
-class CoreExport SocketEngineBase
+class CoreExport SocketEngine
{
- public:
#ifdef _WIN32
/* Windows crap */
- WSADATA wsa;
+ static WSADATA wsa;
#endif
+ public:
/* Map of sockets */
- std::map<int, Socket *> Sockets;
+ static std::map<int, Socket *> Sockets;
- /** Default constructor
+ /** Called to initialize the socket engine
*/
- SocketEngineBase();
+ static void Init();
- /** Default destructor
+ /** Called to shutdown the socket engine
*/
- virtual ~SocketEngineBase();
+ static void Shutdown();
/** Add a socket to the internal list
* @param s The socket
*/
- virtual void AddSocket(Socket *s) { }
+ static void AddSocket(Socket *s);
/** Delete a socket from the internal list
* @param s The socket
*/
- virtual void DelSocket(Socket *s) { }
+ static void DelSocket(Socket *s);
/** Mark a socket as writeable
* @param s The socket
*/
- virtual void MarkWritable(Socket *s) { }
+ static void MarkWritable(Socket *s);
/** Unmark a socket as writeable
* @param s The socket
*/
- virtual void ClearWritable(Socket *s) { }
+ static void ClearWritable(Socket *s);
/** Read from sockets and do things
*/
- virtual void Process() { }
+ static void Process();
};
#endif // SOCKETENGINE_H
diff --git a/include/sysconf.h.cmake b/include/sysconf.h.cmake
index 68f3f74e6..ff391a7b1 100644
--- a/include/sysconf.h.cmake
+++ b/include/sysconf.h.cmake
@@ -7,13 +7,14 @@
#cmakedefine HAVE_SYS_TYPES_H 1
#cmakedefine HAVE_STDINT_H 1
#cmakedefine HAVE_STDDEF_H 1
-#cmakedefine HAVE_BACKTRACE 1
#cmakedefine HAVE_SETGRENT 1
#cmakedefine HAVE_STRCASECMP 1
#cmakedefine HAVE_STRICMP 1
#cmakedefine HAVE_STRINGS_H 1
#cmakedefine HAVE_UMASK 1
#cmakedefine HAVE_EVENTFD 1
+#cmakedefine HAVE_EPOLL 1
+#cmakedefine HAVE_POLL 1
#cmakedefine GETTEXT_FOUND 1
#cmakedefine RUNGROUP "@RUNGROUP@"
diff --git a/modules/core/os_modlist.cpp b/modules/core/os_modlist.cpp
index cb3afbd65..b33adaab1 100644
--- a/modules/core/os_modlist.cpp
+++ b/modules/core/os_modlist.cpp
@@ -34,7 +34,6 @@ class CommandOSModList : public Command
int showSupported = 1;
int showQA = 1;
int showDB = 1;
- int showSocketEngine = 1;
char core[] = "Core";
char third[] = "3rd";
@@ -43,7 +42,6 @@ class CommandOSModList : public Command
char supported[] = "Supported";
char qa[] = "QATested";
char db[] = "Database";
- char socketengine[] = "SocketEngine";
if (!param.empty())
{
@@ -56,7 +54,6 @@ class CommandOSModList : public Command
showSupported = 0;
showQA = 0;
showDB = 0;
- showSocketEngine = 0;
}
else if (param.equals_ci(third))
{
@@ -67,7 +64,6 @@ class CommandOSModList : public Command
showProto = 0;
showEnc = 0;
showDB = 0;
- showSocketEngine = 0;
}
else if (param.equals_ci(proto))
{
@@ -78,7 +74,6 @@ class CommandOSModList : public Command
showSupported = 0;
showQA = 0;
showDB = 0;
- showSocketEngine = 0;
}
else if (param.equals_ci(supported))
{
@@ -89,7 +84,6 @@ class CommandOSModList : public Command
showEnc = 0;
showQA = 0;
showDB = 0;
- showSocketEngine = 0;
}
else if (param.equals_ci(qa))
{
@@ -100,7 +94,6 @@ class CommandOSModList : public Command
showEnc = 0;
showQA = 1;
showDB = 0;
- showSocketEngine = 0;
}
else if (param.equals_ci(enc))
{
@@ -111,7 +104,6 @@ class CommandOSModList : public Command
showEnc = 1;
showQA = 0;
showDB = 0;
- showSocketEngine = 0;
}
else if (param.equals_ci(db))
{
@@ -122,12 +114,6 @@ class CommandOSModList : public Command
showEnc = 0;
showQA = 0;
showDB = 1;
- showSocketEngine = 0;
- }
- else if (param == socketengine)
- {
- showCore = showThird = showProto = showSupported = showEnc = showQA = showDB = 0;
- showSocketEngine = 1;
}
}
@@ -188,13 +174,6 @@ class CommandOSModList : public Command
++count;
}
break;
- case SOCKETENGINE:
- if (showSocketEngine)
- {
- source.Reply(_("Module: \002%s\002 [%s] [%s]"), m->name.c_str(), m->version.c_str(), socketengine);
- ++count;
- }
- break;
default:
break;
}
diff --git a/modules/extra/m_xmlrpc.cpp b/modules/extra/m_xmlrpc.cpp
index 34288195a..5246572ff 100644
--- a/modules/extra/m_xmlrpc.cpp
+++ b/modules/extra/m_xmlrpc.cpp
@@ -229,7 +229,7 @@ class ModuleXMLRPC : public Module
~ModuleXMLRPC()
{
/* Clean up our sockets and our listening sockets */
- for (std::map<int, Socket *>::const_iterator it = SocketEngine->Sockets.begin(), it_end = SocketEngine->Sockets.end(); it != it_end; ++it)
+ for (std::map<int, Socket *>::const_iterator it = SocketEngine::Sockets.begin(), it_end = SocketEngine::Sockets.end(); it != it_end; ++it)
{
Socket *s = it->second;
diff --git a/modules/socketengines/m_socketengine_epoll.cpp b/modules/socketengines/m_socketengine_epoll.cpp
deleted file mode 100644
index 0950f62de..000000000
--- a/modules/socketengines/m_socketengine_epoll.cpp
+++ /dev/null
@@ -1,178 +0,0 @@
-/* RequiredFunctions: epoll_wait */
-
-#include "module.h"
-#include <sys/epoll.h>
-#include <ulimit.h>
-
-class SocketEngineEPoll : public SocketEngineBase
-{
- private:
- long max;
- int EngineHandle;
- epoll_event *events;
-
- public:
- SocketEngineEPoll()
- {
- max = ulimit(4, 0);
-
- if (max <= 0)
- {
- Log() << "Can't determine maximum number of open sockets";
- throw ModuleException("Can't determine maximum number of open sockets");
- }
-
- EngineHandle = epoll_create(max / 4);
-
- if (EngineHandle == -1)
- {
- Log() << "Could not initialize epoll socket engine: " << Anope::LastError();
- throw ModuleException(Anope::string("Could not initialize epoll socket engine: ") + Anope::LastError());
- }
-
- events = new epoll_event[max];
- memset(events, 0, sizeof(epoll_event) * max);
- }
-
- ~SocketEngineEPoll()
- {
- delete [] events;
- }
-
- void AddSocket(Socket *s)
- {
- epoll_event ev;
-
- memset(&ev, 0, sizeof(ev));
-
- ev.events = EPOLLIN;
- ev.data.fd = s->GetFD();
-
- if (epoll_ctl(EngineHandle, EPOLL_CTL_ADD, ev.data.fd, &ev) == -1)
- {
- Log() << "Unable to add fd " << ev.data.fd << " to socketengine epoll: " << Anope::LastError();
- return;
- }
-
- Sockets.insert(std::make_pair(ev.data.fd, s));
- }
-
- void DelSocket(Socket *s)
- {
- epoll_event ev;
-
- memset(&ev, 0, sizeof(ev));
-
- ev.data.fd = s->GetFD();
-
- if (epoll_ctl(EngineHandle, EPOLL_CTL_DEL, ev.data.fd, &ev) == -1)
- {
- Log() << "Unable to delete fd " << ev.data.fd << " from socketengine epoll: " << Anope::LastError();
- return;
- }
-
- Sockets.erase(ev.data.fd);
- }
-
- void MarkWritable(Socket *s)
- {
- if (s->HasFlag(SF_WRITABLE))
- return;
-
- epoll_event ev;
-
- memset(&ev, 0, sizeof(ev));
-
- ev.events = EPOLLIN | EPOLLOUT;
- ev.data.fd = s->GetFD();
-
- if (epoll_ctl(EngineHandle, EPOLL_CTL_MOD, ev.data.fd, &ev) == -1)
- Log() << "Unable to mark fd " << ev.data.fd << " as writable in socketengine epoll: " << Anope::LastError();
- else
- s->SetFlag(SF_WRITABLE);
- }
-
- void ClearWritable(Socket *s)
- {
- if (!s->HasFlag(SF_WRITABLE))
- return;
-
- epoll_event ev;
-
- memset(&ev, 0, sizeof(ev));
-
- ev.events = EPOLLIN;
- ev.data.fd = s->GetFD();
-
- if (epoll_ctl(EngineHandle, EPOLL_CTL_MOD, ev.data.fd, &ev) == -1)
- Log() << "Unable to mark fd " << ev.data.fd << " as unwritable in socketengine epoll: " << Anope::LastError();
- else
- s->UnsetFlag(SF_WRITABLE);
- }
-
- void Process()
- {
- int total = epoll_wait(EngineHandle, events, max - 1, Config->ReadTimeout * 1000);
- Anope::CurTime = time(NULL);
-
- /* EINTR can be given if the read timeout expires */
- if (total == -1)
- {
- if (errno != EINTR)
- Log() << "SockEngine::Process(): error: " << Anope::LastError();
- return;
- }
-
- for (int i = 0; i < total; ++i)
- {
- epoll_event *ev = &events[i];
- Socket *s = Sockets[ev->data.fd];
-
- if (s->HasFlag(SF_DEAD))
- continue;
- if (ev->events & (EPOLLHUP | EPOLLERR))
- {
- s->ProcessError();
- s->SetFlag(SF_DEAD);
- continue;
- }
-
- if ((ev->events & EPOLLIN) && !s->ProcessRead())
- s->SetFlag(SF_DEAD);
-
- if ((ev->events & EPOLLOUT) && !s->ProcessWrite())
- s->SetFlag(SF_DEAD);
- }
-
- for (int i = 0; i < total; ++i)
- {
- epoll_event *ev = &events[i];
- Socket *s = Sockets[ev->data.fd];
-
- if (s->HasFlag(SF_DEAD))
- delete s;
- }
- }
-};
-
-class ModuleSocketEngineEPoll : public Module
-{
- SocketEngineEPoll engine;
-
- public:
- ModuleSocketEngineEPoll(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
- {
- this->SetAuthor("Anope");
- this->SetPermanent(true);
- this->SetType(SOCKETENGINE);
-
- SocketEngine = &engine;
- }
-
- ~ModuleSocketEngineEPoll()
- {
- SocketEngine = NULL;
- }
-};
-
-MODULE_INIT(ModuleSocketEngineEPoll)
diff --git a/modules/socketengines/m_socketengine_poll.cpp b/modules/socketengines/m_socketengine_poll.cpp
deleted file mode 100644
index e85c79bb0..000000000
--- a/modules/socketengines/m_socketengine_poll.cpp
+++ /dev/null
@@ -1,198 +0,0 @@
-#include "module.h"
-
-#ifndef _WIN32
-# include <ulimit.h>
-# include <sys/poll.h>
-# include <poll.h>
-# ifndef POLLRDHUP
-# define POLLRDHUP 0
-# endif
-#else
-# define poll WSAPoll
-# define POLLRDHUP POLLHUP
-#endif
-
-class SocketEnginePoll : public SocketEngineBase
-{
- private:
- long max;
- pollfd *events;
- int SocketCount;
- std::map<int, int> socket_positions;
-
- public:
- SocketEnginePoll()
- {
- SocketCount = 0;
-#ifndef _WIN32
- max = ulimit(4, 0);
-#else
- max = 1024;
-#endif
-
- if (max <= 0)
- {
- Log() << "Can't determine maximum number of open sockets";
- throw ModuleException("Can't determine maximum number of open sockets");
- }
-
- events = new pollfd[max];
- }
-
- ~SocketEnginePoll()
- {
- delete [] events;
- }
-
- void AddSocket(Socket *s)
- {
- if (SocketCount == max)
- {
- Log() << "Unable to add fd " << s->GetFD() << " to socketengine poll, engine is full";
- return;
- }
-
- pollfd *ev = &this->events[SocketCount];
- ev->fd = s->GetFD();
- ev->events = POLLIN;
- ev->revents = 0;
-
- Sockets.insert(std::make_pair(ev->fd, s));
- socket_positions.insert(std::make_pair(ev->fd, SocketCount));
-
- ++SocketCount;
- }
-
- void DelSocket(Socket *s)
- {
- std::map<int, int>::iterator pos = socket_positions.find(s->GetFD());
- if (pos == socket_positions.end())
- {
- Log() << "Unable to delete unknown fd " << s->GetFD() << " from socketengine poll";
- return;
- }
-
- if (pos->second != SocketCount - 1)
- {
- pollfd *ev = &this->events[pos->second],
- *last_ev = &this->events[SocketCount - 1];
-
- ev->fd = last_ev->fd;
- ev->events = last_ev->events;
- ev->revents = last_ev->revents;
-
- socket_positions[ev->fd] = pos->second;
- }
-
- Sockets.erase(s->GetFD());
- this->socket_positions.erase(pos);
-
- --SocketCount;
- }
-
- void MarkWritable(Socket *s)
- {
- if (s->HasFlag(SF_WRITABLE))
- return;
-
- std::map<int, int>::iterator pos = socket_positions.find(s->GetFD());
- if (pos == socket_positions.end())
- {
- Log() << "Unable to mark unknown fd " << s->GetFD() << " as writable";
- return;
- }
-
- pollfd *ev = &this->events[pos->second];
- ev->events |= POLLOUT;
-
- s->SetFlag(SF_WRITABLE);
- }
-
- void ClearWritable(Socket *s)
- {
- if (!s->HasFlag(SF_WRITABLE))
- return;
-
- std::map<int, int>::iterator pos = socket_positions.find(s->GetFD());
- if (pos == socket_positions.end())
- {
- Log() << "Unable to mark unknown fd " << s->GetFD() << " as writable";
- return;
- }
-
- pollfd *ev = &this->events[pos->second];
- ev->events &= ~POLLOUT;
-
- s->UnsetFlag(SF_WRITABLE);
- }
-
- void Process()
- {
- int total = poll(this->events, this->SocketCount, Config->ReadTimeout * 1000);
- Anope::CurTime = time(NULL);
-
- /* EINTR can be given if the read timeout expires */
- if (total == -1)
- {
- if (errno != EINTR)
- Log() << "SockEngine::Process(): error: " << Anope::LastError();
- return;
- }
-
- for (int i = 0, processed = 0; i < SocketCount && processed != total; ++i)
- {
- pollfd *ev = &this->events[i];
-
- if (ev->revents != 0)
- ++processed;
-
- Socket *s = Sockets[ev->fd];
-
- if (s->HasFlag(SF_DEAD))
- continue;
- if (ev->revents & (POLLERR | POLLRDHUP))
- {
- s->ProcessError();
- s->SetFlag(SF_DEAD);
- continue;
- }
-
- if ((ev->revents & POLLIN) && !s->ProcessRead())
- s->SetFlag(SF_DEAD);
-
- if ((ev->revents & POLLOUT) && !s->ProcessWrite())
- s->SetFlag(SF_DEAD);
- }
-
- for (int i = 0; i < SocketCount; ++i)
- {
- pollfd *ev = &this->events[i];
- Socket *s = Sockets[ev->fd];
-
- if (s->HasFlag(SF_DEAD))
- delete s;
- }
- }
-};
-
-class ModuleSocketEnginePoll : public Module
-{
- SocketEnginePoll engine;
-
- public:
- ModuleSocketEnginePoll(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
- {
- this->SetAuthor("Anope");
- this->SetPermanent(true);
- this->SetType(SOCKETENGINE);
-
- SocketEngine = &engine;
- }
-
- ~ModuleSocketEnginePoll()
- {
- SocketEngine = NULL;
- }
-};
-
-MODULE_INIT(ModuleSocketEnginePoll)
diff --git a/modules/socketengines/m_socketengine_select.cpp b/modules/socketengines/m_socketengine_select.cpp
deleted file mode 100644
index 3ea9eab27..000000000
--- a/modules/socketengines/m_socketengine_select.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-#include "module.h"
-
-class SocketEngineSelect : public SocketEngineBase
-{
- private:
- /* Max Read FD */
- int MaxFD;
- /* Read FDs */
- fd_set ReadFDs;
- /* Write FDs */
- fd_set WriteFDs;
-
- public:
- SocketEngineSelect()
- {
- MaxFD = 0;
- FD_ZERO(&ReadFDs);
- FD_ZERO(&WriteFDs);
- }
-
- ~SocketEngineSelect()
- {
- FD_ZERO(&ReadFDs);
- FD_ZERO(&WriteFDs);
- }
-
- void AddSocket(Socket *s)
- {
- if (s->GetFD() > MaxFD)
- MaxFD = s->GetFD();
- FD_SET(s->GetFD(), &ReadFDs);
- Sockets.insert(std::make_pair(s->GetFD(), s));
- }
-
- void DelSocket(Socket *s)
- {
- if (s->GetFD() == MaxFD)
- --MaxFD;
- FD_CLR(s->GetFD(), &ReadFDs);
- FD_CLR(s->GetFD(), &WriteFDs);
- Sockets.erase(s->GetFD());
- }
-
- void MarkWritable(Socket *s)
- {
- if (s->HasFlag(SF_WRITABLE))
- return;
- FD_SET(s->GetFD(), &WriteFDs);
- s->SetFlag(SF_WRITABLE);
- }
-
- void ClearWritable(Socket *s)
- {
- if (!s->HasFlag(SF_WRITABLE))
- return;
- FD_CLR(s->GetFD(), &WriteFDs);
- s->UnsetFlag(SF_WRITABLE);
- }
-
- void Process()
- {
- fd_set rfdset = ReadFDs, wfdset = WriteFDs, efdset = ReadFDs;
- timeval tval;
- tval.tv_sec = Config->ReadTimeout;
- tval.tv_usec = 0;
-
- int sresult = select(MaxFD + 1, &rfdset, &wfdset, &efdset, &tval);
- Anope::CurTime = time(NULL);
-
- if (sresult == -1)
- {
- Log() << "SockEngine::Process(): error: " << Anope::LastError();
- }
- else if (sresult)
- {
- int processed = 0;
- for (std::map<int, Socket *>::const_iterator it = Sockets.begin(), it_end = Sockets.end(); it != it_end && processed != sresult; ++it)
- {
- Socket *s = it->second;
-
- if (FD_ISSET(s->GetFD(), &efdset) || FD_ISSET(s->GetFD(), &rfdset) || FD_ISSET(s->GetFD(), &wfdset))
- ++processed;
- if (s->HasFlag(SF_DEAD))
- continue;
- if (FD_ISSET(s->GetFD(), &efdset))
- {
- s->ProcessError();
- s->SetFlag(SF_DEAD);
- continue;
- }
- if (FD_ISSET(s->GetFD(), &rfdset) && !s->ProcessRead())
- s->SetFlag(SF_DEAD);
- if (FD_ISSET(s->GetFD(), &wfdset) && !s->ProcessWrite())
- s->SetFlag(SF_DEAD);
- }
-
- for (std::map<int, Socket *>::iterator it = Sockets.begin(), it_end = Sockets.end(); it != it_end; )
- {
- Socket *s = it->second;
- ++it;
-
- if (s->HasFlag(SF_DEAD))
- delete s;
- }
- }
- }
-};
-
-class ModuleSocketEngineSelect : public Module
-{
- SocketEngineSelect engine;
-
- public:
- ModuleSocketEngineSelect(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
- {
- this->SetAuthor("Anope");
- this->SetPermanent(true);
- this->SetType(SOCKETENGINE);
-
- SocketEngine = &engine;
- }
-
- ~ModuleSocketEngineSelect()
- {
- SocketEngine = NULL;
- }
-};
-
-MODULE_INIT(ModuleSocketEngineSelect)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f606beff6..47d2e8efb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -5,19 +5,29 @@ file(GLOB SRC_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
if(WIN32)
append_to_list(SRC_SRCS win32/windows.cpp)
append_to_list(SRC_SRCS threadengines/threadengine_win32.cpp)
- append_to_list(SRC_SRCS socketengines/socketengine_win32.cpp)
+ append_to_list(SRC_SRCS socketengines/pipeengine_win32.cpp)
# If not using Windows, add the pthread threading engine to the list
else(WIN32)
append_to_list(SRC_SRCS threadengines/threadengine_pthread.cpp)
# If we have eventfd, use it
if(HAVE_EVENTFD AND HAVE_SYS_EVENTFD_H)
- append_to_list(SRC_SRCS socketengines/socketengine_eventfd.cpp)
+ append_to_list(SRC_SRCS socketengines/pipeengine_eventfd.cpp)
# Else fall back to pipe
else(HAVE_EVENTFD AND HAVE_SYS_EVENTFD_H)
- append_to_list(SRC_SRCS socketengines/socketengine_pipe.cpp)
+ append_to_list(SRC_SRCS socketengines/pipeengine_pipe.cpp)
endif(HAVE_EVENTFD AND HAVE_SYS_EVENTFD_H)
endif(WIN32)
+if(HAVE_EPOLL)
+ append_to_list(SRC_SRCS socketengines/socketengine_epoll.cpp)
+else(HAVE_EPOLL)
+ if(HAVE_POLL)
+ append_to_list(SRC_SRCS socketengines/socketengine_poll.cpp)
+ else(HAVE_POLL)
+ append_to_list(SRC_SRCS socketengines/socketengine_select.cpp)
+ endif(HAVE_POLL)
+endif(HAVE_EPOLL)
+
sort_list(SRC_SRCS)
# Set all the files to use C++ as well as set their compile flags (use the module-specific compile flags, though)
diff --git a/src/dns.cpp b/src/dns.cpp
index 45b3db6bd..7475545c0 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -69,7 +69,7 @@ void DNSRequest::Process()
DNSEngine->requests[this->id] = this;
DNSEngine->packets.push_back(p);
- SocketEngine->MarkWritable(DNSEngine->sock);
+ SocketEngine::MarkWritable(DNSEngine->sock);
this->timeout = new DNSRequestTimeout(this, Config->DNSTimeout);
}
@@ -512,7 +512,8 @@ bool DNSSocket::ProcessWrite()
delete r;
DNSEngine->packets.erase(DNSEngine->packets.begin() + i - 1);
}
- SocketEngine->ClearWritable(this);
+
+ SocketEngine::ClearWritable(this);
return cont;
}
diff --git a/src/init.cpp b/src/init.cpp
index c508b75ea..039067191 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -331,6 +331,9 @@ void Init(int ac, char **av)
throw FatalException("Configuration file failed to validate");
}
+ /* Initialize the socket engine */
+ SocketEngine::Init();
+
/* Add IRCD Protocol Module; exit if there are errors */
if (protocol_module_init())
throw FatalException("Unable to load protocol module");
@@ -341,10 +344,6 @@ void Init(int ac, char **av)
/* Add Encryption Modules */
ModuleManager::LoadModuleList(Config->EncModuleList);
- /* Load the socket engine */
- if (ModuleManager::LoadModule(Config->SocketEngine, NULL) || !SocketEngine)
- throw FatalException("Unable to load socket engine " + Config->SocketEngine);
-
/* Add Database Modules */
ModuleManager::LoadModuleList(Config->DBModuleList);
diff --git a/src/main.cpp b/src/main.cpp
index 53e348e69..7ec3cfe0e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -100,6 +100,7 @@ UplinkSocket::UplinkSocket(bool ipv6) : ConnectionSocket(ipv6)
UplinkSocket::~UplinkSocket()
{
+ SocketEngine::Process();
UplinkSock = NULL;
}
@@ -148,10 +149,14 @@ void do_restart_services()
if (!bi->GetUID().empty())
UserListByUID.erase(bi->GetUID());
}
+
+ FOREACH_MOD(I_OnRestart, OnRestart());
+
+ ModuleManager::UnloadAll();
ircdproto->SendSquit(Config->ServerName, quitmsg);
- SocketEngine->Process();
delete UplinkSock;
- ModuleManager::UnloadAll();
+ SocketEngine::Shutdown();
+
chdir(binary_dir.c_str());
my_av[0] = const_cast<char *>(("./" + services_bin).c_str());
execve(services_bin.c_str(), my_av, my_envp);
@@ -160,8 +165,6 @@ void do_restart_services()
throw FatalException("Restart failed");
}
- FOREACH_MOD(I_OnRestart, OnRestart());
-
exit(1);
}
@@ -200,10 +203,12 @@ static void services_shutdown()
delete u;
}
}
- SocketEngine->Process();
- delete UplinkSock;
FOREACH_MOD(I_OnShutdown, OnShutdown());
ModuleManager::UnloadAll();
+ ircdproto->SendSquit(Config->ServerName, quitmsg);
+ delete UplinkSock;
+ SocketEngine::Shutdown();
+
/* just in case they weren't all removed at least run once */
ModuleManager::CleanupRuntimeDirectory();
}
@@ -458,7 +463,7 @@ int main(int ac, char **av, char **envp)
ModeManager::ProcessModes();
/* Process the socket engine */
- SocketEngine->Process();
+ SocketEngine::Process();
}
if (quitting)
diff --git a/src/socketengines/socketengine_eventfd.cpp b/src/socketengines/pipeengine_eventfd.cpp
index 9e9ec677b..713c73d34 100644
--- a/src/socketengines/socketengine_eventfd.cpp
+++ b/src/socketengines/pipeengine_eventfd.cpp
@@ -36,7 +36,7 @@ Pipe::Pipe() : BufferedSocket()
this->IPv6 = false;
- SocketEngine->AddSocket(this);
+ SocketEngine::AddSocket(this);
}
bool Pipe::ProcessRead()
diff --git a/src/socketengines/socketengine_pipe.cpp b/src/socketengines/pipeengine_pipe.cpp
index 9d5b47154..9d5b47154 100644
--- a/src/socketengines/socketengine_pipe.cpp
+++ b/src/socketengines/pipeengine_pipe.cpp
diff --git a/src/socketengines/socketengine_win32.cpp b/src/socketengines/pipeengine_win32.cpp
index 78d4bf92d..41ec37a4c 100