Module selectors

Types

SelectorData = RootRef
  Source Edit
Event = enum
  EvRead, EvWrite, EvError
  Source Edit
SelectorKey = object
  fd*: SocketHandle
  events*: set[Event]
  data*: SelectorData          ## User object.
  
The events which fd listens for.   Source Edit
ReadyInfo = tuple[key: SelectorKey, events: set[Event]]
  Source Edit
Selector = ref object
  
An object which holds file descriptors to be checked for read/write status.   Source Edit

Procs

proc hash(x: SocketHandle): Hash {.
borrow
.}
  Source Edit
proc `$`(x: SocketHandle): string {.
borrow
.}
  Source Edit
proc register(s: Selector; fd: SocketHandle; events: set[Event]; data: SelectorData): SelectorKey {.
discardable, raises: [], tags: []
.}
Registers file descriptor fd to selector s with a set of Event events.   Source Edit
proc update(s: Selector; fd: SocketHandle; events: set[Event]): SelectorKey {.
discardable, raises: [], tags: []
.}
Updates the events which fd wants notifications for.   Source Edit
proc unregister(s: Selector; fd: SocketHandle): SelectorKey {.
discardable, raises: [], tags: []
.}
Unregisters file descriptor fd from selector s.   Source Edit
proc close(s: Selector) {.
raises: [], tags: []
.}
Closes the selector   Source Edit
proc select(s: Selector; timeout: int): seq[ReadyInfo] {.
raises: [], tags: []
.}
The events field of the returned key contains the original events for which the fd was bound. This is contrary to the events field of the ReadyInfo tuple which determines which events are ready on the fd.   Source Edit
proc newSelector(): Selector {.
raises: [], tags: []
.}
Creates a new selector   Source Edit
proc contains(s: Selector; fd: SocketHandle): bool {.
raises: [], tags: []
.}
Determines whether selector contains a file descriptor.   Source Edit
proc `[]`(s: Selector; fd: SocketHandle): SelectorKey {.
raises: [], tags: []
.}
Retrieves the selector key for fd.   Source Edit
proc contains(s: Selector; key: SelectorKey): bool {.
raises: [], tags: []
.}
Determines whether selector contains this selector key. More accurate than checking if the file descriptor is in the selector because it ensures that the keys are equal. File descriptors may not always be unique especially when an fd is closed and then a new one is opened, the new one may have the same value.   Source Edit
proc len(s: Selector): int {.
raises: [], tags: []
.}
Retrieves the number of registered file descriptors in this Selector.   Source Edit