]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socket.cpp
Fixed to dynamically allocate the fieldlist
[user/henk/code/inspircd.git] / src / socket.cpp
index c4129f67cfeff4316dcca72a19901a4f1a327eb8..b9d5fee5f088cac73729674cf49affdb6da86f85 100644 (file)
@@ -26,7 +26,6 @@
 extern InspIRCd* ServerInstance;
 extern ServerConfig* Config;
 extern time_t TIME;
-extern int openSockfd[MAX_DESCRIPTORS];
 
 /** This will bind a socket to a port. It works for UDP/TCP.
  * If a hostname is given to bind to, the function will first
@@ -120,7 +119,7 @@ int OpenTCPSocket()
 
 bool HasPort(int port, char* addr)
 {
-       for (int count = 0; count < ServerInstance->stats->BoundPortCount; count++)
+       for (unsigned long count = 0; count < ServerInstance->stats->BoundPortCount; count++)
        {
                if ((port == Config->ports[count]) && (!strcasecmp(Config->addrs[count],addr)))
                {
@@ -165,20 +164,23 @@ int BindPorts(bool bail)
                {
                        for (int count = InitialPortCount; count < InitialPortCount + PortCount; count++)
                        {
-                               if ((openSockfd[count] = OpenTCPSocket()) == ERROR)
+                               if ((Config->openSockfd[count] = OpenTCPSocket()) == ERROR)
                                {
-                                       log(DEBUG,"Bad fd %d binding port [%s:%d]",openSockfd[count],Config->addrs[count],Config->ports[count]);
+                                       log(DEBUG,"Bad fd %d binding port [%s:%d]",Config->openSockfd[count],Config->addrs[count],Config->ports[count]);
                                        return ERROR;
                                }
-                               if (!BindSocket(openSockfd[count],client,server,Config->ports[count],Config->addrs[count]))
+                               if (!BindSocket(Config->openSockfd[count],client,server,Config->ports[count],Config->addrs[count]))
                                {
                                        log(DEFAULT,"Failed to bind port [%s:%d]: %s",Config->addrs[count],Config->ports[count],strerror(errno));
                                }
                                else
                                {
                                        /* Associate the new open port with a slot in the socket engine */
-                                       ServerInstance->SE->AddFd(openSockfd[count],true,X_LISTEN);
-                                       BoundPortCount++;
+                                       if (Config->openSockfd[count] > -1)
+                                       {
+                                               ServerInstance->SE->AddFd(Config->openSockfd[count],true,X_LISTEN);
+                                               BoundPortCount++;
+                                       }
                                }
                        }
                        return InitialPortCount + BoundPortCount;
@@ -218,13 +220,13 @@ int BindPorts(bool bail)
 
        for (int count = 0; count < PortCount; count++)
        {
-               if ((openSockfd[BoundPortCount] = OpenTCPSocket()) == ERROR)
+               if ((Config->openSockfd[BoundPortCount] = OpenTCPSocket()) == ERROR)
                {
-                       log(DEBUG,"Bad fd %d binding port [%s:%d]",openSockfd[BoundPortCount],Config->addrs[count],Config->ports[count]);
+                       log(DEBUG,"Bad fd %d binding port [%s:%d]",Config->openSockfd[BoundPortCount],Config->addrs[count],Config->ports[count]);
                        return ERROR;
                }
 
-               if (!BindSocket(openSockfd[BoundPortCount],client,server,Config->ports[count],Config->addrs[count]))
+               if (!BindSocket(Config->openSockfd[BoundPortCount],client,server,Config->ports[count],Config->addrs[count]))
                {
                        log(DEFAULT,"Failed to bind port [%s:%d]: %s",Config->addrs[count],Config->ports[count],strerror(errno));
                }