]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socket.cpp
Moved some other stuff into ServerConfig
[user/henk/code/inspircd.git] / src / socket.cpp
index f441ddb552d5a6ead6c2852052a0d0441d3bf3c8..420c29f6ff6700789edc8f006728073d9595bb62 100644 (file)
@@ -39,12 +39,11 @@ using namespace std;
 
 extern SocketEngine* SE;
 
-extern FILE *log_file;
 extern int boundPortCount;
 extern int openSockfd[MAXSOCKS];
 extern time_t TIME;
-extern bool unlimitcore;
-extern int MaxConn;
+
+InspSocket* socket_ref[65535];
 
 InspSocket::InspSocket()
 {
@@ -57,6 +56,7 @@ InspSocket::InspSocket(int newfd, char* ip)
        this->state = I_CONNECTED;
        this->IP = ip;
        SE->AddFd(this->fd,true,X_ESTAB_MODULE);
+       socket_ref[this->fd] = this;
 }
 
 InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long maxtime)
@@ -85,6 +85,7 @@ InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long
                        {
                                this->state = I_LISTENING;
                                SE->AddFd(this->fd,true,X_ESTAB_MODULE);
+                               socket_ref[this->fd] = this;
                                log(DEBUG,"New socket now in I_LISTENING state");
                                return;
                        }
@@ -132,6 +133,7 @@ InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long
                 }
                 this->state = I_CONNECTING;
                SE->AddFd(this->fd,false,X_ESTAB_MODULE);
+               socket_ref[this->fd] = this;
                 return;
        }
 }
@@ -143,6 +145,7 @@ void InspSocket::Close()
                this->OnClose();
                shutdown(this->fd,2);
                close(this->fd);
+               socket_ref[this->fd] = NULL;
                this->fd = -1;
        }
 }
@@ -194,9 +197,9 @@ int InspSocket::Write(std::string data)
        return written;
 }
 
-bool InspSocket::Poll()
+bool InspSocket::Timeout(time_t current)
 {
-       if ((time(NULL) > timeout_end) && (this->state == I_CONNECTING))
+       if ((this->state == I_CONNECTING) && (current > timeout_end))
        {
                // for non-listening sockets, the timeout can occur
                // which causes termination of the connection after
@@ -204,23 +207,27 @@ bool InspSocket::Poll()
                // connection.
                this->OnTimeout();
                this->OnError(I_ERR_TIMEOUT);
-               timeout = true;
+               timeout = true;
                this->state = I_ERROR;
-               return false;
+               return true;
        }
+       return false;
+}
 
+bool InspSocket::Poll()
+{
        int incoming = -1;
        
        switch (this->state)
        {
                case I_CONNECTING:
                        this->SetState(I_CONNECTED);
-                       return this->OnConnected();
                        /* Our socket was in write-state, so delete it and re-add it
                         * in read-state.
                         */
                        SE->DelFd(this->fd);
                        SE->AddFd(this->fd,true,X_ESTAB_MODULE);
+                       return this->OnConnected();
                break;
                case I_LISTENING:
                        length = sizeof (client);