]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socket.cpp
Split more of treesocket1
[user/henk/code/inspircd.git] / src / socket.cpp
index 09885eca16d3fd209f1e68f0eaebbbccb8701c1b..bd8147b3fa08e2ebc74fdf4b2be751b036cbaaae 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
@@ -65,13 +65,24 @@ ListenSocket::~ListenSocket()
        }
 }
 
+
+// XXX this is a bit of an untidy way to avoid reallocating this constantly. also, we leak it on shutdown.. but that's kinda minor - w
+static sockaddr *sock_us;
+static sockaddr *client;
+static bool setup_sock = false;
+
 void ListenSocket::HandleEvent(EventType, int)
 {
-       sockaddr* sock_us = new sockaddr[2];    // our port number
-       sockaddr* client = new sockaddr[2];
        socklen_t uslen, length;                // length of our port number
        int incomingSockfd, in_port;
 
+       if (!setup_sock)
+       {
+               sock_us = new sockaddr[2];
+               client = new sockaddr[2];
+               setup_sock = true;
+       }
+
 #ifdef IPV6
        if (this->family == AF_INET6)
        {
@@ -117,7 +128,7 @@ void ListenSocket::HandleEvent(EventType, int)
                        }
                }
                ServerInstance->stats->statsAccept++;
-               User::AddClient(ServerInstance, incomingSockfd, in_port, false, this->family, client);
+               ServerInstance->Users->AddClient(ServerInstance, incomingSockfd, in_port, false, this->family, client);
        }
        else
        {
@@ -125,8 +136,6 @@ void ListenSocket::HandleEvent(EventType, int)
                ServerInstance->SE->Close(incomingSockfd);
                ServerInstance->stats->statsRefused++;
        }
-       delete[] client;
-       delete[] sock_us;
 }
 
 /* Match raw bytes using CIDR bit matching, used by higher level MatchCIDR() */