diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-12 12:07:44 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-12 12:07:44 +0000 |
commit | c720c0a3c7e990bd70507791c13e728ea7bfc21c (patch) | |
tree | 40cbc00c61628903f9027af60836d0e2f74fe7e7 /src/socket.cpp | |
parent | 718e7fa3cc47f84ad25b873d83479800f0559899 (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/socket.cpp')
-rw-r--r-- | src/socket.cpp | 59 |
1 files changed, 35 insertions, 24 deletions
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; } |