]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socket.cpp
*slaps self* for not test compiling
[user/henk/code/inspircd.git] / src / socket.cpp
index 3c446c45b2fccb00bb34c9eadc9794c4d9d9cf3a..9345af22486453b33b6008bbd42f6736bc250660 100644 (file)
@@ -2,14 +2,11 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                    E-mail:
- *             <brain@chatspike.net>
- *               <Craig@chatspike.net>
- *     
- * Written by Craig Edwards, Craig McLure, and others.
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
  * This program is free but copyrighted software; see
- *         the file COPYING for details.
+ *            the file COPYING for details.
  *
  * ---------------------------------------------------
  */
@@ -21,7 +18,6 @@
 #include "socketengine.h"
 #include "wildcard.h"
 
-using namespace std;
 using namespace irc::sockets;
 
 /* Used when comparing CIDR masks for the modulus bits left over.
@@ -40,7 +36,7 @@ const char inverted_bits[8] = {       0x00, /* 00000000 - 0 bits - never actually used
 };
 
 
-ListenSocket::ListenSocket(InspIRCd* Instance, int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr) : ServerInstance(Instance)
+ListenSocket::ListenSocket(InspIRCd* Instance, int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr) : ServerInstance(Instance), desc("plaintext")
 {
        this->SetFd(sockfd);
        Instance->Log(DEBUG,"Binding to port %s:%d",addr,port);
@@ -51,6 +47,16 @@ ListenSocket::ListenSocket(InspIRCd* Instance, int sockfd, insp_sockaddr client,
        }
 }
 
+ListenSocket::~ListenSocket()
+{
+       if (this->GetFd() > -1)
+       {
+               shutdown(this->fd, 2);
+               close(this->fd);
+               this->fd = -1;
+       }
+}
+
 void ListenSocket::HandleEvent(EventType et, int errornum)
 {
        insp_sockaddr sock_us;  // our port number
@@ -84,9 +90,9 @@ void ListenSocket::HandleEvent(EventType et, int errornum)
                                ServerInstance->Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin_addr), in_port);
 #endif
                        }
-                       catch (ModuleException& modexcept)
+                       catch (CoreException& modexcept)
                        {
-                               ServerInstance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
+                               ServerInstance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
                        }
                }
                ServerInstance->stats->statsAccept++;
@@ -275,19 +281,18 @@ bool irc::sockets::MatchCIDR(const char* address, const char* cidr_mask, bool ma
        return MatchCIDRBits(addr_raw, mask_raw, bits);
 }
 
-inline void irc::sockets::Blocking(int s)
+void irc::sockets::Blocking(int s)
 {
        int flags = fcntl(s, F_GETFL, 0);
        fcntl(s, F_SETFL, flags ^ O_NONBLOCK);
 }
 
-inline void irc::sockets::NonBlocking(int s)
+void irc::sockets::NonBlocking(int s)
 {
        int flags = fcntl(s, F_GETFL, 0);
        fcntl(s, F_SETFL, flags | O_NONBLOCK);
 }
 
-
 /** This will bind a socket to a port. It works for UDP/TCP.
  * It can only bind to IP addresses, if you wish to bind to hostnames
  * you should first resolve them using class 'Resolver'.
@@ -389,7 +394,7 @@ bool InspIRCd::HasPort(int port, char* addr)
 }
 
 /* XXX: Probably belongs in class InspIRCd */
-int InspIRCd::BindPorts(bool bail, int &ports_found)
+int InspIRCd::BindPorts(bool bail, int &ports_found, FailedPortList &failed_ports)
 {
        char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
        insp_sockaddr client, server;
@@ -411,7 +416,7 @@ int InspIRCd::BindPorts(bool bail, int &ports_found)
                {
                        irc::portparser portrange(configToken, false);
                        long portno = -1;
-                       while (portno = portrange.GetToken())
+                       while ((portno = portrange.GetToken()))
                        {
                                if (!HasPort(portno, Addr))
                                {
@@ -439,6 +444,7 @@ int InspIRCd::BindPorts(bool bail, int &ports_found)
                                        if (fd == ERROR)
                                        {
                                                this->Log(DEBUG,"Bad fd %d binding port [%s:%d]",fd,Config->addrs[count],Config->ports[count]);
+                                               failed_ports.push_back(std::make_pair(Config->addrs[count],Config->ports[count]));
                                        }
                                        else
                                        {
@@ -451,6 +457,7 @@ int InspIRCd::BindPorts(bool bail, int &ports_found)
                                                                shutdown(Config->openSockfd[BoundPortCount]->GetFd(),2);
                                                                close(Config->openSockfd[BoundPortCount]->GetFd());
                                                                delete Config->openSockfd[BoundPortCount];
+                                                               failed_ports.push_back(std::make_pair(Config->addrs[count],Config->ports[count]));
                                                        }
                                                        else
                                                                BoundPortCount++;
@@ -475,6 +482,7 @@ int InspIRCd::BindPorts(bool bail, int &ports_found)
                if (fd == ERROR)
                {
                        this->Log(DEBUG,"Bad fd %d binding port [%s:%d]",fd,Config->addrs[count],Config->ports[count]);
+                       failed_ports.push_back(std::make_pair(Config->addrs[count],Config->ports[count]));
                }
                else
                {
@@ -483,6 +491,8 @@ int InspIRCd::BindPorts(bool bail, int &ports_found)
                        {
                                BoundPortCount++;
                        }
+                       else
+                               failed_ports.push_back(std::make_pair(Config->addrs[count],Config->ports[count]));
                }
        }
        return BoundPortCount;