summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-12 22:29:06 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-12 22:29:06 +0000
commit7d283ead756f22b2c659414b89938777ad97599f (patch)
tree5f658ddae1ed059e127e9939bd2ab6e651240d8a
parent4d6d3859d208d5576e7149de9a0a5576b7cf5153 (diff)
Efficiency suggestion by w00t, faster processing of module sockets at the expense of a bit of ram
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2357 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/inspircd.cpp25
-rw-r--r--src/socket.cpp6
2 files changed, 20 insertions, 11 deletions
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 5b4b8f5d1..ccf0257e7 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -121,6 +121,8 @@ char addrs[MAXBUF][255];
socklen_t length;
char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
+extern InspSocket* socket_ref[65535];
+
time_t TIME = time(NULL), OLDTIME = time(NULL);
SocketEngine* SE = NULL;
@@ -2639,8 +2641,9 @@ int InspIRCd(char** argv, int argc)
int incomingSockfd;
userrec* cu = NULL;
InspSocket* s = NULL;
+ InspSocket* s_del = NULL;
char target[MAXBUF];
- unsigned int numsockets, numberactive;
+ unsigned int numberactive;
/* Beta 7 moved all this stuff out of the main function
* into smaller sub-functions, much tidier -- Brain
@@ -2755,23 +2758,23 @@ int InspIRCd(char** argv, int argc)
* Modules are encouraged to inherit their sockets from
* InspSocket so we can process them neatly like this.
*/
- numsockets = module_sockets.size();
- for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
+ s = socket_ref[activefds[activefd]];
+
+ if ((s) && (!s->Poll()))
{
- s = (InspSocket*)*a;
- if ((s) && (s->GetFd() == activefds[activefd]))
+ log(DEBUG,"Socket poll returned false, close and bail");
+ SE->DelFd(s->GetFd());
+ for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
{
- if (!s->Poll())
+ s_del = (InspSocket*)*a;
+ if ((s_del) && (s_del->GetFd() == activefds[activefd]))
{
- log(DEBUG,"Socket poll returned false, close and bail");
- SE->DelFd(s->GetFd());
- s->Close();
module_sockets.erase(a);
- delete s;
break;
}
- if (module_sockets.size() != numsockets) break;
}
+ s->Close();
+ delete s;
}
break;
diff --git a/src/socket.cpp b/src/socket.cpp
index 625c0ff70..8da570fe4 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -46,6 +46,8 @@ extern time_t TIME;
extern bool unlimitcore;
extern int MaxConn;
+InspSocket* socket_ref[65535];
+
InspSocket::InspSocket()
{
this->state = I_DISCONNECTED;
@@ -57,6 +59,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 +88,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 +136,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 +148,7 @@ void InspSocket::Close()
this->OnClose();
shutdown(this->fd,2);
close(this->fd);
+ socket_ref[this->fd] = NULL;
this->fd = -1;
}
}