libs/wire/wire.bend relies on unsafe/foreign
raw source on the hub · import 0x3d2147650fe101ae3c3e4a95333b4238/libs/wire/wire.bend as Wire
Byte-exact TCP, UDP, and TLS sockets. Source: https://github.com/paymog/bend-kit/tree/main/wire
1 import
import Base
Effects (foreign code)
effect connect source · line 10 · raw
@host:String -> @port:U32 -> @ms:U32 -> IO(Result<&1, &1, Pair(U32, String), Socket>)
TCP connect to a numeric IPv4 or IPv6 address, with a deadline.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect recv source · line 15 · raw
@sock:Socket -> @max:U32 -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), String>))
Octet-String TCP and UDP effects are the slow path: one Char cell per byte.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect send source · line 19 · raw
@sock:Socket -> @data:String -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect send.timeout source · line 24 · raw
@sock:Socket -> @data:String -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
Like send, but interrupts a blocked write at the supplied millisecond deadline.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect recv_from source · line 30 · raw
@sock:Socket -> @max:U32 -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(String, Pair(U32, String))>))
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect send_to source · line 36 · raw
@sock:Socket -> @host:String -> @port:U32 -> @data:String -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect tls.connect source · line 45 · raw
@sock:Socket -> @host:String -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
TLS over a connected TCP socket (OpenSSL 3, loaded at run time; BEND_LIBSSL overrides its path). The certificate chain and host name are always checked.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect tls.connect.cert source · line 53 · raw
@sock:Socket -> @host:String -> @ms:U32 -> @cert_path:String -> @key_path:String -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
Use a PEM certificate chain and its private key for mutual TLS. A load failure is EINVAL; a handshake or server verification failure is EPROTO.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect tls.connect.alpn source · line 62 · raw
@sock:Socket -> @host:String -> @ms:U32 -> @protos:String -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), String>))
protos is a comma-separated ALPN list (for example "h2,http/1.1").
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect tls.send source · line 70 · raw
@sock:Socket -> @data:String -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
The String TLS effects are the slow path: one Char cell per octet.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect tls.send.timeout source · line 75 · raw
@sock:Socket -> @data:String -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
Like tls.send, but interrupts a blocked SSL write at the supplied deadline.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect tls.recv source · line 82 · raw
@sock:Socket -> @max:U32 -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), String>))
"" once the peer sends close_notify. A bare EOF is an error.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect tls.close source · line 87 · raw
@sock:Socket -> IO(Unit)
Ends the TLS session and closes the socket.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect recv.words source · line 93 · raw
@sock:Socket -> @max:U32 -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))
The .words forms move (len, words): bytes packed four to a U32, laid out as bytes/bytes.bend packs them, so no String cell is made per byte.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect send.words source · line 100 · raw
@sock:Socket -> @len:U32 -> @words:Array<U32> -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
len past the end of words fails with EINVAL.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect recv_from.words source · line 107 · raw
@sock:Socket -> @max:U32 -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(String, Pair(U32, Pair(U32, Array<U32>)))>))
UDP keeps the sender address and port beside the packed datagram.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect send_to.words source · line 114 · raw
@sock:Socket -> @host:String -> @port:U32 -> @len:U32 -> @words:Array<U32> -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
len past the end of words fails with EINVAL.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect tls.recv.words source · line 123 · raw
@sock:Socket -> @max:U32 -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))
len 0 once the peer sends close_notify.
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js
effect tls.send.words source · line 129 · raw
@sock:Socket -> @len:U32 -> @words:Array<U32> -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
foreign: libs/wire/effs/wire.c, libs/wire/effs/wire.js