replaced wxFDIODispatcher::RunLoop() with Dispatch() which handles only one event at a time (part 1 of the patch 1733626)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47470 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-07-14 19:50:38 +00:00
parent af57c51ab7
commit 7523de907d
5 changed files with 28 additions and 45 deletions

View File

@@ -55,8 +55,8 @@ public:
// unregister descriptor previously registered with RegisterFD() // unregister descriptor previously registered with RegisterFD()
virtual bool UnregisterFD(int fd) = 0; virtual bool UnregisterFD(int fd) = 0;
// loops waiting for an event to happen on any of the descriptors // wait for an event for at most timeout milliseconds and process it
virtual void RunLoop(int timeout) = 0; virtual void Dispatch(int timeout = TIMEOUT_INFINITE) = 0;
virtual ~wxFDIODispatcher() { } virtual ~wxFDIODispatcher() { }
}; };

View File

@@ -89,7 +89,7 @@ public:
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); virtual bool UnregisterFD(int fd);
virtual void RunLoop(int timeout = TIMEOUT_INFINITE); virtual void Dispatch(int timeout = TIMEOUT_INFINITE);
protected: protected:
wxSelectDispatcher(); wxSelectDispatcher();

View File

@@ -30,7 +30,7 @@ public:
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); virtual bool UnregisterFD(int fd);
virtual void RunLoop(int timeout = TIMEOUT_INFINITE); virtual void Dispatch(int timeout = TIMEOUT_INFINITE);
private: private:
// ctor is private, use Get() // ctor is private, use Get()

View File

@@ -23,7 +23,6 @@
#include "wx/private/selectdispatcher.h" #include "wx/private/selectdispatcher.h"
#include "wx/module.h" #include "wx/module.h"
#include "wx/timer.h"
#include "wx/unix/private.h" #include "wx/unix/private.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
@@ -152,7 +151,7 @@ wxSelectDispatcher *wxSelectDispatcher::Get()
void wxSelectDispatcher::DispatchPending() void wxSelectDispatcher::DispatchPending()
{ {
if ( gs_selectDispatcher ) if ( gs_selectDispatcher )
gs_selectDispatcher->RunLoop(0); gs_selectDispatcher->Dispatch(0);
} }
wxSelectDispatcher::wxSelectDispatcher() wxSelectDispatcher::wxSelectDispatcher()
@@ -229,54 +228,40 @@ void wxSelectDispatcher::ProcessSets(const wxSelectSets& sets)
} }
} }
void wxSelectDispatcher::RunLoop(int timeout) void wxSelectDispatcher::Dispatch(int timeout)
{ {
struct timeval tv, struct timeval tv,
*ptv = NULL; *ptv;
if ( timeout != TIMEOUT_INFINITE ) if ( timeout != TIMEOUT_INFINITE )
{ {
ptv = &tv; ptv = &tv;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = timeout*1000; tv.tv_usec = timeout*1000;
} }
else // no timeout
for ( ;; )
{ {
wxSelectSets sets = m_sets; ptv = NULL;
}
wxStopWatch sw; wxSelectSets sets = m_sets;
if ( ptv && timeout )
sw.Start(ptv->tv_usec/10);
const int ret = sets.Select(m_maxFD + 1, ptv); const int ret = sets.Select(m_maxFD + 1, ptv);
switch ( ret ) switch ( ret )
{ {
case -1: case -1:
// continue if we were interrupted by a signal, else bail out
if ( errno != EINTR ) if ( errno != EINTR )
{ {
wxLogSysError(_("Failed to monitor I/O channels")); wxLogSysError(_("Failed to monitor I/O channels"));
return;
} }
break; break;
case 0: case 0:
// timeout expired without anything happening // timeout expired without anything happening
return; break;
default: default:
ProcessSets(sets); ProcessSets(sets);
} }
if ( ptv )
{
timeout -= sw.Time();
if ( timeout <= 0 )
break;
ptv->tv_usec = timeout*1000;
}
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -135,7 +135,7 @@ bool wxEpollDispatcher::UnregisterFD(int fd)
return true; return true;
} }
void wxEpollDispatcher::RunLoop(int timeout) void wxEpollDispatcher::Dispatch(int timeout)
{ {
epoll_event events[16]; epoll_event events[16];
@@ -168,11 +168,9 @@ void wxEpollDispatcher::RunLoop(int timeout)
if ( p->events & EPOLLIN ) if ( p->events & EPOLLIN )
handler->OnReadWaiting(); handler->OnReadWaiting();
else if ( p->events & EPOLLOUT )
if ( p->events & EPOLLOUT )
handler->OnWriteWaiting(); handler->OnWriteWaiting();
else if ( p->events & (EPOLLERR | EPOLLHUP) )
if ( p->events & (EPOLLERR | EPOLLHUP) )
handler->OnExceptionWaiting(); handler->OnExceptionWaiting();
} }
} }