diff options
-rw-r--r-- | include/socket.h | 4 | ||||
-rw-r--r-- | src/modules.cpp | 12 | ||||
-rw-r--r-- | src/socket.cpp | 16 |
3 files changed, 18 insertions, 14 deletions
diff --git a/include/socket.h b/include/socket.h index e36bbd231..7dabd4bd3 100644 --- a/include/socket.h +++ b/include/socket.h @@ -148,6 +148,8 @@ private: void SetQueues(int nfd); + bool ClosePending; + public: /** @@ -326,6 +328,8 @@ public: virtual bool DoResolve(); virtual bool DoConnect(); + + void MarkAsClosed(); }; #endif diff --git a/src/modules.cpp b/src/modules.cpp index 5847e6054..529946220 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -328,17 +328,7 @@ void Server::RemoveSocket(InspSocket* sock) { InspSocket* s = (InspSocket*)*a; if (s == sock) - { - s->Close(); - /* - log(DEBUG,"Forcibly removed socket"); - ServerInstance->SE->DelFd(s->GetFd()); - log(DEBUG,"Delete Fd from socket engine"); - s->Close(); - module_sockets.erase(a); - delete s; - return;*/ - } + s->MarkAsClosed(); } } diff --git a/src/socket.cpp b/src/socket.cpp index 23d760002..2f8030d7f 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -48,6 +48,7 @@ InspSocket::InspSocket() { this->state = I_DISCONNECTED; this->fd = -1; + this->ClosePending = false; } InspSocket::InspSocket(int newfd, char* ip) @@ -55,13 +56,14 @@ InspSocket::InspSocket(int newfd, char* ip) this->fd = newfd; this->state = I_CONNECTED; this->IP = ip; + this->ClosePending = false; ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE); socket_ref[this->fd] = this; } -InspSocket::InspSocket(const std::string &ahost, int aport, bool listening, unsigned long maxtime) - : fd(-1), host(ahost) +InspSocket::InspSocket(const std::string &ahost, int aport, bool listening, unsigned long maxtime) : fd(-1), host(ahost) { + this->ClosePending = false; this->outbuffer.clear(); if (listening) { if ((this->fd = OpenTCPSocket()) == ERROR) @@ -240,6 +242,11 @@ char* InspSocket::Read() } } +void InspSocket::MarkAsClosed() +{ + this->ClosePending = true; +} + // There are two possible outcomes to this function. // It will either write all of the data, or an undefined amount. // If an undefined amount is written the connection has failed @@ -290,6 +297,9 @@ bool InspSocket::Timeout(time_t current) if (!socket_ref[this->fd] || !ServerInstance->SE->HasFd(this->fd)) return false; + if (this->ClosePending) + return true; + if (((this->state == I_RESOLVING) || (this->state == I_CONNECTING)) && (current > timeout_end)) { log(DEBUG,"Timed out, current=%lu timeout_end=%lu"); @@ -314,7 +324,7 @@ bool InspSocket::Poll() int incoming = -1; bool n = true; - if ((fd < 0) || (fd > MAX_DESCRIPTORS)) + if ((fd < 0) || (fd > MAX_DESCRIPTORS) || (this->ClosePending)) return false; switch (this->state) |