Narra

Reference

std/net

std/net

TCP sockets on the event loop of the thread.

narra
import * as Net from "std/net"

The guide teaches it in chapter 14, Async.

This page is generated by scripts/std/generate.nra from narrac query --json interface std/net. Do not edit it.

Types

Listener

narra
export opaque struct Listener

Functions: listen, localPort, accept.

Connection

narra
export opaque struct Connection

Functions: accept, connect, read, chunks, write.

Functions

listen

narra
export function listen(host: string, port: int): Result<Listener, AsyncError> uses io, alloc

Effects: io, alloc.

localPort

narra
export function localPort(listener: Listener): int uses io

Effects: io.

accept

narra
export async function accept(listener: Listener): Result<Connection, AsyncError> uses io, alloc

Effects: io, alloc.

connect

narra
export async function connect(host: string, port: int): Result<Connection, AsyncError> uses io, alloc

Effects: io, alloc.

read

narra
export async function read(connection: Connection, maxBytes: int): Result<bytes, AsyncError> uses io, alloc

Effects: io, alloc.

chunks

narra
export async function* chunks(connection: Connection, maxBytes: int): AsyncGenerator<Result<bytes, AsyncError>> uses (io, alloc)

Effects: io, alloc.

write

narra
export async function write(connection: Connection, data: bytes): Result<int, AsyncError> uses io, alloc

Effects: io, alloc.