]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socketengines/socketengine_epoll.cpp
irc::stringjoiner cleanup
[user/henk/code/inspircd.git] / src / socketengines / socketengine_epoll.cpp
index 567ddd69f4d0389b107c0b9dbc8b749526b75191..895d8aa2504eef052016ee45ce7e1eb78f510cd3 100644 (file)
@@ -26,6 +26,7 @@
 #include "socketengine.h"
 #include <sys/epoll.h>
 #include <ulimit.h>
+#include <iostream>
 #define EP_DELAY 5
 
 /** A specialisation of the SocketEngine class, designed to use linux 2.6 epoll().
@@ -60,8 +61,8 @@ EPollEngine::EPollEngine()
        }
        else
        {
-               ServerInstance->Logs->Log("SOCKET", DEFAULT, "ERROR: Can't determine maximum number of open sockets!");
-               printf("ERROR: Can't determine maximum number of open sockets!\n");
+               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->Exit(EXIT_STATUS_SOCKETENGINE);
        }
 
@@ -70,10 +71,10 @@ EPollEngine::EPollEngine()
 
        if (EngineHandle == -1)
        {
-               ServerInstance->Logs->Log("SOCKET",DEFAULT, "ERROR: Could not initialize socket engine: %s", strerror(errno));
-               ServerInstance->Logs->Log("SOCKET",DEFAULT, "ERROR: Your kernel probably does not have the proper features. This is a fatal error, exiting now.");
-               printf("ERROR: Could not initialize epoll socket engine: %s\n", strerror(errno));
-               printf("ERROR: Your kernel probably does not have the proper features. This is a fatal error, exiting now.\n");
+               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->Exit(EXIT_STATUS_SOCKETENGINE);
        }
 
@@ -90,9 +91,9 @@ EPollEngine::~EPollEngine()
        delete[] events;
 }
 
-static int mask_to_epoll(int event_mask)
+static unsigned mask_to_epoll(int event_mask)
 {
-       int rv = 0;
+       unsigned rv = 0;
        if (event_mask & (FD_WANT_POLL_READ | FD_WANT_POLL_WRITE | FD_WANT_SINGLE_WRITE))
        {
                // we need to use standard polling on this FD
@@ -118,13 +119,13 @@ bool EPollEngine::AddFd(EventHandler* eh, int event_mask)
        int fd = eh->GetFd();
        if ((fd < 0) || (fd > GetMaxFds() - 1))
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+               ServerInstance->Logs->Log("SOCKET",LOG_DEBUG,"AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
                return false;
        }
 
        if (ref[fd])
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"Attempt to add duplicate fd: %d", fd);
+               ServerInstance->Logs->Log("SOCKET",LOG_DEBUG,"Attempt to add duplicate fd: %d", fd);
                return false;
        }
 
@@ -135,11 +136,11 @@ bool EPollEngine::AddFd(EventHandler* eh, int event_mask)
        int i = epoll_ctl(EngineHandle, EPOLL_CTL_ADD, fd, &ev);
        if (i < 0)
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"Error adding fd: %d to socketengine: %s", fd, strerror(errno));
+               ServerInstance->Logs->Log("SOCKET",LOG_DEBUG,"Error adding fd: %d to socketengine: %s", fd, strerror(errno));
                return false;
        }
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"New file descriptor: %d", fd);
+       ServerInstance->Logs->Log("SOCKET",LOG_DEBUG,"New file descriptor: %d", fd);
 
        ref[fd] = eh;
        SocketEngine::SetEventMask(eh, event_mask);
@@ -149,8 +150,8 @@ bool EPollEngine::AddFd(EventHandler* eh, int event_mask)
 
 void EPollEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
 {
-       int old_events = mask_to_epoll(old_mask);
-       int new_events = mask_to_epoll(new_mask);
+       unsigned old_events = mask_to_epoll(old_mask);
+       unsigned new_events = mask_to_epoll(new_mask);
        if (old_events != new_events)
        {
                // ok, we actually have something to tell the kernel about
@@ -167,7 +168,7 @@ void EPollEngine::DelFd(EventHandler* eh)
        int fd = eh->GetFd();
        if ((fd < 0) || (fd > GetMaxFds() - 1))
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+               ServerInstance->Logs->Log("SOCKET",LOG_DEBUG,"DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
                return;
        }
 
@@ -178,12 +179,12 @@ void EPollEngine::DelFd(EventHandler* eh)
 
        if (i < 0)
        {
-               ServerInstance->Logs->Log("SOCKET",DEBUG,"epoll_ctl can't remove socket: %s", strerror(errno));
+               ServerInstance->Logs->Log("SOCKET",LOG_DEBUG,"epoll_ctl can't remove socket: %s", strerror(errno));
        }
 
        ref[fd] = NULL;
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd);
+       ServerInstance->Logs->Log("SOCKET",LOG_DEBUG,"Remove file descriptor: %d", fd);
        CurrentSetSize--;
 }
 
@@ -201,7 +202,7 @@ int EPollEngine::DispatchEvents()
                EventHandler* eh = ref[events[j].data.fd];
                if (!eh)
                {
-                       ServerInstance->Logs->Log("SOCKET",DEBUG,"Got event on unknown fd: %d", events[j].data.fd);
+                       ServerInstance->Logs->Log("SOCKET",LOG_DEBUG,"Got event on unknown fd: %d", events[j].data.fd);
                        epoll_ctl(EngineHandle, EPOLL_CTL_DEL, events[j].data.fd, &events[j]);
                        continue;
                }