A wrapper around native socket polling functionality for monitoring multiple sockets for I/O readiness. This class provides a high-level abstraction over native poll operations, allowing you to monitor sockets for read and write events.

Constructor

new(n:Int)

Creates a new Poll instance.

Parameters:

n

The maximum number of sockets to monitor.

Variables

readIndexes:Array<Int>

An array of indices corresponding to sockets ready for reading after polling.

writeIndexes:Array<Int>

An array of indices corresponding to sockets ready for writing after polling.

Methods

events(?t:Float):Void

Waits for events on the prepared sockets.

Parameters:

t

The timeout in seconds. Use -1.0 for an infinite wait. Defaults to -1.0 if not specified.

poll(a:Array<Socket>, ?t:Float):Array<Socket>

Polls the given sockets for any events (e.g., readability or writability).

Parameters:

a

An array of sockets to monitor for events.

t

The timeout in seconds. Use -1.0 for an infinite wait. Defaults to -1.0 if not specified.

Returns:

An array of sockets that are ready for I/O operations.

prepare(read:Array<Socket>, write:Array<Socket>):Void

Prepares the poll structure for monitoring read and write events on the given sockets.

Parameters:

read

An array of sockets to monitor for readability.

write

An array of sockets to monitor for writability.