From fd5f65b6f5c1848c7922c3820a90f6020abbabb1 Mon Sep 17 00:00:00 2001 From: brain Date: Tue, 25 Sep 2007 00:29:02 +0000 Subject: 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 --- src/socketengine_epoll.cpp | 3 ++- src/socketengine_iocp.cpp | 8 ++++---- src/socketengine_kqueue.cpp | 5 +++-- src/socketengine_select.cpp | 1 - 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') 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); -- cgit v1.2.3