summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-12 12:07:44 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-12 12:07:44 +0000
commitc720c0a3c7e990bd70507791c13e728ea7bfc21c (patch)
tree40cbc00c61628903f9027af60836d0e2f74fe7e7 /src
parent718e7fa3cc47f84ad25b873d83479800f0559899 (diff)
Added module sockets to new engine, MAY NOT WORK
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2328 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/inspircd.cpp62
-rw-r--r--src/socket.cpp59
2 files changed, 73 insertions, 48 deletions
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 5d10c088f..1f80ffd97 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -1615,13 +1615,12 @@ std::string GetVersionString()
s1 = savept;
v2 = strtok_r(s1," ",&savept);
s1 = savept;
- char socketengine[] = engine_name;
#ifdef THREADED_DNS
char dnsengine[] = "multithread";
#else
char dnsengine[] = "singlethread";
#endif
- snprintf(versiondata,MAXBUF,"%s Rev. %s %s :%s [FLAGS=%lu,%s,%s]",VERSION,v2,ServerName,SYSTEM,(unsigned long)OPTIMISATION,socketengine,dnsengine);
+ snprintf(versiondata,MAXBUF,"%s Rev. %s %s :%s [FLAGS=%lu,%s,%s]",VERSION,v2,ServerName,SYSTEM,(unsigned long)OPTIMISATION,SE->GetName().c_str(),dnsengine);
return versiondata;
}
@@ -2657,22 +2656,6 @@ int InspIRCd(char** argv, int argc)
dns_poll();
#endif
- unsigned int numsockets = module_sockets.size();
- for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
- {
- InspSocket* s = (InspSocket*)*a;
- if ((s) && (!s->Poll()))
- {
- log(DEBUG,"Socket poll returned false, close and bail");
- s->Close();
- module_sockets.erase(a);
- delete s;
- break;
- }
- // we gained a socket, sarper
- if (module_sockets.size() != numsockets) break;
- }
-
// *FIX* Instead of closing sockets in kill_link when they receive the ERROR :blah line, we should queue
// them in a list, then reap the list every second or so.
if (((TIME % 5) == 0) && (!expire_run))
@@ -2688,17 +2671,48 @@ int InspIRCd(char** argv, int argc)
DoBackgroundUserStuff();
SE->Wait(activefds);
-
+
for (unsigned int activefd = 0; activefd < activefds.size(); activefd++)
{
- userrec* cu = fd_ref_table[activefds[activefd]];
- if (cu)
+ if (SE->GetType(activefds[activefd]) == X_ESTAB_CLIENT)
{
- /* It's a user */
- ProcessUser(cu);
+ log(DEBUG,"Got a ready socket of type X_ESTAB_CLIENT");
+ userrec* cu = fd_ref_table[activefds[activefd]];
+ if (cu)
+ {
+ /* It's a user */
+ ProcessUser(cu);
+ }
}
- else
+ else if (SE->GetType(activefds[activefd]) == X_MODULE)
+ {
+ log(DEBUG,"Got a ready socket of type X_MODULE");
+ unsigned int numsockets = module_sockets.size();
+ for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
+ {
+ InspSocket* s = (InspSocket*)*a;
+ if ((s) && (s->GetFd() == activefds[activefd]))
+ {
+ if (!s->Poll())
+ {
+ 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;
+ }
+ }
+ }
+ else if (SE->GetType(activefds[activefd]) == X_ESTAB_DNS)
+ {
+ log(DEBUG,"Got a ready socket of type X_ESTAB_DNS");
+ }
+ else if (SE->GetType(activefds[activefd]) == X_LISTEN)
{
+ log(DEBUG,"Got a ready socket of type X_LISTEN");
/* It maybe a listener */
for (count = 0; count < boundPortCount; count++)
{
diff --git a/src/socket.cpp b/src/socket.cpp
index 36b6d1d1e..f441ddb55 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -35,6 +35,9 @@ using namespace std;
#include "inspircd_util.h"
#include "inspstring.h"
#include "helperfuncs.h"
+#include "socketengine.h"
+
+extern SocketEngine* SE;
extern FILE *log_file;
extern int boundPortCount;
@@ -53,6 +56,7 @@ InspSocket::InspSocket(int newfd, char* ip)
this->fd = newfd;
this->state = I_CONNECTED;
this->IP = ip;
+ SE->AddFd(this->fd,true,X_ESTAB_MODULE);
}
InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long maxtime)
@@ -80,6 +84,7 @@ InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long
else
{
this->state = I_LISTENING;
+ SE->AddFd(this->fd,true,X_ESTAB_MODULE);
log(DEBUG,"New socket now in I_LISTENING state");
return;
}
@@ -126,6 +131,7 @@ InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long
}
}
this->state = I_CONNECTING;
+ SE->AddFd(this->fd,false,X_ESTAB_MODULE);
return;
}
}
@@ -202,33 +208,33 @@ bool InspSocket::Poll()
this->state = I_ERROR;
return false;
}
- polls.fd = this->fd;
- state == I_CONNECTING ? polls.events = POLLOUT : polls.events = POLLIN;
- int ret = poll(&polls,1,1);
- if (ret > 0)
+ int incoming = -1;
+
+ switch (this->state)
{
- int incoming = -1;
-
- switch (this->state)
- {
- case I_CONNECTING:
- this->SetState(I_CONNECTED);
- return this->OnConnected();
- break;
- case I_LISTENING:
- length = sizeof (client);
- incoming = accept (this->fd, (sockaddr*)&client,&length);
- this->OnIncomingConnection(incoming,inet_ntoa(client.sin_addr));
- return true;
- break;
- case I_CONNECTED:
- return this->OnDataReady();
- break;
- default:
- break;
- }
+ 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);
+ break;
+ case I_LISTENING:
+ length = sizeof (client);
+ incoming = accept (this->fd, (sockaddr*)&client,&length);
+ this->OnIncomingConnection(incoming,inet_ntoa(client.sin_addr));
+ return true;
+ break;
+ case I_CONNECTED:
+ return this->OnDataReady();
+ break;
+ default:
+ break;
}
+
return true;
}
@@ -243,6 +249,11 @@ InspSocketState InspSocket::GetState()
return this->state;
}
+int InspSocket::GetFd()
+{
+ return this->fd;
+}
+
bool InspSocket::OnConnected() { return true; }
void InspSocket::OnError(InspSocketError e) { return; }
int InspSocket::OnDisconnect() { return 0; }