src/wire.bend relies on unsafe/foreign
raw source on the hub · import emerging-ezhttp@0.20.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.loop.on source · line 76 · raw
@+secure:Bool -> @s:Socket -> @r:0xdc8b9e3a3b68c4b632d5e290f8608324/src/wirespec.Read -> @more:(@_:Socket -> @_:0xdc8b9e3a3b68c4b632d5e290f8608324/src/wirespec.Got -> IO(String)) -> IO(String)
a judged read: read again, or close and answer
def wire.loop.got source · line 86 · raw
@+secure:Bool -> @s:Socket -> @acc:0xdc8b9e3a3b68c4b632d5e290f8608324/src/wirespec.Got -> @len:U32 -> @buf:Array<U32> -> @more:(@_:Socket -> @_:0xdc8b9e3a3b68c4b632d5e290f8608324/src/wirespec.Got -> IO(String)) -> IO(String)
a receive's octets, or the server's close (no octets)
def wire.loop.un source · line 93 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @acc:0xdc8b9e3a3b68c4b632d5e290f8608324/src/wirespec.Got -> @r:Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>) -> @more:(@_:Socket -> @_:0xdc8b9e3a3b68c4b632d5e290f8608324/src/wirespec.Got -> IO(String)) -> IO(String)
a receive's outcome: a failure is the answer
def wire.loop source · line 107 · raw
@fuel:Nat -> @+secure:Bool -> @s:Socket -> @+host:String -> @+port:U32 -> @+ms:U32 -> @acc:0xdc8b9e3a3b68c4b632d5e290f8608324/src/wirespec.Got -> IO(String)
receive until wirespec.bend says the answer is whole
def wire.after.send source · line 122 · 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 136 · 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 145 · 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(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 158 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @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 170 · 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 181 · 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 194 · 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(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 208 · 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 219 · 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 230 · raw
@+secure:Bool -> @+ms:U32 -> @+host:String -> @+port:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(String)
the exchange once its octets are packed
def wire.run source · line 239 · raw
@+secure:Bool -> @+ms:U32 -> @+host:String -> @+port:U32 -> @+method:String -> @req:String -> @tail:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> 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 246 · raw
@secure:Bool -> @host:String -> @port:U32 -> @method:String -> @req:String -> @tail:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> 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 251 · raw
@secure:Bool -> @ms:U32 -> @host:String -> @port:U32 -> @method:String -> @req:String -> @tail:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(String)
the same exchange, bounded by a timeout in milliseconds