UnixStream
buffered
(Fn [UnixStream] BufReader)
wraps this UnixStream in a BufReader for buffered I/O. Takes ownership of the stream — the BufReader will close it when deleted.
(match (UnixStream.connect "/tmp/my.sock")
(Result.Success s)
(let [br (UnixStream.buffered s)]
(do
(BufReader.write &br "hello\n")
(ignore (BufReader.flush &br))
(match (BufReader.read-line &br)
(Result.Success line) (println* &line)
_ ())
(BufReader.delete br)))
_ ())
connect
(Fn [(Ref String a)] (Result UnixStream String))
(connect path)
connects to a Unix domain socket at the given path. Returns (Result UnixStream String).
read
(Fn [(Ref UnixStream a)] (Result String b))
(read stream)
reads up to 4096 bytes from the stream. Returns the data as a string, or an error. Returns an empty string on connection close.
read-append
(Fn [(Ref UnixStream a), (Ref (Array Byte) b)] (Result Int String))
(read-append stream buf)
reads from the stream and appends to an existing byte buffer. Returns bytes read (0 = connection closed), or an error.
read-bytes
(Fn [(Ref UnixStream a)] (Result (Array Byte) b))
(read-bytes stream)
reads up to 4096 bytes as a byte array.
send
(Fn [(Ref UnixStream a), (Ref String b)] (Result Int String))
(send stream msg)
sends a string over the stream. Returns bytes sent or an error.
send-bytes
(Fn [(Ref UnixStream a), (Ref (Array Byte) b)] (Result Int String))
(send-bytes stream data)
sends binary data over the stream. Returns bytes sent or an error.
shutdown
(Fn [(Ref UnixStream a), Int] ())
(shutdown stream how)
shuts down the stream. 0 = reads, 1 = writes, 2 = both.
with-stream
Macro
(with-stream name path :rest forms)
connects, executes forms, then closes the stream.