~/bend-docscommunity

net.bend relies on unsafe/foreign

raw source on the hub · import 0x650cd729029c76d9f6151ee977dc0ae8/net.bend as Net

Net: connections that may turn TLS mid-stream (net.c, native only). A connection is a Socket; after Net.tls, Net.send, Net.poll and Net.close go through the TLS session. Net.connect resolves host names, which Base's TCP.connect does not.

1 import
import Base

Effects (foreign code)

effect Net.connect source · line 8 · raw

@host:String -> @port:U32 -> IO(Result<&1, &1, Pair(U32, String), Socket>)

A host (name or IP) and port; tries every address it resolves to.

foreign: net.c, net.js

effect Net.tls source · line 16 · raw

@sock:Socket -> @host:String -> @cafile:String -> @cert:String -> @key:String -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))

A verified TLS 1.2+ session on the socket, for host; cafile "" trusts the system's certificate store; cert and key ("" for none) are PEM files with this side's certificate, for a server that asks for one.

foreign: net.c, net.js

effect Net.connect_via source · line 25 · raw

@proxy:String -> @pport:U32 -> @user:String -> @pass:String -> @host:String -> @port:U32 -> @kind:U32 -> IO(Result<&1, &1, Pair(U32, String), Socket>)

A connection to host:port through a proxy, which resolves the host: kind 0 is SOCKS5 (RFC 1928; user "" skips its password step, RFC 1929), kind 1 an HTTP proxy's CONNECT (RFC 9110 9.3.6; user "" sends no Proxy-Authorization).

foreign: net.c, net.js

effect Net.tls_accept source · line 32 · raw

@sock:Socket -> @cert:String -> @key:String -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))

The server's side of the handshake, with a PEM certificate chain and its PEM key.

foreign: net.c, net.js

effect Net.send source · line 37 · raw

@sock:Socket -> @data:String -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))

foreign: net.c, net.js

effect Net.poll source · line 43 · raw

@sock:Socket -> @max:U32 -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Maybe<&1, String>>))

Up to max bytes; Some{""} when the peer closed, None{} after ms.

foreign: net.c, net.js

effect Net.close source · line 48 · raw

@sock:Socket -> IO(Unit)

foreign: net.c, net.js

effect Net.time source · line 53 · raw

IO(U32)

Seconds since 1970-01-01 UTC.

foreign: net.c, net.js

effect Net.helo source · line 58 · raw

@sock:Socket -> IO(Pair(Socket, String))

What to say after EHLO: the host's FQDN, else an address literal.

foreign: net.c, net.js

effect Net.hostname source · line 63 · raw

IO(String)

The host's name as configured, maybe not fully qualified (for HELO).

foreign: net.c, net.js

effect Net.debug source · line 70 · raw

@on:U32 -> IO(Unit)

Turn the dialog trace on (1) or off (0): every line sent and received goes to stderr as "C: " and "S: ", with AUTH data masked and the message's text replaced by its size.

foreign: net.c, net.js

effect Dkim.sha256 source · line 78 · raw

@data:String -> IO(Result<&1, &1, Pair(U32, String), String>)

The SHA-256 of a text's bytes, in base64.

foreign: net.c, net.js

effect Dkim.alg source · line 83 · raw

@keyfile:String -> IO(Result<&1, &1, Pair(U32, String), String>)

"rsa-sha256" or "ed25519-sha256", by the kind of the PEM private key.

foreign: net.c, net.js

effect Dkim.sign source · line 88 · raw

@keyfile:String -> @data:String -> IO(Result<&1, &1, Pair(U32, String), String>)

The signature of a text's bytes with the PEM private key, in base64.

foreign: net.c, net.js