~/bend-docscommunity

conn.bend relies on unsafe/foreign

raw source on the hub · import 0xd6fc55bf65b187fec4175f80d08c165a/conn.bend as Conn

What the RTSP and RTMP clients share: a connection's opening, reads, writes and failures in continuation style (the next step is handed the socket back). A step that fails closes the socket and ends in Fail, whatever the result T was to be. The sockets are net.c's: hosts by name, TLS, reads with a deadline.

4 imports
import Base
import ./bytes.bend as B
import ./net.bend as X
import ./opts.bend as E

Definitions

def Res source · line 10 · raw

@T:Type -> Type

def Recv source · line 13 · raw

Type

def Sent source · line 16 · raw

Type

def Conn.fail source · line 20 · raw

@-T:Type -> @s:Socket -> @why:0xd6fc55bf65b187fec4175f80d08c165a/opts.Why -> @code:U32 -> @msg:String -> IO(Res(T))

The socket closed and the error given.

def Conn.got.n source · line 25 · raw

@-T:Type -> @s:Socket -> @buf:List<&2, U32> -> @+piece:List<&2, U32> -> @more:(@_:Socket -> @_:List<&2, U32> -> @_:U32 -> IO(Res(T))) -> IO(Res(T))

def Conn.got source · line 29 · raw

@-T:Type -> @m:Recv -> @buf:List<&2, U32> -> @more:(@_:Socket -> @_:List<&2, U32> -> @_:U32 -> IO(Res(T))) -> IO(Res(T))

def Conn.recv.n source · line 44 · raw

@-T:Type -> @s:Socket -> @ms:U32 -> @buf:List<&2, U32> -> @more:(@_:Socket -> @_:List<&2, U32> -> @_:U32 -> IO(Res(T))) -> IO(Res(T))

More bytes onto the buffer, waiting at most ms, and how many came.

def Conn.recv source · line 51 · raw

@-T:Type -> @s:Socket -> @ms:U32 -> @buf:List<&2, U32> -> @more:(@_:Socket -> @_:List<&2, U32> -> IO(Res(T))) -> IO(Res(T))

More bytes onto the buffer, waiting at most ms.

def Conn.sent source · line 55 · raw

@-T:Type -> @m:Sent -> @k:(@_:Socket -> IO(Res(T))) -> IO(Res(T))

def Conn.send source · line 64 · raw

@-T:Type -> @s:Socket -> @bs:List<&2, U32> -> @k:(@_:Socket -> IO(Res(T))) -> IO(Res(T))

def Conn.say source · line 71 · raw

@-T:Type -> @s:Socket -> @text:String -> @k:(@_:Socket -> IO(Res(T))) -> IO(Res(T))

Text as bytes (a request's lines are ASCII).

def Conn.shut.end source · line 74 · raw

@m:Recv -> @go:(@_:Socket -> IO(Unit)) -> IO(Unit)

def Conn.shut.drain source · line 87 · raw

@turns:Nat -> @s:Socket -> @+ms:U32 -> IO(Unit)

What the server still sends is read and dropped, for at most turns reads, until it is quiet for ms or it closes; then the socket is closed. A server gets to answer the last word and to free the session before the connection goes: some refuse a new session while the old one is still theirs.

def Conn.shut.sent source · line 96 · raw

@m:Sent -> @ms:U32 -> IO(Unit)

def Conn.shut source · line 106 · raw

@s:Socket -> @last:List<&2, U32> -> @ms:U32 -> IO(Unit)

A last word to the server, then the socket closed once the server has been quiet for ms (or at once, with no last word).

def Conn.secured source · line 115 · raw

@-T:Type -> @m:Sent -> @k:(@_:Socket -> IO(Res(T))) -> IO(Res(T))

def Conn.opened source · line 124 · raw

@-T:Type -> @r:Result<&1, &1, Pair(U32, String), Socket> -> @tls:Bool -> @host:String -> @ca:String -> @k:(@_:Socket -> IO(Res(T))) -> IO(Res(T))

def Conn.open source · line 140 · raw

@-T:Type -> @+host:String -> @port:U32 -> @tls:Bool -> @ca:String -> @k:(@_:Socket -> IO(Res(T))) -> IO(Res(T))

A connection to host:port, under TLS when asked: the certificate is checked against the host's name and the system's store, or the PEM file ca names (for a server with a certificate of its own making).