Types
AddressFamily {.pure.} = enum None, IPv4, IPv6, Unix
- Source Edit
DualStackType {.pure.} = enum Auto, Enabled, Disabled, Default
- Source Edit
ServerCommand = enum Start, Pause, Stop
- Server's commands Source Edit
ServerFlags = enum ReuseAddr, ReusePort, TcpNoDelay, NoAutoRead, GCUserData, FirstPipe, NoPipeFlash, Broadcast, V4Mapped
- Server's flags Source Edit
ServerStatus = enum Starting, Stopped, Running, Closed
- Server's statuses Source Edit
SocketServer = ref object of RootRef sock*: AsyncFD local*: TransportAddress status*: ServerStatus udata*: pointer flags*: set[ServerFlags] bufferSize*: int loopFuture*: Future[void].Raising([]) domain*: Domain apending*: bool asock*: AsyncFD errorCode*: OSErrorCode abuffer*: array[128, byte] dualstack*: DualStackType when defined(windows): aovl*: CustomOverlapped
- Socket server object Source Edit
TransportAbortedError = object of TransportError
- Remote client disconnected before server accepts connection Source Edit
TransportAddress = object case family*: AddressFamily of AddressFamily.None: nil of AddressFamily.IPv4: address_v4*: array[4, uint8] of AddressFamily.IPv6: address_v6*: array[16, uint8] of AddressFamily.Unix: address_un*: array[108, uint8] port*: Port
- Transport network address Source Edit
TransportAddressError = object of TransportError code*: OSErrorCode
- Transport's address specific exception Source Edit
TransportError = object of AsyncError
- Transport's specific exception Source Edit
TransportIncompleteError = object of TransportError
- Transport's incomplete data received exception Source Edit
TransportLimitError = object of TransportError
- Transport's data limit reached exception Source Edit
TransportNoSupport = object of TransportError
- Transport's capability not supported exception Source Edit
TransportOsError = object of TransportError code*: OSErrorCode
- Transport's OS specific exception Source Edit
TransportState = enum ReadPending, ReadPaused, ReadClosed, ReadEof, ReadError, WritePending, WritePaused, WriteClosed, WriteEof, WriteError
- Transport's state Source Edit
TransportTooManyError = object of TransportError
- Too many open file descriptors exception Source Edit
TransportUseClosedError = object of TransportError
- Usage after transport close exception Source Edit
TransportUseEofError = object of TransportError
- Usage after transport half-close exception Source Edit
Vars
AnyAddress = TransportAddress(family: AddressFamily.IPv4, port: Port(0))
- Default INADDR_ANY address for IPv4 Source Edit
AnyAddress6 = TransportAddress(family: AddressFamily.IPv6, port: Port(0))
- Default INADDR_ANY address for IPv6 Source Edit
Consts
DefaultDatagramBufferSize = 65536
- Default buffer size for datagram transports Source Edit
DefaultStreamBufferSize = 16384
- Default buffer size for stream transports Source Edit
Procs
proc `$`(address: TransportAddress): string {....raises: [], tags: [].}
- Returns string representation of address. Source Edit
proc `==`(lhs, rhs: TransportAddress): bool {....raises: [], tags: [].}
- Compare two transport addresses lhs and rhs. Return true if addresses are equal. Source Edit
proc address(ta: TransportAddress): IpAddress {....raises: [ValueError], raises: [], tags: [].}
-
Converts TransportAddress to net.IpAddress object.
Note its impossible to convert TransportAddress of Unix family, because IpAddress supports only IPv4, IPv6 addresses.
Source Edit proc fromSAddr(sa: ptr Sockaddr_storage; sl: SockLen; address: var TransportAddress) {....raises: [], tags: [].}
- Set transport address address with value from OS specific socket address storage. Source Edit
proc getAutoAddress(port: Port): TransportAddress {....raises: [], tags: [].}
- Source Edit
proc getAutoAddresses(localPort: Port; remotePort: Port): tuple[ local: TransportAddress, remote: TransportAddress] {....raises: [], tags: [].}
- Source Edit
proc getDomain(address: TransportAddress): Domain {....raises: [], tags: [].}
- Returns OS specific Domain from TransportAddress. Source Edit
proc getDomain(socket: AsyncFD): Result[AddressFamily, OSErrorCode] {. ...raises: [], tags: [].}
-
Returns address family which is used to create socket socket.
Note: chronos supports only AF_INET, AF_INET6 and AF_UNIX sockets. For all other types of sockets this procedure returns EAFNOSUPPORT/WSAEAFNOSUPPORT error.
Source Edit proc host(ta: TransportAddress): string {....raises: [], raises: [], tags: [].}
-
Returns host of TransportAddress ta.
For IPv4 and IPv6 addresses it will return IP address as string, or empty string for Unix address.
Source Edit proc initTAddress(address: IpAddress; port: Port): TransportAddress {. ...raises: [], tags: [].}
- Initialize TransportAddress with net.nim IpAddress and port number port. Source Edit
proc initTAddress(address: string): TransportAddress {. ...raises: [TransportAddressError], raises: [], tags: [].}
-
Parses string representation of address. address can be IPv4, IPv6 or Unix domain address.
IPv4 transport address format is a.b.c.d:port. IPv6 transport address format is [::]:port. Unix transport address format is /address.
Source Edit proc initTAddress(address: string; port: int): TransportAddress {. ...raises: [TransportAddressError], raises: [], tags: [].}
- Initialize TransportAddress with IP (IPv4 or IPv6) address address and port number port. Source Edit
proc initTAddress(address: string; port: Port): TransportAddress {. ...raises: [TransportAddressError], raises: [], tags: [].}
- Initialize TransportAddress with IP (IPv4 or IPv6) address address and port number port. Source Edit
proc isAvailable(family: AddressFamily): bool {....raises: [], tags: [].}
- Source Edit
proc raiseTransportError(ecode: OSErrorCode) {. ...raises: [TransportAbortedError, TransportTooManyError, TransportOsError], noreturn, ...raises: [], tags: [].}
- Raises transport specific OS error. Source Edit
proc raiseTransportOsError(err: OSErrorCode) {....raises: [TransportOsError], raises: [], tags: [].}
- Raises transport specific OS error. Source Edit
proc resolveTAddress(address: string): seq[TransportAddress] {. ...raises: [TransportAddressError], raises: [], tags: [].}
-
Resolve string representation of address.
Supported formats are: IPv4 numeric address a.b.c.d:port IPv6 numeric address [::]:port Hostname address hostname:port
If hostname address is detected, then network address translation via DNS will be performed.
Source Edit proc resolveTAddress(address: string; domain: Domain): seq[TransportAddress] {. ...raises: [TransportAddressError], raises: [], tags: [].}
- Source Edit
proc resolveTAddress(address: string; family: AddressFamily): seq[ TransportAddress] {....raises: [TransportAddressError], raises: [], tags: [].}
-
Resolve string representation of address.
Supported formats are: IPv4 numeric address a.b.c.d:port IPv6 numeric address [::]:port Hostname address hostname:port
If hostname address is detected, then network address translation via DNS will be performed.
Source Edit proc resolveTAddress(address: string; family: IpAddressFamily): seq[ TransportAddress] {....deprecated, raises: [TransportAddressError], raises: [], tags: [].}
- Source Edit
proc resolveTAddress(address: string; port: Port): seq[TransportAddress] {. ...raises: [TransportAddressError], raises: [], tags: [].}
-
Resolve string representation of address.
Supported formats are: IPv4 numeric address a.b.c.d:port IPv6 numeric address [::]:port Hostname address hostname:port
If hostname address is detected, then network address translation via DNS will be performed.
Source Edit proc resolveTAddress(address: string; port: Port; domain: Domain): seq[ TransportAddress] {....raises: [TransportAddressError], raises: [], tags: [].}
- Source Edit
proc resolveTAddress(address: string; port: Port; family: AddressFamily): seq[ TransportAddress] {....raises: [TransportAddressError], raises: [], tags: [].}
-
Resolve string representation of address.
address could be dot IPv4/IPv6 address or hostname.
If hostname address is detected, then network address translation via DNS will be performed.
Source Edit proc resolveTAddress(address: string; port: Port; family: IpAddressFamily): seq[ TransportAddress] {....deprecated, raises: [TransportAddressError], raises: [], tags: [].}
- Source Edit
proc setDualstack(socket: AsyncFD; family: AddressFamily; flag: DualStackType): Result[ void, OSErrorCode] {....raises: [], tags: [].}
- Source Edit
proc setDualstack(socket: AsyncFD; flag: DualStackType): Result[void, OSErrorCode] {....raises: [], tags: [].}
- Source Edit
proc toHex(address: TransportAddress): string {....raises: [], tags: [].}
- Returns hexadecimal representation of address. Source Edit
proc toIpAddress(address: TransportAddress): IpAddress {....raises: [], tags: [].}
- Source Edit
proc toSAddr(address: TransportAddress; sa: var Sockaddr_storage; sl: var SockLen) {....raises: [], tags: [].}
- Set socket OS specific socket address storage with address from transport address address. Source Edit
proc windowsAnyAddressFix(a: TransportAddress): TransportAddress {....raises: [], tags: [].}
- BSD Sockets on *nix systems are able to perform connections to 0.0.0.0 or ::0 which are equal to 127.0.0.1 or ::1. Source Edit
Templates
template checkClosed(t: untyped)
- Source Edit
template checkClosed(t: untyped; future: untyped)
- Source Edit
template checkWriteEof(t: untyped; future: untyped)
- Source Edit
template getConnectionAbortedError(code: OSErrorCode): ref TransportAbortedError
- Source Edit
template getConnectionAbortedError(m: string = ""): ref TransportAbortedError
- Source Edit
template getError(t: untyped): ref TransportError
- Source Edit
template getServerUseClosedError(): ref TransportUseClosedError
- Source Edit
template getTransportError(ecode: OSErrorCode): untyped
- Source Edit
template getTransportOsError(err: cint): ref TransportOsError
- Source Edit
template getTransportOsError(err: OSErrorCode): ref TransportOsError
- Source Edit
template getTransportTooManyError(code = OSErrorCode(0)): ref TransportTooManyError
- Source Edit
template getTransportUseClosedError(): ref TransportUseClosedError
- Source Edit