aboutsummaryrefslogtreecommitdiffstats
path: root/src/socket.cpp
diff options
context:
space:
mode:
authorGravatar brain2006-08-08 09:21:48 +0000
committerGravatar brain2006-08-08 09:21:48 +0000
commite842add667c59d49b8c635aafd48e35c427b811d (patch)
treedc681cffd588641c0f8426f03b5ba2a7b2e3b9fa /src/socket.cpp
parentAs trunk: remove dependent commands from hash before deleting Module* so that... (diff)
More checks for running out of file descriptors, or file descriptors being forbidden
git-svn-id: http://svn.inspircd.org/repository/branches/1_0_stable@4779 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/socket.cpp')
-rw-r--r--src/socket.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/socket.cpp b/src/socket.cpp
index e25e096c6..c12450e29 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -57,8 +57,7 @@ InspSocket::InspSocket(int newfd, char* ip)
this->fd = newfd;
this->state = I_CONNECTED;
strlcpy(this->IP,ip,MAXBUF);
- this->ClosePending = false;
- 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;
}
@@ -91,7 +90,14 @@ InspSocket::InspSocket(const std::string &ahost, int aport, bool listening, unsi
else
{
this->state = I_LISTENING;
- ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE);
+ if (!ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE))
+ {
+ this->Close();
+ this->fd = -1;
+ this->ClosePending = true;
+ this->state = I_ERROR;
+ this->OnError(I_ERR_NOMOREFDS);
+ }
socket_ref[this->fd] = this;
log(DEBUG,"New socket now in I_LISTENING state");
return;
@@ -263,7 +269,15 @@ bool InspSocket::DoConnect()
}
}
this->state = I_CONNECTING;
- 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->state = I_ERROR;
+ this->fd = -1;
+ this->ClosePending = true;
+ return false;
+ }
socket_ref[this->fd] = this;
this->SetQueues(this->fd);
log(DEBUG,"Returning true from InspSocket::DoConnect");
@@ -432,7 +446,8 @@ bool InspSocket::Poll()
* in read-state.
*/
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;
case I_LISTENING: