~/bend-docscommunity

src/wire.bend relies on unsafe/foreign

raw source on the hub · import emerging-ezhttp@0.21.0.0/src/wire.bend as Wire

ezhttp/src/wire: one request out and one response back, over bend-kit-wire's sockets. Its effects park on the runtime's event loop, so exchanges run side by side under IO.fork. bend-kit-dns resolves the host; TLS is bend-kit-wire's (OpenSSL 3 loaded at run time, BEND_LIBSSL to point at it).

An exchange's answer is every octet of the response, packed (Received), or a failure: a non-zero status on its first line, then the reason (wirespec.bend wire.fail). Every decision is wirespec.bend's: the deadline (wire.ms.of), the octets sent (wire.payload), what a failed call is reported as (wire.fail) and when the response is whole (wire.read.count, else wire.read.next on a copy of the receive as text), so a server that keeps the connection open after a complete response is not waited on (SPEC.md HTTP-CLI-1, 6, 10, 13; HTTP-TRUST-3, 5).

6 imports
import Base
import bend-kit-wire@0.4.6.1/wire.bend as W
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes
import bend-kit-dns@0.6.0.2/dns.bend as Dns
import ./wirespec.bend as Spec
import ./http.bend as Http

Types

type Answer source · line 80 · raw

Type

an exchange's answer: the failure it was reported with (a status other than 0 on its first line, then the reason, wirespec.bend wire.fail), or every octet of the response, packed

Definitions

def wire.max source · line 23 · raw

U32

the most octets one receive asks for

def wire.reads source · line 27 · raw

Nat

the most receives one exchange makes

def wire.close source · line 33 · raw

@secure:Bool -> @s:Socket -> IO(Unit)

close a socket, ending its TLS session when it has one

def wire.recv source · line 41 · raw

@secure:Bool -> @s:Socket -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))

the next octets a socket has received, packed four to a word

def wire.sent source · line 50 · raw

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

a send.words.deadline answer without its count of octets accepted

def wire.send source · line 56 · raw

@secure:Bool -> @s:Socket -> @+len:U32 -> @buf:Array<U32> -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))

send octets, the plain send bounded by the deadline

def wire.shake source · line 67 · raw

@secure:Bool -> @s:Socket -> @host:String -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))

the TLS handshake with the host, when the exchange is secure

def wire.failed source · line 85 · raw

@+secure:Bool -> @s:Socket -> @answer:String -> IO(Answer)

a failed call's answer, the socket closed first

def wire.loop.on source · line 90 · raw

@+secure:Bool -> @s:Socket -> @r:0xedb2120a04a47dc18c3a756ec7c62750/src/wirespec.Read -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @more:(@_:Socket -> @_:0xedb2120a04a47dc18c3a756ec7c62750/src/http.Hear -> @_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)) -> IO(Answer)

a judged read: read again, or close and answer what was received

def wire.loop.copied source · line 101 · raw

@+secure:Bool -> @s:Socket -> @h:0xedb2120a04a47dc18c3a756ec7c62750/src/http.Hear -> @r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @more:(@_:Socket -> @_:0xedb2120a04a47dc18c3a756ec7c62750/src/http.Hear -> @_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)) -> IO(Answer)

a receive judged by a copy of it as text, dropped after the judging; the octets themselves are appended packed

def wire.loop.text source · line 109 · raw

@+secure:Bool -> @s:Socket -> @h:0xedb2120a04a47dc18c3a756ec7c62750/src/http.Hear -> @piece:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @more:(@_:Socket -> @_:0xedb2120a04a47dc18c3a756ec7c62750/src/http.Hear -> @_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)) -> IO(Answer)

a read judged by its text, when its count alone does not decide it

def wire.loop.judge source · line 115 · raw

@+secure:Bool -> @s:Socket -> @h:0xedb2120a04a47dc18c3a756ec7c62750/src/http.Hear -> @piece:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @counted:Maybe<&2, 0xedb2120a04a47dc18c3a756ec7c62750/src/wirespec.Read> -> @more:(@_:Socket -> @_:0xedb2120a04a47dc18c3a756ec7c62750/src/http.Hear -> @_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)) -> IO(Answer)

a read judged by its count when that decides it (SPEC.md HTTP-CLI-6)

def wire.loop.un source · line 125 · raw

@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+h:0xedb2120a04a47dc18c3a756ec7c62750/src/http.Hear -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @r:Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>) -> @more:(@_:Socket -> @_:0xedb2120a04a47dc18c3a756ec7c62750/src/http.Hear -> @_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)) -> IO(Answer)

a receive's outcome: a failure is the answer

def wire.loop source · line 140 · raw

@fuel:Nat -> @+secure:Bool -> @s:Socket -> @+host:String -> @+port:U32 -> @+ms:U32 -> @h:0xedb2120a04a47dc18c3a756ec7c62750/src/http.Hear -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)

receive until wirespec.bend says the answer is whole, the octets appended to what came before

def wire.after.send source · line 154 · raw

@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @r:Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>) -> IO(Answer)

after the send: read the answer, or the send's failure

def wire.put source · line 167 · raw

@+secure:Bool -> @s:Socket -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)

send the octets an exchange carries, then read its answer

def wire.after.shake source · line 176 · raw

@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @r:Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>) -> IO(Answer)

after the handshake: send, or the handshake's failure (the socket closed plainly, as no TLS session was made)

def wire.after.connect source · line 189 · raw

@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @r:Result<&1, &1, Pair(U32, String), Socket> -> IO(Answer)

after the connect: the handshake, or the connect's failure

def wire.dial.next source · line 202 · raw

@r:Result<&1, &1, Pair(U32, String), Socket> -> @more:(@_:Unit -> IO(Result<&1, &1, Pair(U32, String), Socket>)) -> IO(Result<&1, &1, Pair(U32, String), Socket>)

a connect that failed tries the next address; one that worked is kept

def wire.dial source · line 213 · raw

@rest:List<&2, String> -> @+first:String -> @+port:U32 -> @+ms:U32 -> IO(Result<&1, &1, Pair(U32, String), Socket>)

connect to each address in turn until one connects; the last one's failure when none does

def wire.after.resolve source · line 226 · raw

@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @r:Result<&1, &1, Pair(U32, String), List<&2, String>> -> IO(Answer)

after the resolve: connect, or the resolve's failure (no address at all is ENOENT, as bend-kit-dns reports a name with none)

def wire.looked source · line 242 · raw

@r:Result<&1, &1, Pair(U32, String), String> -> IO(Result<&1, &1, Pair(U32, String), List<&2, String>>)

the OS resolver's addresses, NUL-separated, as a list

def wire.resolve source · line 253 · raw

@+host:String -> @literal:List<&2, String> -> IO(Result<&1, &1, Pair(U32, String), List<&2, String>>)

a host's addresses: a numeric address or localhost as it is, else the OS resolver's answer

def wire.run.with source · line 264 · raw

@+secure:Bool -> @+ms:U32 -> @+host:String -> @+port:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)

the exchange once its octets are packed

def wire.run source · line 273 · raw

@+secure:Bool -> @+ms:U32 -> @+host:String -> @+port:U32 -> @+method:String -> @req:String -> @tail:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)

a request with this method, sent to a host as wirespec.bend says, with its tail of octets after it, every call bounded by the deadline; its whole answer

def wire.talk source · line 280 · raw

@secure:Bool -> @host:String -> @port:U32 -> @method:String -> @req:String -> @tail:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)

a request sent to a host, its tail of octets after it, and its whole answer read back, with the default deadline

def wire.talk.timed source · line 285 · raw

@secure:Bool -> @ms:U32 -> @host:String -> @port:U32 -> @method:String -> @req:String -> @tail:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)

the same exchange, bounded by a timeout in milliseconds