// 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;
//
// 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);
// 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() { }
// 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);
}
// 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:
// 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:
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;
}
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);
}
}
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) )
return true;
}
-bool wxEpollDispatcher::UnregisterFD(int fd, int flags)
+bool wxEpollDispatcher::UnregisterFD(int fd)
{
epoll_event ev;
ev.events = 0;