#include <Iguana/Utilities/classlib/iobase/IOSelector.h>
Public Types | |
enum | Strategy { S_DEFAULT, S_SELECT, S_RTSIGIO, S_RTSIGONE, S_DEVPOLL, S_POLL, S_KQUEUE } |
Selector strategies. More... | |
Public Member Functions | |
virtual void | andMask (IOChannel *channel, unsigned value) |
virtual void | attach (IOChannel *channel, unsigned mask, IOSelectCB c=IOSelectCB()) |
virtual void | clear (void) |
virtual void | detach (IOChannel *channel) |
virtual unsigned | dispatch (long msecs=-1) |
IOSelector (const Strategy *strategy=SV_DEFAULT) | |
virtual bool | nextReady (IOSelectEvent &event, IOSelectCB &c) |
virtual void | orMask (IOChannel *channel, unsigned value) |
virtual unsigned | pump (long msecs=-1) |
virtual void | setMask (IOChannel *channel, unsigned value) |
virtual bool | wait (long msecs=-1) |
virtual | ~IOSelector (void) |
Static Public Attributes | |
static CLASSLIB_API const Strategy | SV_DEFAULT [] |
Default strategy vector. | |
static CLASSLIB_API const Strategy | SV_HIGHPERF [] |
Default high-load strategy vector. | |
Private Attributes | |
IOSelectMethod * | m_strategy |
IOSelector is a class for listening changes in the status of multiple I/O channels simultaneously. It is intended to be used when an application has multiple I/O channels whose activity it wants to monitor and to whose states it wants to respond to. Typical uses include server applications that want to wait and respond to client activity, or clients that have more than one server to talk to.
IOSelector defines a basic platform-specific strategy for listening activity on the channels (S_DEFAULT), sufficient for most basic needs. Applications with more specific demands, such as very large number of clients or high performance requirements can customise the selector to particular platform-specific system calls.
The general usage model of this class is to first attach one or more IOChannel objects, perform a wait, respond to the updated channel states, perform further waits, and finally deregister the channels. Channels can be added or removed at any time (FIXME: will changes erase current wait update status?).
It is more efficient to register channels once and do multiple waits on them than to register them all, do one wait and then register all again. While channels can be added and removed at any time that suits the application, changing the list as rarely as possible enables significant optimisation with some strategies (e.g. S_DEVPOLL). Clients that can sustain descriptor interest for a long time should use dispatch(). Since pump() always removes the descriptor before invoking the handler, it is by definition not able to sustain high performance, but may still suit certain I/O processing models.
If the application needs to maintain connection to more than just a handful of clients, it is in general better to use this class than to use several threads with blocking I/O. (FIXME: explain why or at least link to the documentation.)
Limitations:
EWOULDBLOCK
error. The client may first have to read ordinary data to make room in system buffers for the out-of-band data, or perform other tricks. For examples on correct handling of such conditions, including use of Socket::isAtMark(), see GNU libc info, node "Out-of-Band Data".
Definition at line 109 of file IOSelector.h.
Selector strategies.
S_DEFAULT |
Default selector strategy, should always be included as a last-resort fallback if other methods are unavailable.
On unix: select() with automatic switch to poll() if there are too many file descriptors (FIXME not yet, sometimes poll() is just a wrapper for select()). On windows a multi-threaded custom poller; the only alternative on this platform. |
S_SELECT |
Use select().
|
S_RTSIGIO |
Use real-time signals (real-time version of SIGIO) with POSIX signal queueing.
Automatically uses S_POLL as fallback for handling overflow. |
S_RTSIGONE |
S_RTSIGIO with only one signal queued per file descriptor which can significantly reduce overflow.
|
S_DEVPOLL |
Use /dev/poll.
|
S_POLL |
Use poll().
|
S_KQUEUE |
Use kqueue().
|
Definition at line 113 of file IOSelector.h.
00113 { 00120 S_DEFAULT, 00121 00123 S_SELECT, 00124 00128 S_RTSIGIO, 00129 00132 S_RTSIGONE, 00133 00135 S_DEVPOLL, 00136 00138 S_POLL, 00139 00141 S_KQUEUE 00142 };
lat::IOSelector::IOSelector | ( | const Strategy * | strategy = SV_DEFAULT |
) |
virtual lat::IOSelector::~IOSelector | ( | void | ) | [virtual] |
virtual void lat::IOSelector::attach | ( | IOChannel * | channel, | |
unsigned | mask, | |||
IOSelectCB | c = IOSelectCB() | |||
) | [virtual] |
Referenced by IgNet::losePeer(), DQMNet::losePeer(), and VisNet::losePeer().
virtual unsigned lat::IOSelector::dispatch | ( | long | msecs = -1 |
) | [virtual] |
Referenced by VisNet::run(), IgNet::run(), and DQMNet::run().
virtual bool lat::IOSelector::nextReady | ( | IOSelectEvent & | event, | |
IOSelectCB & | c | |||
) | [virtual] |
virtual unsigned lat::IOSelector::pump | ( | long | msecs = -1 |
) | [virtual] |
virtual bool lat::IOSelector::wait | ( | long | msecs = -1 |
) | [virtual] |
IOSelectMethod* lat::IOSelector::m_strategy [private] |
Definition at line 204 of file IOSelector.h.
CLASSLIB_API const Strategy lat::IOSelector::SV_DEFAULT[] [static] |
CLASSLIB_API const Strategy lat::IOSelector::SV_HIGHPERF[] [static] |