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
This commit is contained in:
Vadim Zeitlin
2007-07-14 19:41:46 +00:00
parent c11132ca80
commit af57c51ab7
7 changed files with 32 additions and 25 deletions

View File

@@ -52,10 +52,8 @@ public:
// modify descriptor flags or handler, return true on success // modify descriptor flags or handler, return true on success
virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags) = 0; virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags) = 0;
// unregister descriptor previously registered with RegisterFD(), the // unregister descriptor previously registered with RegisterFD()
// caller is responsible for deleting the returned handler pointer if virtual bool UnregisterFD(int fd) = 0;
// necessary
virtual bool UnregisterFD(int fd, int flags) = 0;
// loops waiting for an event to happen on any of the descriptors // loops waiting for an event to happen on any of the descriptors
virtual void RunLoop(int timeout) = 0; virtual void RunLoop(int timeout) = 0;
@@ -94,10 +92,12 @@ WX_DECLARE_HASH_MAP(
// //
// notice that all functions for FD management have implementation // notice that all functions for FD management have implementation
// in the base class and should be called from the derived classes // 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: public:
// find the handler for the given fd, return NULL if none // find the handler for the given fd, return NULL if none
wxFDIOHandler *FindHandler(int fd) const; wxFDIOHandler *FindHandler(int fd) const;
// register handler for the given descriptor with the dispatcher, return // register handler for the given descriptor with the dispatcher, return
// true on success or false on error // true on success or false on error
virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags); virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags);
@@ -105,10 +105,8 @@ public:
// modify descriptor flags or handler, return true on success // modify descriptor flags or handler, return true on success
virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags); virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags);
// unregister descriptor previously registered with RegisterFD(), the // unregister descriptor previously registered with RegisterFD()
// caller is responsible for deleting the returned handler pointer if virtual bool UnregisterFD(int fd);
// necessary
virtual bool UnregisterFD(int fd, int flags);
virtual ~wxMappedFDIODispatcher() { } virtual ~wxMappedFDIODispatcher() { }

View File

@@ -38,9 +38,9 @@ public:
// same as SetFD() except it unsets the bits set in the flags for the given // same as SetFD() except it unsets the bits set in the flags for the given
// fd // 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 // implement pure virtual methods of the base class
virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags = wxFDIO_ALL); virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags = wxFDIO_ALL);
virtual bool ModifyFD(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); virtual void RunLoop(int timeout = TIMEOUT_INFINITE);
protected: protected:

View File

@@ -29,7 +29,7 @@ public:
// implement base class pure virtual methods // implement base class pure virtual methods
virtual bool RegisterFD(int fd, wxFDIOHandler* handler, int flags = wxFDIO_ALL); virtual bool RegisterFD(int fd, wxFDIOHandler* handler, int flags = wxFDIO_ALL);
virtual bool ModifyFD(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); virtual void RunLoop(int timeout = TIMEOUT_INFINITE);
private: private:

View File

@@ -78,18 +78,13 @@ bool wxMappedFDIODispatcher::ModifyFD(int fd, wxFDIOHandler *handler, int flags)
return true; return true;
} }
bool wxMappedFDIODispatcher::UnregisterFD(int fd, int flags) bool wxMappedFDIODispatcher::UnregisterFD(int fd)
{ {
wxFDIOHandlerMap::iterator i = m_handlers.find(fd); wxFDIOHandlerMap::iterator i = m_handlers.find(fd);
if( i == m_handlers.end()) if ( i == m_handlers.end() )
return false; return false;
i->second.flags &= ~flags; m_handlers.erase(i);
if ( !i->second.flags )
{
// this handler is not registered for anything any more, get rid of it
m_handlers.erase(i);
}
return true; return true;
} }

View File

@@ -180,13 +180,24 @@ void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket,
return; return;
wxGSocketIOHandler * const wxGSocketIOHandler * const
handler = (wxGSocketIOHandler*)dispatcher->UnregisterFD(fd, flag); handler = wx_static_cast(wxGSocketIOHandler *, dispatcher->FindHandler(fd));
if ( handler ) if ( handler )
{ {
handler->RemoveFlag(flag); handler->RemoveFlag(flag);
if ( !handler->GetFlags() ) if ( !handler->GetFlags() )
{
dispatcher->UnregisterFD(fd);
delete handler; delete handler;
}
else
{
dispatcher->ModifyFD(fd, handler, handler->GetFlags());
}
}
else
{
dispatcher->UnregisterFD(fd);
} }
} }

View File

@@ -184,9 +184,12 @@ bool wxSelectDispatcher::ModifyFD(int fd, wxFDIOHandler *handler, int flags)
return m_sets.SetFD(fd, 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 // remove the handler if we don't need it any more
if ( !m_sets.HasFD(fd) ) if ( !m_sets.HasFD(fd) )

View File

@@ -120,7 +120,7 @@ bool wxEpollDispatcher::ModifyFD(int fd, wxFDIOHandler* handler, int flags)
return true; return true;
} }
bool wxEpollDispatcher::UnregisterFD(int fd, int flags) bool wxEpollDispatcher::UnregisterFD(int fd)
{ {
epoll_event ev; epoll_event ev;
ev.events = 0; ev.events = 0;