summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-09-25 00:29:02 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-09-25 00:29:02 +0000
commitfd5f65b6f5c1848c7922c3820a90f6020abbabb1 (patch)
tree58146a91f73a175b884bad95ca2942d397012206 /src
parentedf061fc6a7259f84a4e3be6f43c9e0601b3b39d (diff)
Fix for bug #407, set ref[fd] AFTER some checks that may return false and leave the socket engine in an undefined state
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8077 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/socketengine_epoll.cpp3
-rw-r--r--src/socketengine_iocp.cpp8
-rw-r--r--src/socketengine_kqueue.cpp5
-rw-r--r--src/socketengine_select.cpp1
4 files changed, 9 insertions, 8 deletions
diff --git a/src/socketengine_epoll.cpp b/src/socketengine_epoll.cpp
index 381701093..97efec127 100644
--- a/src/socketengine_epoll.cpp
+++ b/src/socketengine_epoll.cpp
@@ -48,7 +48,6 @@ bool EPollEngine::AddFd(EventHandler* eh)
if (ref[fd])
return false;
- ref[fd] = eh;
struct epoll_event ev;
memset(&ev,0,sizeof(struct epoll_event));
eh->Readable() ? ev.events = EPOLLIN : ev.events = EPOLLOUT;
@@ -60,6 +59,8 @@ bool EPollEngine::AddFd(EventHandler* eh)
}
ServerInstance->Log(DEBUG,"New file descriptor: %d", fd);
+
+ ref[fd] = eh;
CurrentSetSize++;
return true;
}
diff --git a/src/socketengine_iocp.cpp b/src/socketengine_iocp.cpp
index d66ca2ac4..96ff9eb31 100644
--- a/src/socketengine_iocp.cpp
+++ b/src/socketengine_iocp.cpp
@@ -74,10 +74,6 @@ bool IOCPEngine::AddFd(EventHandler* eh)
if (!CreateIoCompletionPort((HANDLE)eh->GetFd(), m_completionPort, completion_key, 0))
return false;
- /* set up binding, increase set size */
- ref[*fake_fd] = eh;
- ++CurrentSetSize;
-
/* setup initial events */
if(is_accept)
PostAcceptEvent(eh);
@@ -101,6 +97,10 @@ bool IOCPEngine::AddFd(EventHandler* eh)
/* Ohshi-, map::insert failed :/ */
return false;
}
+
+ ++CurrentSetSize;
+ ref[*fake_fd] = eh;
+
return true;
}
diff --git a/src/socketengine_kqueue.cpp b/src/socketengine_kqueue.cpp
index e33f9f772..50f6242e2 100644
--- a/src/socketengine_kqueue.cpp
+++ b/src/socketengine_kqueue.cpp
@@ -61,15 +61,16 @@ bool KQueueEngine::AddFd(EventHandler* eh)
if (ref[fd])
return false;
- ref[fd] = eh;
-
struct kevent ke;
EV_SET(&ke, fd, eh->Readable() ? EVFILT_READ : EVFILT_WRITE, EV_ADD, 0, 0, NULL);
int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
if (i == -1)
+ {
return false;
+ }
+ ref[fd] = eh;
CurrentSetSize++;
ServerInstance->Log(DEBUG,"New file descriptor: %d", fd);
diff --git a/src/socketengine_select.cpp b/src/socketengine_select.cpp
index b87d2769d..c70e609b5 100644
--- a/src/socketengine_select.cpp
+++ b/src/socketengine_select.cpp
@@ -42,7 +42,6 @@ bool SelectEngine::AddFd(EventHandler* eh)
return false;
ref[fd] = eh;
-
CurrentSetSize++;
ServerInstance->Log(DEBUG,"New file descriptor: %d", fd);