diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-09 14:53:19 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-09 14:53:19 +0000 |
commit | ab46b96db4d457e6a4f2e978c38b79762cdeb9d5 (patch) | |
tree | 01b9489ae9804ee45b765ad7045efee54b34347b /src/inspsocket.cpp | |
parent | f0680338833dd76966ba1769980abb9eafb50467 (diff) |
Move socket_ref and module_sockets vectors/arrays into InspIRCd*. These are public members, which InspSocket can modify.
(eventually, this will be marshalled safely through some accessors). When constructing an InspSocket you must now provide
an InspIRCd* instance to 'attach' the socket to.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4812 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/inspsocket.cpp')
-rw-r--r-- | src/inspsocket.cpp | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 5c8607f7d..6a0fbc556 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -21,43 +21,42 @@ #include <stdexcept> #include "inspircd_config.h" #include "socket.h" -#include "inspircd.h" #include "configreader.h" #include "inspstring.h" #include "helperfuncs.h" #include "socketengine.h" #include "message.h" +#include "inspircd.h" -extern InspIRCd* ServerInstance; extern time_t TIME; extern Server* MyServer; -InspSocket* socket_ref[MAX_DESCRIPTORS]; - - -InspSocket::InspSocket() +InspSocket::InspSocket(InspIRCd* SI) { this->state = I_DISCONNECTED; this->fd = -1; this->ClosePending = false; + this->Instance = SI; } -InspSocket::InspSocket(int newfd, const char* ip) +InspSocket::InspSocket(InspIRCd* SI, int newfd, const char* ip) { this->fd = newfd; this->state = I_CONNECTED; strlcpy(this->IP,ip,MAXBUF); this->ClosePending = false; + this->Instance = SI; if (this->fd > -1) { - this->ClosePending = (!ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE)); - socket_ref[this->fd] = this; + this->ClosePending = (!this->Instance->SE->AddFd(this->fd,true,X_ESTAB_MODULE)); + this->Instance->socket_ref[this->fd] = this; } } -InspSocket::InspSocket(const std::string &ipaddr, int aport, bool listening, unsigned long maxtime) : fd(-1) +InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool listening, unsigned long maxtime) : fd(-1) { + this->Instance = SI; strlcpy(host,ipaddr.c_str(),MAXBUF); this->ClosePending = false; if (listening) { @@ -87,14 +86,14 @@ InspSocket::InspSocket(const std::string &ipaddr, int aport, bool listening, uns this->state = I_LISTENING; if (this->fd > -1) { - if (!ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE)) + if (!this->Instance->SE->AddFd(this->fd,true,X_ESTAB_MODULE)) { this->Close(); this->state = I_ERROR; this->OnError(I_ERR_NOMOREFDS); this->ClosePending = true; } - socket_ref[this->fd] = this; + this->Instance->socket_ref[this->fd] = this; } log(DEBUG,"New socket now in I_LISTENING state"); return; @@ -139,8 +138,8 @@ void InspSocket::WantWrite() * This behaviour may be fixed in a later version. */ this->WaitingForWriteEvent = true; - ServerInstance->SE->DelFd(this->fd); - if (!ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE)) + this->Instance->SE->DelFd(this->fd); + if (!this->Instance->SE->AddFd(this->fd,false,X_ESTAB_MODULE)) { this->Close(); this->fd = -1; @@ -265,7 +264,7 @@ bool InspSocket::DoConnect() this->state = I_CONNECTING; if (this->fd > -1) { - if (!ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE)) + if (!this->Instance->SE->AddFd(this->fd,false,X_ESTAB_MODULE)) { this->OnError(I_ERR_NOMOREFDS); this->Close(); @@ -274,7 +273,7 @@ bool InspSocket::DoConnect() this->ClosePending = true; return false; } - socket_ref[this->fd] = this; + this->Instance->socket_ref[this->fd] = this; this->SetQueues(this->fd); } log(DEBUG,"Returning true from InspSocket::DoConnect"); @@ -289,7 +288,7 @@ void InspSocket::Close() this->OnClose(); shutdown(this->fd,2); close(this->fd); - socket_ref[this->fd] = NULL; + this->Instance->socket_ref[this->fd] = NULL; this->ClosePending = true; this->fd = -1; } @@ -390,7 +389,7 @@ bool InspSocket::FlushWriteBuffer() bool InspSocket::Timeout(time_t current) { - if (!socket_ref[this->fd] || !ServerInstance->SE->HasFd(this->fd)) + if (!this->Instance->socket_ref[this->fd] || !this->Instance->SE->HasFd(this->fd)) { log(DEBUG,"No FD or socket ref"); return false; @@ -421,7 +420,7 @@ bool InspSocket::Timeout(time_t current) bool InspSocket::Poll() { - if (!socket_ref[this->fd] || !ServerInstance->SE->HasFd(this->fd)) + if (!this->Instance->socket_ref[this->fd] || !this->Instance->SE->HasFd(this->fd)) return false; int incoming = -1; @@ -440,8 +439,8 @@ bool InspSocket::Poll() */ if (this->fd > -1) { - ServerInstance->SE->DelFd(this->fd); - if (!ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE)) + this->Instance->SE->DelFd(this->fd); + if (!this->Instance->SE->AddFd(this->fd,true,X_ESTAB_MODULE)) return false; } return this->OnConnected(); @@ -462,8 +461,8 @@ bool InspSocket::Poll() if (this->WaitingForWriteEvent) { /* Switch back to read events */ - ServerInstance->SE->DelFd(this->fd); - if (!ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE)) + this->Instance->SE->DelFd(this->fd); + if (!this->Instance->SE->AddFd(this->fd,true,X_ESTAB_MODULE)) return false; /* Trigger the write event */ |