diff options
author | Adam <Adam@anope.org> | 2011-04-26 19:13:51 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-05-16 04:08:47 -0400 |
commit | e7887c1f013248274574ab8e3167f742ccb3d69b (patch) | |
tree | f9f5959512b7129711f03156320ae0e46cabaec3 /modules | |
parent | 076ebafa1b4cc935c466c615b94eaac415af9a67 (diff) |
Unmodularized the socket engine because its causing problems and really is unnecessary
Diffstat (limited to 'modules')
-rw-r--r-- | modules/core/os_modlist.cpp | 21 | ||||
-rw-r--r-- | modules/extra/m_xmlrpc.cpp | 2 | ||||
-rw-r--r-- | modules/socketengines/m_socketengine_epoll.cpp | 178 | ||||
-rw-r--r-- | modules/socketengines/m_socketengine_poll.cpp | 198 | ||||
-rw-r--r-- | modules/socketengines/m_socketengine_select.cpp | 129 |
5 files changed, 1 insertions, 527 deletions
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) |