easy-nio.selector
Wrapper around java.nio.channels.Selector.
acceptable?
(acceptable? key)Returns true if key’s channel is ready to accept a new socket connection.
all-keys
(all-keys sel)Returns the set of all keys registered with sel, including those not yet ready.
clear-keys!
(clear-keys! selected)Removes all keys from the selected-key set after processing. Call this after all keys in selected have been handled.
connectable?
(connectable? key)Returns true if key’s channel is ready to complete a connection.
deregister!
(deregister! key)Cancels key, removing its channel from the selector. The key becomes invalid immediately. The cancellation takes effect on the next select! call.
get-interests
(get-interests key)Retrieves this key’s interest set. It is guaranteed that the returned set will only contain operation bits that are valid for this key’s channel.
register!
(register! ch sel ops)(register! ch sel ops attachment)Registers channel ch with selector sel for the given operations ops (a bitwise OR of op-read, op-write, op-accept, op-connect). Optionally accepts an attachment — any object — stored on the key and retrievable via (attachment key). Useful for associating per-channel state (e.g. a buffer, a handler, a connection id). Returns the resulting SelectionKey.
select!
(select! sel)Selects a set of keys whose corresponding channels are ready for I/O operations. Blocks until at least one channel is ready for an operation it is registered for.
select-now!
(select-now! sel)Non-blocking select. Returns immediately with the number of keys whose ready-op sets were updated since the last select call. Returns 0 if no channels are ready.
select-timeout!
(select-timeout! sel timeout-ms)Like select!, but blocks for at most timeout-ms milliseconds. Returns the number of keys whose ready-operation sets were updated.
selected-keys
(selected-keys sel)Returns the mutable Set of SelectionKeys that are ready.
set-interests!
(set-interests! key ops)Updates the interest ops of key to ops. Useful for switching a channel between read and write interest mid-lifecycle, e.g. after accumulating a full response to send. Returns key.
wakeup!
(wakeup! sel)Causes the first selection operation that has not yet returned to return immediately. Returns sel.