// Authors: Lukasz Michalski and Vadim Zeitlin
// Created: December 2006
// Copyright: (c) Lukasz Michalski
-// RCS-ID: $Id$
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#if wxUSE_SELECT_DISPATCHER
-#include <sys/types.h>
+#if defined(HAVE_SYS_SELECT_H) || defined(__WATCOMC__)
+ #include <sys/time.h>
+ #include <sys/select.h>
+#endif
+
+#ifdef __WATCOMC__
+ #include <types.h>
+ #include <sys/ioctl.h>
+ #include <tcpustd.h>
+#else
+ #include <sys/types.h>
+#endif
#include "wx/private/fdiodispatcher.h"
// select() itself
int Select(int nfds, struct timeval *tv);
- // call the handler methods corresponding to the sets having this fd
- void Handle(int fd, wxFDIOHandler& handler) const;
+ // call the handler methods corresponding to the sets having this fd if it
+ // is present in any set and return true if it is
+ bool Handle(int fd, wxFDIOHandler& handler) const;
private:
typedef void (wxFDIOHandler::*Callback)();
class WXDLLIMPEXP_BASE wxSelectDispatcher : public wxMappedFDIODispatcher
{
public:
- // creates an instance of this class, the caller takes ownership of it
- static wxSelectDispatcher *Create();
+ // default ctor
+ wxSelectDispatcher() { m_maxFD = -1; }
// implement pure virtual methods of the base class
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);
-
-protected:
- // ctor is not public, use Create()
- wxSelectDispatcher();
+ virtual bool HasPending() const;
+ virtual int 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 the
+ // number of handlers we called
+ int 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,
const char *name);
+ // common part of HasPending() and Dispatch(): calls select() with the
+ // specified timeout
+ int DoSelect(wxSelectSets& sets, int timeout) const;
+
// the select sets containing all the registered fds
wxSelectSets m_sets;