From 7523de907dd77eedd33431d5ff46478a467faf5f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 14 Jul 2007 19:50:38 +0000 Subject: [PATCH] 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 --- include/wx/private/fdiodispatcher.h | 4 +- include/wx/private/selectdispatcher.h | 2 +- include/wx/unix/private/epolldispatcher.h | 2 +- src/common/selectdispatcher.cpp | 57 +++++++++-------------- src/unix/epolldispatcher.cpp | 8 ++-- 5 files changed, 28 insertions(+), 45 deletions(-) diff --git a/include/wx/private/fdiodispatcher.h b/include/wx/private/fdiodispatcher.h index 40e9982e23..52e8efba7b 100644 --- a/include/wx/private/fdiodispatcher.h +++ b/include/wx/private/fdiodispatcher.h @@ -55,8 +55,8 @@ public: // 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() { } }; diff --git a/include/wx/private/selectdispatcher.h b/include/wx/private/selectdispatcher.h index fac5f22844..d61f0daf77 100644 --- a/include/wx/private/selectdispatcher.h +++ b/include/wx/private/selectdispatcher.h @@ -89,7 +89,7 @@ public: 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(); diff --git a/include/wx/unix/private/epolldispatcher.h b/include/wx/unix/private/epolldispatcher.h index 735ab6d72c..c42b40f0a4 100644 --- a/include/wx/unix/private/epolldispatcher.h +++ b/include/wx/unix/private/epolldispatcher.h @@ -30,7 +30,7 @@ public: 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() diff --git a/src/common/selectdispatcher.cpp b/src/common/selectdispatcher.cpp index 02c95710b7..654eee9f4a 100644 --- a/src/common/selectdispatcher.cpp +++ b/src/common/selectdispatcher.cpp @@ -23,7 +23,6 @@ #include "wx/private/selectdispatcher.h" #include "wx/module.h" -#include "wx/timer.h" #include "wx/unix/private.h" #ifndef WX_PRECOMP @@ -152,7 +151,7 @@ wxSelectDispatcher *wxSelectDispatcher::Get() void wxSelectDispatcher::DispatchPending() { if ( gs_selectDispatcher ) - gs_selectDispatcher->RunLoop(0); + gs_selectDispatcher->Dispatch(0); } wxSelectDispatcher::wxSelectDispatcher() @@ -229,53 +228,39 @@ void wxSelectDispatcher::ProcessSets(const wxSelectSets& sets) } } -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); } } diff --git a/src/unix/epolldispatcher.cpp b/src/unix/epolldispatcher.cpp index 9f8505cae7..16ec914ad6 100644 --- a/src/unix/epolldispatcher.cpp +++ b/src/unix/epolldispatcher.cpp @@ -135,7 +135,7 @@ bool wxEpollDispatcher::UnregisterFD(int fd) return true; } -void wxEpollDispatcher::RunLoop(int timeout) +void wxEpollDispatcher::Dispatch(int timeout) { epoll_event events[16]; @@ -168,11 +168,9 @@ void wxEpollDispatcher::RunLoop(int timeout) 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(); } } -- 2.45.2