// 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;
+ // wait for an event for at most timeout milliseconds and process it
+ virtual void Dispatch(int timeout = TIMEOUT_INFINITE) = 0;
virtual ~wxFDIODispatcher() { }
};
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);
- virtual void RunLoop(int timeout = TIMEOUT_INFINITE);
+ virtual void Dispatch(int timeout = TIMEOUT_INFINITE);
protected:
wxSelectDispatcher();
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);
- virtual void RunLoop(int timeout = TIMEOUT_INFINITE);
+ virtual void Dispatch(int timeout = TIMEOUT_INFINITE);
private:
// ctor is private, use Get()
#include "wx/private/selectdispatcher.h"
#include "wx/module.h"
-#include "wx/timer.h"
#include "wx/unix/private.h"
#ifndef WX_PRECOMP
void wxSelectDispatcher::DispatchPending()
{
if ( gs_selectDispatcher )
- gs_selectDispatcher->RunLoop(0);
+ gs_selectDispatcher->Dispatch(0);
}
wxSelectDispatcher::wxSelectDispatcher()
}
}
-void wxSelectDispatcher::RunLoop(int timeout)
+void wxSelectDispatcher::Dispatch(int timeout)
{
struct timeval tv,
- *ptv = NULL;
+ *ptv;
if ( timeout != TIMEOUT_INFINITE )
{
ptv = &tv;
tv.tv_sec = 0;
tv.tv_usec = timeout*1000;
}
-
- for ( ;; )
+ else // no timeout
{
- wxSelectSets sets = m_sets;
+ ptv = NULL;
+ }
- wxStopWatch sw;
- if ( ptv && timeout )
- sw.Start(ptv->tv_usec/10);
+ wxSelectSets sets = m_sets;
- const int ret = sets.Select(m_maxFD + 1, ptv);
- switch ( ret )
- {
- case -1:
- // continue if we were interrupted by a signal, else bail out
- if ( errno != EINTR )
- {
- wxLogSysError(_("Failed to monitor I/O channels"));
- return;
- }
- break;
-
- case 0:
- // timeout expired without anything happening
- return;
-
- default:
- ProcessSets(sets);
- }
+ const int ret = sets.Select(m_maxFD + 1, ptv);
+ switch ( ret )
+ {
+ case -1:
+ if ( errno != EINTR )
+ {
+ wxLogSysError(_("Failed to monitor I/O channels"));
+ }
+ break;
- if ( ptv )
- {
- timeout -= sw.Time();
- if ( timeout <= 0 )
- break;
+ case 0:
+ // timeout expired without anything happening
+ break;
- ptv->tv_usec = timeout*1000;
- }
+ default:
+ ProcessSets(sets);
}
}
return true;
}
-void wxEpollDispatcher::RunLoop(int timeout)
+void wxEpollDispatcher::Dispatch(int timeout)
{
epoll_event events[16];
if ( p->events & EPOLLIN )
handler->OnReadWaiting();
-
- if ( p->events & EPOLLOUT )
+ else if ( p->events & EPOLLOUT )
handler->OnWriteWaiting();
-
- if ( p->events & (EPOLLERR | EPOLLHUP) )
+ else if ( p->events & (EPOLLERR | EPOLLHUP) )
handler->OnExceptionWaiting();
}
}