Module selectors

Types

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

Procs

proc hash(x: SocketHandle): THash {.borrow.}
  Source
proc `$`(x: SocketHandle): string {.borrow.}
  Source
proc register(s: Selector; fd: SocketHandle; events: set[Event]; data: RootRef): SelectorKey {.
    discardable, raises: [], tags: [].}
Registers file descriptor fd to selector s with a set of TEvent events.   Source
proc update(s: Selector; fd: SocketHandle; events: set[Event]): SelectorKey {.
    discardable, raises: [], tags: [].}
Updates the events which fd wants notifications for.   Source
proc unregister(s: Selector; fd: SocketHandle): SelectorKey {.discardable, 
    raises: [], tags: [].}
Unregisters file descriptor fd from selector s.   Source
proc close(s: Selector) {.raises: [], tags: [].}
Closes the selector   Source
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 TReadyInfo tuple which determines which events are ready on the fd.   Source
proc newSelector(): Selector {.raises: [], tags: [].}
Creates a new selector   Source
proc contains(s: Selector; fd: SocketHandle): bool {.raises: [], tags: [].}
Determines whether selector contains a file descriptor.   Source
proc `[]`(s: Selector; fd: SocketHandle): SelectorKey {.raises: [], tags: [].}
Retrieves the selector key for fd.   Source
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