projects
/
wxWidgets.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cleanup
[wxWidgets.git]
/
src
/
common
/
selectdispatcher.cpp
diff --git
a/src/common/selectdispatcher.cpp
b/src/common/selectdispatcher.cpp
index 138fa3cc8c5721a8f6b6dd68f8bd18de1858d1e7..dca9adec8577978f6f953651a5ad042099649f75 100644
(file)
--- a/
src/common/selectdispatcher.cpp
+++ b/
src/common/selectdispatcher.cpp
@@
-19,6
+19,10
@@
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
#if wxUSE_SELECT_DISPATCHER
#include "wx/private/selectdispatcher.h"
#if wxUSE_SELECT_DISPATCHER
#include "wx/private/selectdispatcher.h"
@@
-30,10
+34,6
@@
#include "wx/intl.h"
#endif
#include "wx/intl.h"
#endif
-#ifdef HAVE_SYS_SELECT_H
- #include <sys/select.h>
-#endif
-
#include <errno.h>
#define wxSelectDispatcher_Trace wxT("selectdispatcher")
#include <errno.h>
#define wxSelectDispatcher_Trace wxT("selectdispatcher")
@@
-88,7
+88,7
@@
bool wxSelectSets::HasFD(int fd) const
bool wxSelectSets::SetFD(int fd, int flags)
{
bool wxSelectSets::SetFD(int fd, int flags)
{
- wxCHECK_MSG( fd >= 0, false,
_
T("invalid descriptor") );
+ wxCHECK_MSG( fd >= 0, false,
wx
T("invalid descriptor") );
for ( int n = 0; n < Max; n++ )
{
for ( int n = 0; n < Max; n++ )
{
@@
-110,37
+110,28
@@
int wxSelectSets::Select(int nfds, struct timeval *tv)
return select(nfds, &m_fds[Read], &m_fds[Write], &m_fds[Except], tv);
}
return select(nfds, &m_fds[Read], &m_fds[Write], &m_fds[Except], tv);
}
-
void
wxSelectSets::Handle(int fd, wxFDIOHandler& handler) const
+
bool
wxSelectSets::Handle(int fd, wxFDIOHandler& handler) const
{
for ( int n = 0; n < Max; n++ )
{
if ( wxFD_ISSET(fd, (fd_set*) &m_fds[n]) )
{
wxLogTrace(wxSelectDispatcher_Trace,
{
for ( int n = 0; n < Max; n++ )
{
if ( wxFD_ISSET(fd, (fd_set*) &m_fds[n]) )
{
wxLogTrace(wxSelectDispatcher_Trace,
-
_
T("Got %s event on fd %d"), ms_names[n], fd);
+
wx
T("Got %s event on fd %d"), ms_names[n], fd);
(handler.*ms_handlers[n])();
(handler.*ms_handlers[n])();
- // callback can modify sets and destroy handler
, returning from
- //
here guarantees that one event is processed at a
time
- return;
+ // callback can modify sets and destroy handler
+ //
this forces that one event can be processed at one
time
+ return
true
;
}
}
}
}
+
+ return false;
}
// ----------------------------------------------------------------------------
// wxSelectDispatcher
// ----------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------
// wxSelectDispatcher
// ----------------------------------------------------------------------------
-/* static */
-wxSelectDispatcher *wxSelectDispatcher::Create()
-{
- return new wxSelectDispatcher;
-}
-
-wxSelectDispatcher::wxSelectDispatcher()
-{
- m_maxFD = -1;
-}
-
bool wxSelectDispatcher::RegisterFD(int fd, wxFDIOHandler *handler, int flags)
{
if ( !wxMappedFDIODispatcher::RegisterFD(fd, handler, flags) )
bool wxSelectDispatcher::RegisterFD(int fd, wxFDIOHandler *handler, int flags)
{
if ( !wxMappedFDIODispatcher::RegisterFD(fd, handler, flags) )
@@
-153,7
+144,7
@@
bool wxSelectDispatcher::RegisterFD(int fd, wxFDIOHandler *handler, int flags)
m_maxFD = fd;
wxLogTrace(wxSelectDispatcher_Trace,
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);
+
wx
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;
}
return true;
}
@@
-162,10
+153,10
@@
bool wxSelectDispatcher::ModifyFD(int fd, wxFDIOHandler *handler, int flags)
if ( !wxMappedFDIODispatcher::ModifyFD(fd, handler, flags) )
return false;
if ( !wxMappedFDIODispatcher::ModifyFD(fd, handler, flags) )
return false;
- wxASSERT_MSG( fd <= m_maxFD,
_
T("logic error: registered fd > m_maxFD?") );
+ wxASSERT_MSG( fd <= m_maxFD,
wx
T("logic error: registered fd > m_maxFD?") );
wxLogTrace(wxSelectDispatcher_Trace,
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);
+
wx
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);
}
return m_sets.SetFD(fd, flags);
}
@@
-196,12
+187,13
@@
bool wxSelectDispatcher::UnregisterFD(int fd)
}
wxLogTrace(wxSelectDispatcher_Trace,
}
wxLogTrace(wxSelectDispatcher_Trace,
-
_
T("Removed fd %d, current max: %d"), fd, m_maxFD);
+
wx
T("Removed fd %d, current max: %d"), fd, m_maxFD);
return true;
}
return true;
}
-
void
wxSelectDispatcher::ProcessSets(const wxSelectSets& sets)
+
int
wxSelectDispatcher::ProcessSets(const wxSelectSets& sets)
{
{
+ int numEvents = 0;
for ( int fd = 0; fd <= m_maxFD; fd++ )
{
if ( !sets.HasFD(fd) )
for ( int fd = 0; fd <= m_maxFD; fd++ )
{
if ( !sets.HasFD(fd) )
@@
-210,15
+202,18
@@
void wxSelectDispatcher::ProcessSets(const wxSelectSets& sets)
wxFDIOHandler * const handler = FindHandler(fd);
if ( !handler )
{
wxFDIOHandler * const handler = FindHandler(fd);
if ( !handler )
{
- wxFAIL_MSG(
_
T("NULL handler in wxSelectDispatcher?") );
+ wxFAIL_MSG(
wx
T("NULL handler in wxSelectDispatcher?") );
continue;
}
continue;
}
- sets.Handle(fd, *handler);
+ if ( sets.Handle(fd, *handler) )
+ numEvents++;
}
}
+
+ return numEvents;
}
}
-void wxSelectDispatcher::Dispatch(int timeout)
+int wxSelectDispatcher::DoSelect(wxSelectSets& sets, int timeout) const
{
struct timeval tv,
*ptv;
{
struct timeval tv,
*ptv;
@@
-233,24
+228,37
@@
void wxSelectDispatcher::Dispatch(int timeout)
ptv = NULL;
}
ptv = NULL;
}
- wxSelectSets sets = m_sets;
+ int ret = sets.Select(m_maxFD + 1, ptv);
+
+ // TODO: we need to restart select() in this case but for now just return
+ // as if timeout expired
+ if ( ret == -1 && errno == EINTR )
+ ret = 0;
- const int ret = sets.Select(m_maxFD + 1, ptv);
- switch ( ret )
+ return ret;
+}
+
+bool wxSelectDispatcher::HasPending() const
+{
+ wxSelectSets sets(m_sets);
+ return DoSelect(sets, 0) > 0;
+}
+
+int wxSelectDispatcher::Dispatch(int timeout)
+{
+ wxSelectSets sets(m_sets);
+ switch ( DoSelect(sets, timeout) )
{
case -1:
{
case -1:
- if ( errno != EINTR )
- {
- wxLogSysError(_("Failed to monitor I/O channels"));
- }
- break;
+ wxLogSysError(_("Failed to monitor I/O channels"));
+ return -1;
case 0:
// timeout expired without anything happening
case 0:
// timeout expired without anything happening
-
break
;
+
return 0
;
default:
default:
- ProcessSets(sets);
+
return
ProcessSets(sets);
}
}
}
}