]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socketengines/socketengine_epoll.cpp
Add support for blocking tag messages with the deaf mode.
[user/henk/code/inspircd.git] / src / socketengines / socketengine_epoll.cpp
index 1c4d8963dc2e1354bc16f8e7233aa9ba83e1af5e..7ca9da3fd8a113472d0ef3498d95247de2228c2c 100644 (file)
@@ -1,8 +1,16 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2014-2015 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2014, 2016 Adam <Adam@anope.org>
+ *   Copyright (C) 2013, 2017, 2019 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2012 Ariadne Conill <ariadne@dereferenced.org>
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
+ *   Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006-2008 Craig Edwards <brain@inspircd.org>
+ *   Copyright (C) 2006, 2008 Robin Burchell <robin+git@viroteck.net>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
  */
 
 
-#include <vector>
-#include <string>
-#include <map>
 #include "inspircd.h"
-#include "exitcodes.h"
-#include "socketengine.h"
+
 #include <sys/epoll.h>
-#include <ulimit.h>
-#include <iostream>
-#define EP_DELAY 5
+#include <sys/resource.h>
 
 /** A specialisation of the SocketEngine class, designed to use linux 2.6 epoll().
  */
@@ -37,35 +39,18 @@ namespace
 
        /** These are used by epoll() to hold socket events
         */
-       std::vector<struct epoll_event> events(1);
+       std::vector<struct epoll_event> events(16);
 }
 
 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);
-       }
+       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()
@@ -194,7 +179,7 @@ int SocketEngine::DispatchEvents()
                if (ev.events & EPOLLHUP)
                {
                        stats.ErrorEvents++;
-                       eh->HandleEvent(EVENT_ERROR, 0);
+                       eh->OnEventHandlerError(0);
                        continue;
                }
 
@@ -206,7 +191,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;
                }
 
@@ -226,16 +211,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();
                }
        }