diff options
Diffstat (limited to 'src/socketengines')
-rw-r--r-- | src/socketengines/socketengine_epoll.cpp | 26 | ||||
-rw-r--r-- | src/socketengines/socketengine_kqueue.cpp | 9 | ||||
-rw-r--r-- | src/socketengines/socketengine_poll.cpp | 14 | ||||
-rw-r--r-- | src/socketengines/socketengine_ports.cpp | 10 | ||||
-rw-r--r-- | src/socketengines/socketengine_select.cpp | 9 |
5 files changed, 25 insertions, 43 deletions
diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp index 7d919ec9f..c442e340d 100644 --- a/src/socketengines/socketengine_epoll.cpp +++ b/src/socketengines/socketengine_epoll.cpp @@ -18,16 +18,12 @@ */ -#include <vector> -#include <string> -#include <map> #include "inspircd.h" #include "exitcodes.h" -#include "socketengine.h" + #include <sys/epoll.h> -#include <ulimit.h> +#include <sys/resource.h> #include <iostream> -#define EP_DELAY 5 /** A specialisation of the SocketEngine class, designed to use linux 2.6 epoll(). */ @@ -42,8 +38,12 @@ namespace void SocketEngine::Init() { - // MAX_DESCRIPTORS is mainly used for display purposes, no problem if ulimit() fails and returns a negative number - MAX_DESCRIPTORS = ulimit(4, 0); + // MAX_DESCRIPTORS is mainly used for display purposes, no problem if getrlimit() fails + struct rlimit limit; + if (!getrlimit(RLIMIT_NOFILE, &limit)) + { + MAX_DESCRIPTORS = limit.rlim_cur; + } // 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. @@ -185,7 +185,7 @@ int SocketEngine::DispatchEvents() if (ev.events & EPOLLHUP) { stats.ErrorEvents++; - eh->HandleEvent(EVENT_ERROR, 0); + eh->OnEventHandlerError(0); continue; } @@ -197,7 +197,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; } @@ -217,16 +217,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(); } } diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp index d5a3bb793..9db902314 100644 --- a/src/socketengines/socketengine_kqueue.cpp +++ b/src/socketengines/socketengine_kqueue.cpp @@ -24,7 +24,6 @@ #include <sys/types.h> #include <sys/event.h> #include <sys/time.h> -#include "socketengine.h" #include <iostream> #include <sys/sysctl.h> @@ -195,25 +194,23 @@ int SocketEngine::DispatchEvents() if (kev.flags & EV_EOF) { stats.ErrorEvents++; - eh->HandleEvent(EVENT_ERROR, kev.fflags); + eh->OnEventHandlerError(kev.fflags); continue; } if (filter == EVFILT_WRITE) { - stats.WriteEvents++; /* When mask is FD_WANT_FAST_WRITE or FD_WANT_SINGLE_WRITE, * we set a one-shot write, so we need to clear that bit * to detect when it set again. */ const int bits_to_clr = FD_WANT_SINGLE_WRITE | FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK; eh->SetEventMask(eh->GetEventMask() & ~bits_to_clr); - eh->HandleEvent(EVENT_WRITE); + eh->OnEventHandlerWrite(); } else if (filter == EVFILT_READ) { - stats.ReadEvents++; eh->SetEventMask(eh->GetEventMask() & ~FD_READ_WILL_BLOCK); - eh->HandleEvent(EVENT_READ); + eh->OnEventHandlerRead(); } } diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp index 4e6d0b9f5..59991d80d 100644 --- a/src/socketengines/socketengine_poll.cpp +++ b/src/socketengines/socketengine_poll.cpp @@ -21,12 +21,8 @@ */ -#include <vector> -#include <string> -#include <map> #include "exitcodes.h" #include "inspircd.h" -#include "socketengine.h" #include <sys/poll.h> #include <sys/resource.h> @@ -172,7 +168,7 @@ int SocketEngine::DispatchEvents() int processed = 0; ServerInstance->UpdateTime(); - for (int index = 0; index < CurrentSetSize && processed < i; index++) + for (size_t index = 0; index < CurrentSetSize && processed < i; index++) { struct pollfd& pfd = events[index]; @@ -189,7 +185,7 @@ int SocketEngine::DispatchEvents() if (revents & POLLHUP) { - eh->HandleEvent(EVENT_ERROR, 0); + eh->OnEventHandlerError(0); continue; } @@ -200,14 +196,14 @@ 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; } if (revents & POLLIN) { eh->SetEventMask(eh->GetEventMask() & ~FD_READ_WILL_BLOCK); - eh->HandleEvent(EVENT_READ); + eh->OnEventHandlerRead(); if (eh != GetRef(fd)) // whoops, deleted out from under us continue; @@ -221,7 +217,7 @@ int SocketEngine::DispatchEvents() // The vector could've been resized, reference can be invalid by now; don't use it events[index].events = mask_to_poll(mask); - eh->HandleEvent(EVENT_WRITE); + eh->OnEventHandlerWrite(); } } diff --git a/src/socketengines/socketengine_ports.cpp b/src/socketengines/socketengine_ports.cpp index c6ddb041c..68fa70e3b 100644 --- a/src/socketengines/socketengine_ports.cpp +++ b/src/socketengines/socketengine_ports.cpp @@ -25,11 +25,7 @@ # error You need Solaris 10 or later to make use of this code. #endif -#include <vector> -#include <string> -#include <map> #include "inspircd.h" -#include "socketengine.h" #include <port.h> #include <iostream> #include <ulimit.h> @@ -163,15 +159,13 @@ int SocketEngine::DispatchEvents() port_associate(EngineHandle, PORT_SOURCE_FD, fd, mask_to_events(mask), eh); if (portev_events & POLLRDNORM) { - stats.ReadEvents++; - eh->HandleEvent(EVENT_READ); + eh->OnEventHandlerRead(); if (eh != GetRef(fd)) continue; } if (portev_events & POLLWRNORM) { - stats.WriteEvents++; - eh->HandleEvent(EVENT_WRITE); + eh->OnEventHandlerWrite(); } } diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp index be4a7d186..42f634db1 100644 --- a/src/socketengines/socketengine_select.cpp +++ b/src/socketengines/socketengine_select.cpp @@ -20,7 +20,6 @@ #include "inspircd.h" -#include "socketengine.h" #ifndef _WIN32 #include <sys/select.h> @@ -142,26 +141,24 @@ int SocketEngine::DispatchEvents() if (getsockopt(i, SOL_SOCKET, SO_ERROR, (char*)&errcode, &codesize) < 0) errcode = errno; - ev->HandleEvent(EVENT_ERROR, errcode); + ev->OnEventHandlerError(errcode); continue; } if (has_read) { - stats.ReadEvents++; ev->SetEventMask(ev->GetEventMask() & ~FD_READ_WILL_BLOCK); - ev->HandleEvent(EVENT_READ); + ev->OnEventHandlerRead(); if (ev != GetRef(i)) continue; } if (has_write) { - stats.WriteEvents++; int newmask = (ev->GetEventMask() & ~(FD_WRITE_WILL_BLOCK | FD_WANT_SINGLE_WRITE)); SocketEngine::OnSetEvent(ev, ev->GetEventMask(), newmask); ev->SetEventMask(newmask); - ev->HandleEvent(EVENT_WRITE); + ev->OnEventHandlerWrite(); } } |