diff options
author | Adam <Adam@anope.org> | 2011-08-21 13:38:42 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-09-10 01:55:09 -0400 |
commit | 2eb708e5ad8b259876d24d828f7472b77864c256 (patch) | |
tree | bed6b70d4bc67eb413453a116e77f8f724cdf3fd /src/socketengines/socketengine_epoll.cpp | |
parent | 4fcb371bc8813cd647b7769a64d586e3a57d684d (diff) |
Cleaned up some of the socket code, cleaned up the pipe engines, added support for binary sockets, and cleaned up the asynch connect/accept code
Diffstat (limited to 'src/socketengines/socketengine_epoll.cpp')
-rw-r--r-- | src/socketengines/socketengine_epoll.cpp | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp index ad9bef3ce..73f7e10d6 100644 --- a/src/socketengines/socketengine_epoll.cpp +++ b/src/socketengines/socketengine_epoll.cpp @@ -11,18 +11,12 @@ void SocketEngine::Init() max = ulimit(4, 0); if (max <= 0) - { - Log() << "Can't determine maximum number of open sockets"; - throw CoreException("Can't determine maximum number of open sockets"); - } + throw SocketException("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 CoreException(Anope::string("Could not initialize epoll socket engine: ") + Anope::LastError()); - } + throw SocketException("Could not initialize epoll socket engine: " + Anope::LastError()); events = new epoll_event[max]; memset(events, 0, sizeof(epoll_event) * max); @@ -53,10 +47,7 @@ void SocketEngine::AddSocket(Socket *s) 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; - } + throw SocketException("Unable to add fd " + stringify(ev.data.fd) + " to epoll: " + Anope::LastError()); Sockets.insert(std::make_pair(ev.data.fd, s)); } @@ -70,10 +61,7 @@ void SocketEngine::DelSocket(Socket *s) 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; - } + throw SocketException("Unable to remove fd " + stringify(ev.data.fd) + " from epoll: " + Anope::LastError()); Sockets.erase(ev.data.fd); } @@ -91,9 +79,9 @@ void SocketEngine::MarkWritable(Socket *s) 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); + throw SocketException("Unable to mark fd " + stringify(ev.data.fd) + " as writable in epoll: " + Anope::LastError()); + + s->SetFlag(SF_WRITABLE); } void SocketEngine::ClearWritable(Socket *s) @@ -109,9 +97,9 @@ void SocketEngine::ClearWritable(Socket *s) 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); + throw SocketException("Unable clear mark fd " + stringify(ev.data.fd) + " as writable in epoll: " + Anope::LastError()); + + s->UnsetFlag(SF_WRITABLE); } void SocketEngine::Process() @@ -130,10 +118,15 @@ void SocketEngine::Process() for (int i = 0; i < total; ++i) { epoll_event *ev = &events[i]; - Socket *s = Sockets[ev->data.fd]; + + std::map<int, Socket *>::iterator it = Sockets.find(ev->data.fd); + if (it == Sockets.end()) + continue; + Socket *s = it->second; if (s->HasFlag(SF_DEAD)) continue; + if (ev->events & (EPOLLHUP | EPOLLERR)) { s->ProcessError(); @@ -141,6 +134,9 @@ void SocketEngine::Process() continue; } + if (!s->Process()) + continue; + if ((ev->events & EPOLLIN) && !s->ProcessRead()) s->SetFlag(SF_DEAD); @@ -151,7 +147,10 @@ void SocketEngine::Process() for (int i = 0; i < total; ++i) { epoll_event *ev = &events[i]; - Socket *s = Sockets[ev->data.fd]; + std::map<int, Socket *>::iterator it = Sockets.find(ev->data.fd); + if (it == Sockets.end()) + continue; + Socket *s = it->second; if (s->HasFlag(SF_DEAD)) delete s; |