#if wxUSE_SELECT_DISPATCHER
#include "wx/private/selectdispatcher.h"
-#include "wx/module.h"
#include "wx/unix/private.h"
#ifndef WX_PRECOMP
#include "wx/intl.h"
#endif
-#ifdef HAVE_SYS_SELECT_H
+#if defined(HAVE_SYS_SELECT_H) || defined(__WATCOMC__)
+ #include <sys/time.h>
#include <sys/select.h>
#endif
if ( flags & ms_flags[n] )
{
wxFD_SET(fd, &m_fds[n]);
- wxLogTrace(wxSelectDispatcher_Trace,
- _T("Registered fd %d for %s events"), fd, ms_names[n]);
}
else if ( wxFD_ISSET(fd, (fd_set*) &m_fds[n]) )
{
wxFD_CLR(fd, &m_fds[n]);
- wxLogTrace(wxSelectDispatcher_Trace,
- _T("Unregistered fd %d from %s events"), fd, ms_names[n]);
}
}
wxLogTrace(wxSelectDispatcher_Trace,
_T("Got %s event on fd %d"), ms_names[n], fd);
(handler.*ms_handlers[n])();
+ // callback can modify sets and destroy handler
+ // this forces that one event can be processed at one time
+ return;
}
}
}
// wxSelectDispatcher
// ----------------------------------------------------------------------------
-static wxSelectDispatcher *gs_selectDispatcher = NULL;
-
-/* static */
-wxSelectDispatcher *wxSelectDispatcher::Get()
-{
- if ( !gs_selectDispatcher )
- {
- // the dispatcher should be only created from one thread so it should
- // be ok to use a global without any protection here
- gs_selectDispatcher = new wxSelectDispatcher;
- }
-
- return gs_selectDispatcher;
-}
-
-/* static */
-void wxSelectDispatcher::DispatchPending()
-{
- if ( gs_selectDispatcher )
- gs_selectDispatcher->Dispatch(0);
-}
-
-wxSelectDispatcher::wxSelectDispatcher()
-{
- m_maxFD = -1;
-}
-
bool wxSelectDispatcher::RegisterFD(int fd, wxFDIOHandler *handler, int flags)
{
if ( !wxMappedFDIODispatcher::RegisterFD(fd, handler, flags) )
if ( fd > m_maxFD )
m_maxFD = fd;
+ wxLogTrace(wxSelectDispatcher_Trace,
+ _T("Registered fd %d: input:%d, output:%d, exceptional:%d"), fd, (flags & wxFDIO_INPUT) == wxFDIO_INPUT, (flags & wxFDIO_OUTPUT), (flags & wxFDIO_EXCEPTION) == wxFDIO_EXCEPTION);
return true;
}
wxASSERT_MSG( fd <= m_maxFD, _T("logic error: registered fd > m_maxFD?") );
+ wxLogTrace(wxSelectDispatcher_Trace,
+ _T("Modified fd %d: input:%d, output:%d, exceptional:%d"), fd, (flags & wxFDIO_INPUT) == wxFDIO_INPUT, (flags & wxFDIO_OUTPUT) == wxFDIO_OUTPUT, (flags & wxFDIO_EXCEPTION) == wxFDIO_EXCEPTION);
return m_sets.SetFD(fd, flags);
}
++it )
{
if ( it->first > m_maxFD )
+ {
m_maxFD = it->first;
+ }
}
}
}
+ wxLogTrace(wxSelectDispatcher_Trace,
+ _T("Removed fd %d, current max: %d"), fd, m_maxFD);
return true;
}
}
}
-// ----------------------------------------------------------------------------
-// wxSelectDispatcherModule
-// ----------------------------------------------------------------------------
-
-class wxSelectDispatcherModule : public wxModule
-{
-public:
- virtual bool OnInit() { return true; }
- virtual void OnExit() { wxDELETE(gs_selectDispatcher); }
-
-private:
- DECLARE_DYNAMIC_CLASS(wxSelectDispatcherModule)
-};
-
-IMPLEMENT_DYNAMIC_CLASS(wxSelectDispatcherModule, wxModule)
-
#endif // wxUSE_SELECT_DISPATCHER