summaryrefslogtreecommitdiff
path: root/src/inspsocket.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-08 09:32:57 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-08 09:32:57 +0000
commit2329d59b09cdc05b0b403f7d313df65492e1813b (patch)
tree6d5f005565b62883e09ed2b2e09752fc034da413 /src/inspsocket.cpp
parent3794888ebf1fb19f404c22ff2d5333ccc6c3129e (diff)
Extra checking that the fd's we pass to SocketEngine::AddFd were added (a lot of assuming was going off, leading to total chaos if we run out of fd's etc)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4780 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/inspsocket.cpp')
-rw-r--r--src/inspsocket.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp
index 17268dc78..fcd1c3a5a 100644
--- a/src/inspsocket.cpp
+++ b/src/inspsocket.cpp
@@ -52,7 +52,7 @@ InspSocket::InspSocket(int newfd, const char* ip)
this->ClosePending = false;
if (this->fd > -1)
{
- ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE);
+ this->ClosePending = (!ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE));
socket_ref[this->fd] = this;
}
}
@@ -88,7 +88,13 @@ InspSocket::InspSocket(const std::string &ipaddr, int aport, bool listening, uns
this->state = I_LISTENING;
if (this->fd > -1)
{
- ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE);
+ if (!ServerInstance->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;
}
log(DEBUG,"New socket now in I_LISTENING state");
@@ -135,7 +141,14 @@ void InspSocket::WantWrite()
*/
this->WaitingForWriteEvent = true;
ServerInstance->SE->DelFd(this->fd);
- ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE);
+ if (!ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE))
+ {
+ this->Close();
+ this->fd = -1;
+ this->state = I_ERROR;
+ this->OnError(I_ERR_NOMOREFDS);
+ this->ClosePending = true;
+ }
}
void InspSocket::SetQueues(int nfd)
@@ -253,7 +266,15 @@ bool InspSocket::DoConnect()
this->state = I_CONNECTING;
if (this->fd > -1)
{
- ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE);
+ if (!ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE))
+ {
+ this->OnError(I_ERR_NOMOREFDS);
+ this->Close();
+ this->fd = -1;
+ this->state = I_ERROR;
+ this->ClosePending = true;
+ return false;
+ }
socket_ref[this->fd] = this;
this->SetQueues(this->fd);
}
@@ -421,7 +442,8 @@ bool InspSocket::Poll()
if (this->fd > -1)
{
ServerInstance->SE->DelFd(this->fd);
- ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE);
+ if (!ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE))
+ return false;
}
return this->OnConnected();
break;
@@ -442,7 +464,9 @@ bool InspSocket::Poll()
{
/* Switch back to read events */
ServerInstance->SE->DelFd(this->fd);
- ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE);
+ if (!ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE))
+ return false;
+
/* Trigger the write event */
n = this->OnWriteReady();
}