TlsStream
TlsStream
a
is a TLS-encrypted TCP stream using OpenSSL.
Usage
(match (TlsStream.connect "example.com" 443)
(Result.Success s)
(do
(ignore (TlsStream.send &s "GET / HTTP/1.1
Host: example.com
Connection: close
"))
(match (TlsStream.read &s)
(Result.Success msg) (println* &msg)
(Result.Error e) (IO.errorln &e))
(TlsStream.close s))
(Result.Error e) (IO.errorln &e))
close!
(Fn [(Ref TlsStream a)] ())
closes the TLS stream by reference. Sets fd to -1 to prevent double-close.
connect
(Fn [(Ref String a), Int] (Result TlsStream String))
(connect host port)
connects to a remote host over TLS. Returns (Result TlsStream String).
read
(Fn [(Ref TlsStream a)] (Result String b))
(read stream)
reads up to 4096 bytes from the TLS stream. Returns the data as a string. Returns an empty string on connection close.
read-append
(Fn [(Ref TlsStream a), (Ref (Array Byte) b)] (Result Int String))
(read-append stream buf)
reads from the TLS stream and appends to an existing byte buffer. Returns bytes read (0 = connection closed), or an error.
read-bytes
(Fn [(Ref TlsStream a)] (Result (Array Byte) b))
(read-bytes stream)
reads up to 4096 bytes as a byte array.
send
(Fn [(Ref TlsStream a), (Ref String b)] (Result Int String))
(send stream msg)
sends a string over the TLS stream. Returns bytes sent or an error.
send-bytes
(Fn [(Ref TlsStream a), (Ref (Array Byte) b)] (Result Int String))
(send-bytes stream data)
sends binary data over the TLS stream. Returns bytes sent or an error.
with-stream
Macro
(with-stream name host port :rest forms)
connects over TLS, executes forms, then closes the stream.