From: Vadim Zeitlin Date: Sat, 14 Jul 2007 19:41:46 +0000 (+0000) Subject: changed wxFDIODispatcher::UnregisterFD() to take only fd, without flags, and unregist... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/af57c51ab758ad9810ea5bbb3703341cd5f367b1?ds=inline changed wxFDIODispatcher::UnregisterFD() to take only fd, without flags, and unregister it unconditionally; use ModifyFD() to just change the flags (modified part of patch 1733626) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47469 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/private/fdiodispatcher.h b/include/wx/private/fdiodispatcher.h index 0f71d94fd6..40e9982e23 100644 --- a/include/wx/private/fdiodispatcher.h +++ b/include/wx/private/fdiodispatcher.h @@ -52,10 +52,8 @@ public: // modify descriptor flags or handler, return true on success virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags) = 0; - // unregister descriptor previously registered with RegisterFD(), the - // caller is responsible for deleting the returned handler pointer if - // necessary - virtual bool UnregisterFD(int fd, int flags) = 0; + // unregister descriptor previously registered with RegisterFD() + virtual bool UnregisterFD(int fd) = 0; // loops waiting for an event to happen on any of the descriptors virtual void RunLoop(int timeout) = 0; @@ -94,10 +92,12 @@ WX_DECLARE_HASH_MAP( // // notice that all functions for FD management have implementation // in the base class and should be called from the derived classes -class WXDLLIMPEXP_BASE wxMappedFDIODispatcher : public wxFDIODispatcher { +class WXDLLIMPEXP_BASE wxMappedFDIODispatcher : public wxFDIODispatcher +{ public: // find the handler for the given fd, return NULL if none wxFDIOHandler *FindHandler(int fd) const; + // register handler for the given descriptor with the dispatcher, return // true on success or false on error virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags); @@ -105,10 +105,8 @@ public: // modify descriptor flags or handler, return true on success virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags); - // unregister descriptor previously registered with RegisterFD(), the - // caller is responsible for deleting the returned handler pointer if - // necessary - virtual bool UnregisterFD(int fd, int flags); + // unregister descriptor previously registered with RegisterFD() + virtual bool UnregisterFD(int fd); virtual ~wxMappedFDIODispatcher() { } diff --git a/include/wx/private/selectdispatcher.h b/include/wx/private/selectdispatcher.h index 130f85bd3f..fac5f22844 100644 --- a/include/wx/private/selectdispatcher.h +++ b/include/wx/private/selectdispatcher.h @@ -38,9 +38,9 @@ public: // same as SetFD() except it unsets the bits set in the flags for the given // fd - bool ClearFD(int fd, int flags) + bool ClearFD(int fd) { - return SetFD(fd, wxFDIO_ALL & ~flags); + return SetFD(fd, 0); } @@ -88,7 +88,7 @@ public: // implement pure virtual methods of the base class virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags = wxFDIO_ALL); virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags = wxFDIO_ALL); - virtual bool UnregisterFD(int fd, int flags = wxFDIO_ALL); + virtual bool UnregisterFD(int fd); virtual void RunLoop(int timeout = TIMEOUT_INFINITE); protected: diff --git a/include/wx/unix/private/epolldispatcher.h b/include/wx/unix/private/epolldispatcher.h index c4b5074472..735ab6d72c 100644 --- a/include/wx/unix/private/epolldispatcher.h +++ b/include/wx/unix/private/epolldispatcher.h @@ -29,7 +29,7 @@ public: // implement base class pure virtual methods virtual bool RegisterFD(int fd, wxFDIOHandler* handler, int flags = wxFDIO_ALL); virtual bool ModifyFD(int fd, wxFDIOHandler* handler, int flags = wxFDIO_ALL); - virtual bool UnregisterFD(int fd, int flags = wxFDIO_ALL); + virtual bool UnregisterFD(int fd); virtual void RunLoop(int timeout = TIMEOUT_INFINITE); private: diff --git a/src/common/fdiodispatcher.cpp b/src/common/fdiodispatcher.cpp index f2e54e3036..112f892dc2 100644 --- a/src/common/fdiodispatcher.cpp +++ b/src/common/fdiodispatcher.cpp @@ -78,18 +78,13 @@ bool wxMappedFDIODispatcher::ModifyFD(int fd, wxFDIOHandler *handler, int flags) return true; } -bool wxMappedFDIODispatcher::UnregisterFD(int fd, int flags) +bool wxMappedFDIODispatcher::UnregisterFD(int fd) { wxFDIOHandlerMap::iterator i = m_handlers.find(fd); - if( i == m_handlers.end()) + if ( i == m_handlers.end() ) return false; - i->second.flags &= ~flags; - if ( !i->second.flags ) - { - // this handler is not registered for anything any more, get rid of it - m_handlers.erase(i); - } + m_handlers.erase(i); return true; } diff --git a/src/common/gsocketiohandler.cpp b/src/common/gsocketiohandler.cpp index e8e6dfcd62..a5ae3e476d 100644 --- a/src/common/gsocketiohandler.cpp +++ b/src/common/gsocketiohandler.cpp @@ -180,13 +180,24 @@ void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, return; wxGSocketIOHandler * const - handler = (wxGSocketIOHandler*)dispatcher->UnregisterFD(fd, flag); + handler = wx_static_cast(wxGSocketIOHandler *, dispatcher->FindHandler(fd)); if ( handler ) { handler->RemoveFlag(flag); if ( !handler->GetFlags() ) + { + dispatcher->UnregisterFD(fd); delete handler; + } + else + { + dispatcher->ModifyFD(fd, handler, handler->GetFlags()); + } + } + else + { + dispatcher->UnregisterFD(fd); } } diff --git a/src/common/selectdispatcher.cpp b/src/common/selectdispatcher.cpp index ef8b95179c..02c95710b7 100644 --- a/src/common/selectdispatcher.cpp +++ b/src/common/selectdispatcher.cpp @@ -184,9 +184,12 @@ bool wxSelectDispatcher::ModifyFD(int fd, wxFDIOHandler *handler, int flags) return m_sets.SetFD(fd, flags); } -bool wxSelectDispatcher::UnregisterFD(int fd, int flags) +bool wxSelectDispatcher::UnregisterFD(int fd) { - m_sets.ClearFD(fd, flags); + m_sets.ClearFD(fd); + + if ( !wxMappedFDIODispatcher::UnregisterFD(fd) ) + return false; // remove the handler if we don't need it any more if ( !m_sets.HasFD(fd) ) diff --git a/src/unix/epolldispatcher.cpp b/src/unix/epolldispatcher.cpp index 382cd5473c..9f8505cae7 100644 --- a/src/unix/epolldispatcher.cpp +++ b/src/unix/epolldispatcher.cpp @@ -120,7 +120,7 @@ bool wxEpollDispatcher::ModifyFD(int fd, wxFDIOHandler* handler, int flags) return true; } -bool wxEpollDispatcher::UnregisterFD(int fd, int flags) +bool wxEpollDispatcher::UnregisterFD(int fd) { epoll_event ev; ev.events = 0;