From a018f26eddbc72fdbf87fe5ee89112a53311fff1 Mon Sep 17 00:00:00 2001 From: danieldg Date: Tue, 2 Mar 2010 03:17:04 +0000 Subject: DelFd should not fail, it will leave a bad dangling pointer in that case git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12584 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/socketengines/socketengine_epoll.cpp | 12 +++++------- src/socketengines/socketengine_kqueue.cpp | 10 ++++------ src/socketengines/socketengine_poll.cpp | 9 ++++----- src/socketengines/socketengine_ports.cpp | 6 +++--- src/socketengines/socketengine_select.cpp | 7 +++---- 5 files changed, 19 insertions(+), 25 deletions(-) (limited to 'src/socketengines') diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp index 4176c3b3a..8a5800208 100644 --- a/src/socketengines/socketengine_epoll.cpp +++ b/src/socketengines/socketengine_epoll.cpp @@ -39,7 +39,7 @@ public: virtual ~EPollEngine(); virtual bool AddFd(EventHandler* eh, int event_mask); virtual void OnSetEvent(EventHandler* eh, int old_mask, int new_mask); - virtual bool DelFd(EventHandler* eh, bool force = false); + virtual void DelFd(EventHandler* eh); virtual int DispatchEvents(); virtual std::string GetName(); }; @@ -155,13 +155,13 @@ void EPollEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) } } -bool EPollEngine::DelFd(EventHandler* eh, bool force) +void EPollEngine::DelFd(EventHandler* eh) { int fd = eh->GetFd(); if ((fd < 0) || (fd > GetMaxFds() - 1)) { ServerInstance->Logs->Log("SOCKET",DEBUG,"DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds()); - return false; + return; } struct epoll_event ev; @@ -169,17 +169,15 @@ bool EPollEngine::DelFd(EventHandler* eh, bool force) ev.data.fd = fd; int i = epoll_ctl(EngineHandle, EPOLL_CTL_DEL, fd, &ev); - if (i < 0 && !force) + if (i < 0) { - ServerInstance->Logs->Log("SOCKET",DEBUG,"Cant remove socket: %s", strerror(errno)); - return false; + ServerInstance->Logs->Log("SOCKET",DEBUG,"epoll_ctl can't remove socket: %s", strerror(errno)); } ref[fd] = NULL; ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd); CurrentSetSize--; - return true; } int EPollEngine::DispatchEvents() diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp index 6f329357d..92dae312d 100644 --- a/src/socketengines/socketengine_kqueue.cpp +++ b/src/socketengines/socketengine_kqueue.cpp @@ -39,7 +39,7 @@ public: virtual ~KQueueEngine(); bool AddFd(EventHandler* eh, int event_mask); void OnSetEvent(EventHandler* eh, int old_mask, int new_mask); - virtual bool DelFd(EventHandler* eh, bool force = false); + virtual bool DelFd(EventHandler* eh); virtual int DispatchEvents(); virtual std::string GetName(); virtual void RecoverFromFork(); @@ -127,14 +127,14 @@ bool KQueueEngine::AddFd(EventHandler* eh, int event_mask) return true; } -bool KQueueEngine::DelFd(EventHandler* eh, bool force) +void KQueueEngine::DelFd(EventHandler* eh) { int fd = eh->GetFd(); if ((fd < 0) || (fd > GetMaxFds() - 1)) { ServerInstance->Logs->Log("SOCKET",DEFAULT,"DelFd() on invalid fd: %d", fd); - return false; + return; } struct kevent ke; @@ -148,18 +148,16 @@ bool KQueueEngine::DelFd(EventHandler* eh, bool force) EV_SET(&ke, eh->GetFd(), EVFILT_READ, EV_DELETE, 0, 0, NULL); int j = kevent(EngineHandle, &ke, 1, 0, 0, NULL); - if ((j < 0) && !force) + if (j < 0) { ServerInstance->Logs->Log("SOCKET",DEFAULT,"Failed to remove fd: %d %s", fd, strerror(errno)); - return false; } CurrentSetSize--; ref[fd] = NULL; ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd); - return true; } void KQueueEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp index a1e0b815a..d20ac35a2 100644 --- a/src/socketengines/socketengine_poll.cpp +++ b/src/socketengines/socketengine_poll.cpp @@ -59,7 +59,7 @@ public: virtual bool AddFd(EventHandler* eh, int event_mask); virtual void OnSetEvent(EventHandler* eh, int old_mask, int new_mask); virtual EventHandler* GetRef(int fd); - virtual bool DelFd(EventHandler* eh, bool force = false); + virtual void DelFd(EventHandler* eh); virtual int DispatchEvents(); virtual std::string GetName(); }; @@ -168,20 +168,20 @@ void PollEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) events[it->second].events = mask_to_poll(new_mask); } -bool PollEngine::DelFd(EventHandler* eh, bool force) +void PollEngine::DelFd(EventHandler* eh) { int fd = eh->GetFd(); if ((fd < 0) || (fd > MAX_DESCRIPTORS)) { ServerInstance->Logs->Log("SOCKET", DEBUG, "DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds()); - return false; + return; } std::map::iterator it = fd_mappings.find(fd); if (it == fd_mappings.end()) { ServerInstance->Logs->Log("SOCKET",DEBUG,"DelFd() on unknown fd: %d", fd); - return false; + return; } unsigned int index = it->second; @@ -213,7 +213,6 @@ bool PollEngine::DelFd(EventHandler* eh, bool force) ServerInstance->Logs->Log("SOCKET", DEBUG, "Remove file descriptor: %d (index: %d) " "(Filled gap with: %d (index: %d))", fd, index, last_fd, last_index); - return true; } int PollEngine::DispatchEvents() diff --git a/src/socketengines/socketengine_ports.cpp b/src/socketengines/socketengine_ports.cpp index 5642a7223..e5523acb6 100644 --- a/src/socketengines/socketengine_ports.cpp +++ b/src/socketengines/socketengine_ports.cpp @@ -48,7 +48,7 @@ public: virtual ~PortsEngine(); virtual bool AddFd(EventHandler* eh, int event_mask); void OnSetEvent(EventHandler* eh, int old_event, int new_event); - virtual bool DelFd(EventHandler* eh, bool force = false); + virtual void DelFd(EventHandler* eh); virtual int DispatchEvents(); virtual std::string GetName(); virtual void WantWrite(EventHandler* eh); @@ -131,11 +131,11 @@ void PortsEngine::WantWrite(EventHandler* eh, int old_mask, int new_mask) port_associate(EngineHandle, PORT_SOURCE_FD, eh->GetFd(), mask_to_events(new_mask), eh); } -bool PortsEngine::DelFd(EventHandler* eh, bool force) +void PortsEngine::DelFd(EventHandler* eh) { int fd = eh->GetFd(); if ((fd < 0) || (fd > GetMaxFds() - 1)) - return false; + return; port_dissociate(EngineHandle, PORT_SOURCE_FD, fd); diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp index 3c33eb474..acc8f8f09 100644 --- a/src/socketengines/socketengine_select.cpp +++ b/src/socketengines/socketengine_select.cpp @@ -32,7 +32,7 @@ public: */ virtual ~SelectEngine(); virtual bool AddFd(EventHandler* eh, int event_mask); - virtual bool DelFd(EventHandler* eh, bool force = false); + virtual void DelFd(EventHandler* eh); void OnSetEvent(EventHandler* eh, int, int); virtual int DispatchEvents(); virtual std::string GetName(); @@ -69,18 +69,17 @@ bool SelectEngine::AddFd(EventHandler* eh, int event_mask) return true; } -bool SelectEngine::DelFd(EventHandler* eh, bool force) +void SelectEngine::DelFd(EventHandler* eh) { int fd = eh->GetFd(); if ((fd < 0) || (fd > GetMaxFds() - 1)) - return false; + return; CurrentSetSize--; ref[fd] = NULL; ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd); - return true; } void SelectEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) -- cgit v1.2.3