*/
-#include "exitcodes.h"
#include "inspircd.h"
#include <sys/poll.h>
std::vector<struct pollfd> events(16);
/** This vector maps fds to an index in the events array.
*/
- std::vector<int> fd_mappings(16);
+ std::vector<int> fd_mappings(16, -1);
}
void SocketEngine::Init()
{
- struct rlimit limits;
- if (!getrlimit(RLIMIT_NOFILE, &limits))
- {
- MAX_DESCRIPTORS = limits.rlim_cur;
- }
- else
- {
- // MAX_DESCRIPTORS is mainly used for display purposes, it's not a problem that getrlimit() failed
- MAX_DESCRIPTORS = -1;
- }
+ LookupMaxFds();
}
void SocketEngine::Deinit()
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];
if (revents & POLLHUP)
{
- eh->HandleEvent(EVENT_ERROR, 0);
+ eh->OnEventHandlerError(0);
continue;
}
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;
// 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();
}
}