src/wire.bend relies on unsafe/foreign
raw source on the hub · import emerging-ezhttp@0.18.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 a status on its first line, then text: "0" and the raw response, or a non-zero status and 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.next), 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).
5 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
Definitions
def wire.max source · line 21 · raw
U32
the most octets one receive asks for
def wire.reads source · line 25 · raw
Nat
the most receives one exchange makes
def wire.close source · line 31 · raw
@secure:Bool -> @s:Socket -> IO(Unit)
close a socket, ending its TLS session when it has one
def wire.recv source · line 39 · 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 48 · 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 54 · 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 65 · 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.end.of source · line 76 · raw
@r:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Read -> String
a read that answered: its answer
def wire.end.more source · line 84 · raw
@r:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Read -> String
the held text went in: now the close
def wire.end source · line 92 · raw
@acc:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> @+text:String -> @none:Bool -> String
what the server's close leaves: the text still held, then the close
def wire.loop.on source · line 100 · raw
@+secure:Bool -> @s:Socket -> @r:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Read -> @more:(@_:Socket -> @_:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> IO(String)) -> IO(String)
a judged read: read again, or close and answer
def wire.loop.judge source · line 111 · raw
@+secure:Bool -> @s:Socket -> @acc:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> @+text:String -> @held:List<&2, U32> -> @none:Bool -> @more:(@_:Socket -> @_:List<&2, U32> -> @_:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> IO(String)) -> IO(String)
decoded text once it is known whether it is empty: read again when the octets finished no character, else judge the text
def wire.loop.text source · line 122 · raw
@+secure:Bool -> @s:Socket -> @acc:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> @t:Pair(String, List<&2, U32>) -> @more:(@_:Socket -> @_:List<&2, U32> -> @_:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> IO(String)) -> IO(String)
octets that arrived, decoded with what was held
def wire.loop.closed source · line 129 · raw
@+secure:Bool -> @s:Socket -> @held:List<&2, U32> -> @acc:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> IO(String)
the server's close: what was held, decoded as it is, then the close
def wire.loop.got source · line 136 · raw
@+secure:Bool -> @s:Socket -> @held:List<&2, U32> -> @acc:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> @+len:U32 -> @buf:Array<U32> -> @closed:Bool -> @more:(@_:Socket -> @_:List<&2, U32> -> @_:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> IO(String)) -> IO(String)
a receive's octets, or the server's close
def wire.loop.un source · line 148 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @held:List<&2, U32> -> @acc:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> @r:Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>) -> @more:(@_:Socket -> @_:List<&2, U32> -> @_:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> IO(String)) -> IO(String)
a receive's outcome: a failure is the answer
def wire.loop source · line 162 · raw
@fuel:Nat -> @+secure:Bool -> @s:Socket -> @+host:String -> @+port:U32 -> @+ms:U32 -> @held:List<&2, U32> -> @acc:0x9aad1f0de4523b34b9bfb69ebb80e11a/src/wirespec.Got -> IO(String)
receive until wirespec.bend says the answer is whole
def wire.after.send source · line 177 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @r:Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>) -> IO(String)
after the send: read the answer, or the send's failure
def wire.put source · line 191 · raw
@+secure:Bool -> @s:Socket -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(String)
send the octets an exchange carries, then read its answer
def wire.after.shake source · line 200 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:String -> @r:Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>) -> IO(String)
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 213 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:String -> @r:Result<&1, &1, Pair(U32, String), Socket> -> IO(String)
after the connect: the handshake, or the connect's failure
def wire.dial.next source · line 225 · 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 236 · 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 249 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:String -> @r:Result<&1, &1, Pair(U32, String), List<&2, String>> -> IO(String)
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 263 · 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 274 · 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 source · line 287 · raw
@+secure:Bool -> @+ms:U32 -> @+host:String -> @+port:U32 -> @+method:String -> @req:String -> @tail:List<&2, U32> -> IO(String)
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 296 · raw
@secure:Bool -> @host:String -> @port:U32 -> @method:String -> @req:String -> @tail:List<&2, U32> -> IO(String)
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 301 · raw
@secure:Bool -> @ms:U32 -> @host:String -> @port:U32 -> @method:String -> @req:String -> @tail:List<&2, U32> -> IO(String)
the same exchange, bounded by a timeout in milliseconds