X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsocketengines%2Fsocketengine_epoll.cpp;h=60b365ee139027a8cd75482157c7e7a8db9536f4;hb=33180223e318c304892b3fa8640f90f1ddf6f4b4;hp=a54907fca0d095a06b7f50d4a39385cc24059fb5;hpb=30fec322809582f91be70cc1bb16c9678180db76;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp index a54907fca..60b365ee1 100644 --- a/src/socketengines/socketengine_epoll.cpp +++ b/src/socketengines/socketengine_epoll.cpp @@ -18,16 +18,10 @@ */ -#include -#include -#include #include "inspircd.h" -#include "exitcodes.h" -#include "socketengine.h" + #include -#include -#include -#define EP_DELAY 5 +#include /** A specialisation of the SocketEngine class, designed to use linux 2.6 epoll(). */ @@ -42,29 +36,13 @@ namespace void SocketEngine::Init() { - int max = ulimit(4, 0); - if (max > 0) - { - MAX_DESCRIPTORS = max; - } - else - { - ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Can't determine maximum number of open sockets!"); - std::cout << "ERROR: Can't determine maximum number of open sockets!" << std::endl; - ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); - } - - // This is not a maximum, just a hint at the eventual number of sockets that may be polled. - EngineHandle = epoll_create(GetMaxFds() / 4); + LookupMaxFds(); + // 128 is not a maximum, just a hint at the eventual number of sockets that may be polled, + // and it is completely ignored by 2.6.8 and later kernels, except it must be larger than zero. + EngineHandle = epoll_create(128); if (EngineHandle == -1) - { - ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Could not initialize socket engine: %s", strerror(errno)); - ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Your kernel probably does not have the proper features. This is a fatal error, exiting now."); - std::cout << "ERROR: Could not initialize epoll socket engine: " << strerror(errno) << std::endl; - std::cout << "ERROR: Your kernel probably does not have the proper features. This is a fatal error, exiting now." << std::endl; - ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); - } + InitError(); } void SocketEngine::RecoverFromFork() @@ -193,7 +171,7 @@ int SocketEngine::DispatchEvents() if (ev.events & EPOLLHUP) { stats.ErrorEvents++; - eh->HandleEvent(EVENT_ERROR, 0); + eh->OnEventHandlerError(0); continue; } @@ -205,7 +183,7 @@ int SocketEngine::DispatchEvents() int errcode; if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &errcode, &codesize) < 0) errcode = errno; - eh->HandleEvent(EVENT_ERROR, errcode); + eh->OnEventHandlerError(errcode); continue; } @@ -225,16 +203,14 @@ int SocketEngine::DispatchEvents() eh->SetEventMask(mask); if (ev.events & EPOLLIN) { - stats.ReadEvents++; - eh->HandleEvent(EVENT_READ); + eh->OnEventHandlerRead(); if (eh != GetRef(fd)) // whoa! we got deleted, better not give out the write event continue; } if (ev.events & EPOLLOUT) { - stats.WriteEvents++; - eh->HandleEvent(EVENT_WRITE); + eh->OnEventHandlerWrite(); } }