From: Vadim Zeitlin Date: Thu, 16 Oct 2008 12:31:30 +0000 (+0000) Subject: made Dispatch() return bool indicating whether we processed any events inside it... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5a557d1ea0c466ea01d8d934d3de8800a625b86a?ds=sidebyside made Dispatch() return bool indicating whether we processed any events inside it or if the timeout expired git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56355 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/private/fdiodispatcher.h b/include/wx/private/fdiodispatcher.h index 04128f858b..e7f367c1ff 100644 --- a/include/wx/private/fdiodispatcher.h +++ b/include/wx/private/fdiodispatcher.h @@ -67,8 +67,10 @@ public: // unregister descriptor previously registered with RegisterFD() virtual bool UnregisterFD(int fd) = 0; - // wait for an event for at most timeout milliseconds and process it - virtual void Dispatch(int timeout = TIMEOUT_INFINITE) = 0; + // wait for an event for at most timeout milliseconds and process it; + // return true if we processed any events or false if timeout expired + // without anything happening + virtual bool Dispatch(int timeout = TIMEOUT_INFINITE) = 0; virtual ~wxFDIODispatcher() { } }; diff --git a/include/wx/private/selectdispatcher.h b/include/wx/private/selectdispatcher.h index 5eed47c55c..a704b8a83c 100644 --- a/include/wx/private/selectdispatcher.h +++ b/include/wx/private/selectdispatcher.h @@ -91,14 +91,15 @@ 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 Dispatch(int timeout = TIMEOUT_INFINITE); + virtual bool Dispatch(int timeout = TIMEOUT_INFINITE); private: // common part of RegisterFD() and ModifyFD() bool DoUpdateFDAndHandler(int fd, wxFDIOHandler *handler, int flags); - // call the handlers for the fds present in the given sets - void ProcessSets(const wxSelectSets& sets); + // call the handlers for the fds present in the given sets, return true if + // we called any handlers + bool ProcessSets(const wxSelectSets& sets); // helper of ProcessSets(): call the handler if its fd is in the set void DoProcessFD(int fd, const fd_set& fds, wxFDIOHandler *handler, diff --git a/src/common/selectdispatcher.cpp b/src/common/selectdispatcher.cpp index ffcf387179..990b62c21c 100644 --- a/src/common/selectdispatcher.cpp +++ b/src/common/selectdispatcher.cpp @@ -190,8 +190,9 @@ bool wxSelectDispatcher::UnregisterFD(int fd) return true; } -void wxSelectDispatcher::ProcessSets(const wxSelectSets& sets) +bool wxSelectDispatcher::ProcessSets(const wxSelectSets& sets) { + bool gotEvent = false; for ( int fd = 0; fd <= m_maxFD; fd++ ) { if ( !sets.HasFD(fd) ) @@ -204,11 +205,15 @@ void wxSelectDispatcher::ProcessSets(const wxSelectSets& sets) continue; } + gotEvent = true; + sets.Handle(fd, *handler); } + + return gotEvent; } -void wxSelectDispatcher::Dispatch(int timeout) +bool wxSelectDispatcher::Dispatch(int timeout) { struct timeval tv, *ptv; @@ -240,8 +245,12 @@ void wxSelectDispatcher::Dispatch(int timeout) break; default: - ProcessSets(sets); + if ( ProcessSets(sets) ) + return true; } + + // nothing happened + return false; } #endif // wxUSE_SELECT_DISPATCHER diff --git a/src/unix/epolldispatcher.cpp b/src/unix/epolldispatcher.cpp index 7cc46b39b0..f509c7be25 100644 --- a/src/unix/epolldispatcher.cpp +++ b/src/unix/epolldispatcher.cpp @@ -158,7 +158,7 @@ bool wxEpollDispatcher::UnregisterFD(int fd) return true; } -void wxEpollDispatcher::Dispatch(int timeout) +bool wxEpollDispatcher::Dispatch(int timeout) { epoll_event events[16]; @@ -176,10 +176,11 @@ void wxEpollDispatcher::Dispatch(int timeout) { wxLogSysError(_("Waiting for IO on epoll descriptor %d failed"), m_epollDescriptor); - return; + return false; } } + bool gotEvents = false; for ( epoll_event *p = events; p < events + e_num; p++ ) { wxFDIOHandler * const handler = (wxFDIOHandler *)(p->data.ptr); @@ -199,7 +200,13 @@ void wxEpollDispatcher::Dispatch(int timeout) handler->OnWriteWaiting(); else if ( p->events & EPOLLERR ) handler->OnExceptionWaiting(); + else + continue; + + gotEvents = true; } + + return gotEvents; } #endif // wxUSE_EPOLL_DISPATCHER