Module selectors


os, hashes, winlean, tables


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


proc hash(x: SocketHandle): Hash {.borrow.}
proc `$`(x: SocketHandle): string {.borrow.}
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.
proc update(s: Selector; fd: SocketHandle; events: set[Event]): SelectorKey {.
    discardable, raises: [], tags: [].}
Updates the events which fd wants notifications for.
proc unregister(s: Selector; fd: SocketHandle): SelectorKey {.discardable, raises: [],
    tags: [].}
Unregisters file descriptor fd from selector s.
proc close(s: Selector) {.raises: [], tags: [].}
Closes the selector
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.
proc newSelector(): Selector {.raises: [], tags: [].}
Creates a new selector
proc contains(s: Selector; fd: SocketHandle): bool {.raises: [], tags: [].}
Determines whether selector contains a file descriptor.
proc `[]`(s: Selector; fd: SocketHandle): SelectorKey {.raises: [], tags: [].}
Retrieves the selector key for fd.
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.
proc len(s: Selector): int {.raises: [], tags: [].}
Retrieves the number of registered file descriptors in this Selector.

© 2006–2017 Andreas Rumpf
Licensed under the MIT License.