]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/listensocket.cpp
Add Module::init() for correct exception handling during hook registration
[user/henk/code/inspircd.git] / src / listensocket.cpp
index 0d6bf89b638dd140e072dda410a971faffb2af23..e77a585ef4d74758986e3ab47d60156c5616545c 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
  * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
@@ -31,11 +31,12 @@ ListenSocket::ListenSocket(ConfigTag* tag, const std::string& addr, int port)
        irc::sockets::satoap(bind_to, bind_addr, bind_port);
        bind_desc = irc::sockets::satouser(bind_to);
 
-       fd = irc::sockets::OpenTCPSocket(bind_addr);
+       fd = socket(bind_to.sa.sa_family, SOCK_STREAM, 0);
 
        if (this->fd > -1)
        {
-               int rv = ServerInstance->SE->Bind(this->fd, &bind_to.sa, sizeof(bind_to));
+               ServerInstance->SE->SetReuse(fd);
+               int rv = ServerInstance->SE->Bind(this->fd, bind_to);
                if (rv >= 0)
                        rv = ServerInstance->SE->Listen(this->fd, ServerInstance->Config->MaxConn);
 
@@ -71,16 +72,12 @@ void ListenSocket::AcceptInternal()
        irc::sockets::sockaddrs client;
        irc::sockets::sockaddrs server;
 
-       ServerInstance->Logs->Log("SOCKET",DEBUG,"HandleEvent for Listensoket");
-       int incomingSockfd;
-
        socklen_t length = sizeof(client);
-       incomingSockfd = ServerInstance->SE->Accept(this, &client.sa, &length);
+       int incomingSockfd = ServerInstance->SE->Accept(this, &client.sa, &length);
 
+       ServerInstance->Logs->Log("SOCKET",DEBUG,"HandleEvent for Listensoket %s nfd=%d", bind_desc.c_str(), incomingSockfd);
        if (incomingSockfd < 0)
        {
-               ServerInstance->SE->Shutdown(incomingSockfd, 2);
-               ServerInstance->SE->Close(incomingSockfd);
                ServerInstance->stats->statsRefused++;
                return;
        }
@@ -141,7 +138,6 @@ void ListenSocket::AcceptInternal()
        }
 
        ServerInstance->SE->NonBlocking(incomingSockfd);
-       ServerInstance->stats->statsAccept++;
 
        ModResult res;
        FIRST_MOD_RESULT(OnAcceptConnection, res, (incomingSockfd, this, &client, &server));
@@ -154,8 +150,17 @@ void ListenSocket::AcceptInternal()
                        res = MOD_RES_ALLOW;
                }
        }
-       if (res != MOD_RES_ALLOW)
+       if (res == MOD_RES_ALLOW)
+       {
+               ServerInstance->stats->statsAccept++;
+       }
+       else
+       {
+               ServerInstance->stats->statsRefused++;
+               ServerInstance->Logs->Log("SOCKET",DEFAULT,"Refusing connection on %s - %s",
+                       bind_desc.c_str(), res == MOD_RES_DENY ? "Connection refused by module" : "Module for this port not found");
                ServerInstance->SE->Close(incomingSockfd);
+       }
 }
 
 void ListenSocket::HandleEvent(EventType e, int err)