PollSelector

Selector that uses the poll() system call to receive I/O events for the registered conduits. To use this class you would normally do something like this:

Members

Aliases

select
alias select = AbstractSelector.select

Alias for the select() method as we're not reimplementing it in this class.

Functions

close
void close()

Close the selector.

count
size_t count()

Return the number of keys resulting from the registration of a conduit to the selector.

key
SelectionKey key(ISelectable conduit)

Return the selection key resulting from the registration of a conduit to the selector.

opApply
int opApply(int delegate(ref SelectionKey sk) dg)

Iterate through the currently registered selection keys. Note that you should not erase or add any items from the selector while iterating, although you can register existing conduits again.

open
void open(uint size, uint maxEvents)

Open the poll()-based selector.

register
void register(ISelectable conduit, Event events, Object attachment)

Associate a conduit to the selector and track specific I/O events. If a conduit is already associated, modify the events and attachment.

select
int select(TimeSpan timeout)

Wait for I/O events from the registered conduits for a specified amount of time.

selectedSet
ISelectionSet selectedSet()

Return the selection set resulting from the call to any of the select() methods.

unregister
void unregister(ISelectable conduit)

Remove a conduit from the selector.

Variables

DefaultSize
enum uint DefaultSize;

Default number of SelectionKey's that will be handled by the PollSelector.

Inherited Members

From AbstractSelector

_restartInterruptedSystemCall
bool _restartInterruptedSystemCall;

Restart interrupted system calls when blocking inside a call to select.

restartInterruptedSystemCall
bool restartInterruptedSystemCall()

Indicates whether interrupted system calls will be restarted when blocking inside a call to select.

restartInterruptedSystemCall
void restartInterruptedSystemCall(bool value)

Sets whether interrupted system calls will be restarted when blocking inside a call to select.

open
void open(uint size, uint maxEvents)

Initialize the selector.

close
void close()

Free any operating system resources that may have been allocated in the call to open().

register
void register(ISelectable conduit, Event events, Object attachment)

Associate a conduit to the selector and track specific I/O events.

reregister
deprecated void reregister(ISelectable conduit, Event events, Object attachment)

Deprecated, use register instead

unregister
void unregister(ISelectable conduit)

Remove a conduit from the selector.

select
int select()

Wait for I/O events from the registered conduits for a specified amount of time.

select
int select(double timeout)

Wait for I/O events from the registered conduits for a specified amount of time.

select
int select(TimeSpan timeout)

Wait for I/O events from the registered conduits for a specified amount of time.

selectedSet
ISelectionSet selectedSet()

Return the selection set resulting from the call to any of the select() methods.

key
SelectionKey key(ISelectable conduit)

Return the selection key resulting from the registration of a conduit to the selector.

count
size_t count()

Return the number of keys resulting from the registration of a conduit to the selector.

toTimeval
timeval* toTimeval(timeval* tv, TimeSpan interval)

* Cast the time duration to a C timeval struct.

checkErrno
void checkErrno(string file, size_t line)

Check the 'errno' global variable from the C standard library and throw an exception with the description of the error.

Examples

import tango.io.selector.PollSelector;

Socket socket;
ISelector selector = new PollSelector();

selector.open(100, 10);

// Register to read from socket
selector.register(socket, Event.Read);

int eventCount = selector.select(0.1); // 0.1 seconds
if (eventCount > 0)
{
    // We can now read from the socket
    socket.read();
}
else if (eventCount == 0)
{
    // Timeout
}
else if (eventCount == -1)
{
    // Another thread called the wakeup() method.
}
else
{
    // Error: should never happen.
}

selector.close();

Meta