X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsocketengines%2Fsocketengine_poll.cpp;h=d25f21d9462d8b40bec004d2ba956c7f25b319bf;hb=3151d60c1ecc9462e4c335282ee6c31672f45111;hp=ac5e02cfd1f1067e2d333adfee698ab7a5857120;hpb=efe77ba63b1e519fc4d563bd9b599277c4bd96e5;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp index ac5e02cfd..d25f21d94 100644 --- a/src/socketengines/socketengine_poll.cpp +++ b/src/socketengines/socketengine_poll.cpp @@ -1,10 +1,12 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2014 Adam - * Copyright (C) 2009 Daniel De Graaf - * Copyright (C) 2009 Uli Schlachter - * Copyright (C) 2009 Craig Edwards + * Copyright (C) 2014-2015 Attila Molnar + * Copyright (C) 2014, 2017 Adam + * Copyright (C) 2013, 2016-2017 Sadie Powell + * Copyright (C) 2012 Robby + * Copyright (C) 2009-2010 Daniel De Graaf + * Copyright (C) 2009 Uli Schlachter * Copyright (C) 2008 Robin Burchell * * This file is part of InspIRCd. InspIRCd is free software: you can @@ -21,25 +23,10 @@ */ -#include -#include -#include -#include -#include "exitcodes.h" #include "inspircd.h" -#include "socketengine.h" - -#ifndef _WIN32 -# ifndef __USE_XOPEN -# define __USE_XOPEN /* fuck every fucking OS ever made. needed by poll.h to work.*/ -# endif -# include -# include -# include -#else -# define struct pollfd WSAPOLLFD -# define poll WSAPoll -#endif + +#include +#include /** A specialisation of the SocketEngine class, designed to use poll(). */ @@ -50,22 +37,12 @@ namespace std::vector events(16); /** This vector maps fds to an index in the events array. */ - std::vector fd_mappings(16); + std::vector fd_mappings(16, -1); } void SocketEngine::Init() { - struct rlimit limits; - if (!getrlimit(RLIMIT_NOFILE, &limits)) - { - MAX_DESCRIPTORS = limits.rlim_cur; - } - else - { - ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Can't determine maximum number of open sockets: %s", strerror(errno)); - std::cout << "ERROR: Can't determine maximum number of open sockets: " << strerror(errno) << std::endl; - ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE); - } + LookupMaxFds(); } void SocketEngine::Deinit() @@ -89,9 +66,9 @@ static int mask_to_poll(int event_mask) bool SocketEngine::AddFd(EventHandler* eh, int event_mask) { int fd = eh->GetFd(); - if ((fd < 0) || (fd > GetMaxFds() - 1)) + if (fd < 0) { - ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds()); + ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "AddFd out of range: (fd: %d)", fd); return false; } @@ -137,9 +114,9 @@ void SocketEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) void SocketEngine::DelFd(EventHandler* eh) { int fd = eh->GetFd(); - if ((fd < 0) || (fd > MAX_DESCRIPTORS)) + if (fd < 0) { - ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds()); + ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DelFd out of range: (fd: %d)", fd); return; } @@ -183,7 +160,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]; @@ -200,7 +177,7 @@ int SocketEngine::DispatchEvents() if (revents & POLLHUP) { - eh->HandleEvent(EVENT_ERROR, 0); + eh->OnEventHandlerError(0); continue; } @@ -211,14 +188,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; @@ -232,7 +209,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(); } }