]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socketengines/socketengine_poll.cpp
Add support for blocking tag messages with the deaf mode.
[user/henk/code/inspircd.git] / src / socketengines / socketengine_poll.cpp
index dc63fe0edc9032a660d8ab5e51c4493d09067d97..d25f21d9462d8b40bec004d2ba956c7f25b319bf 100644 (file)
@@ -1,10 +1,12 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2014 Adam <Adam@anope.org>
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2009 Uli Schlachter <psychon@znc.in>
- *   Copyright (C) 2009 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2014-2015 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2014, 2017 Adam <Adam@anope.org>
+ *   Copyright (C) 2013, 2016-2017 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
@@ -21,7 +23,6 @@
  */
 
 
-#include "exitcodes.h"
 #include "inspircd.h"
 
 #include <sys/poll.h>
@@ -36,21 +37,12 @@ namespace
        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()
@@ -168,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];
 
@@ -185,7 +177,7 @@ int SocketEngine::DispatchEvents()
 
                if (revents & POLLHUP)
                {
-                       eh->HandleEvent(EVENT_ERROR, 0);
+                       eh->OnEventHandlerError(0);
                        continue;
                }
 
@@ -196,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;
@@ -217,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();
                }
        }