Std.Tcp
HostNotFound
Section titled “HostNotFound”error HostNotFound(host: String)The name could not be resolved.
host: String
ConnectionRefused
Section titled “ConnectionRefused”error ConnectionRefused(host: String, port: Int)Nothing accepted the connection.
host: Stringport: Int
ConnectionClosed
Section titled “ConnectionClosed”error ConnectionClosedThe connection was closed by close, by the release of the handler, or by the peer resetting
it, or the peer finished sending before read_exact got its bytes.
TlsFailure
Section titled “TlsFailure”error TlsFailure(message: String)The TLS handshake failed, including a certificate that could not be verified.
message: String
TcpFailure
Section titled “TcpFailure”error TcpFailure(message: String)Any other failure of the host. message is the host’s description.
message: String
Connection
Section titled “Connection”type ConnectionAn open connection, or one that was closed. Held by the host.
enum RootsThe certificates trusted as roots.
-
SystemRootsThe roots that the host trusts.
-
Pem(text: String)One or more CA certificates in PEM, which are then the only roots trusted.
Verify
Section titled “Verify”enum VerifyHow much of the peer’s certificate upgrade_tls checks.
-
Full(roots: Roots)Verifies the chain up to
roots, and that the certificate is for the server name. -
ChainOnly(roots: Roots)Verifies the chain up to
rootsonly. -
NoVerificationChecks nothing: the connection is encrypted, but the peer is not authenticated.
effect TcpA TCP client.
-
suspend fn connect(host: String, port: Int) -> Connection fails HostNotFound | ConnectionRefused | TcpFailureResolves
host(a name or an IP address) and connects toport. -
suspend fn read(conn: Connection, max: Int) -> Option[Bytes] fails ConnectionClosed | TcpFailureAt least 1 and at most
maxbytes, as many as have arrived, orNoneafter the peer has finished sending. -
suspend fn write(conn: Connection, data: Bytes) -> () fails ConnectionClosed | TcpFailureReturns after all of
datahas been handed to the host. -
suspend fn upgrade_tls(conn: Connection, server_name: String, verify: Verify) -> () fails ConnectionClosed | TlsFailure | TcpFailurePerforms a TLS handshake as the client, and turns the same connection into a TLS connection.
-
suspend fn close(conn: Connection) -> ()Closes the connection. Closing a closed connection does nothing.
SystemTcp
Section titled “SystemTcp”handler SystemTcp(registry: Registry): Tcpuses { Async, ProcessHost }The host’s TCP client: node:net and node:tls on JS. Its release closes the connections it
opened that are still open.
registry: Registry
VERIFY_FULL
Section titled “VERIFY_FULL”const VERIFY_FULL: VerifyThe usual check: the chain up to the roots that the host trusts, and the server name.
read_exact
Section titled “read_exact”fn read_exact(conn: Connection, n: Int) -> Bytes fails ConnectionClosed | TcpFailure uses { Tcp }Exactly n bytes, read with read as many times as needed. ConnectionClosed if the peer
finishes sending first. An n of 0 reads nothing; a negative n is a defect.