UnixStream

buffered

external

(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)))
  _ ())

close

external

(Fn [UnixStream] ())

closes the stream, releasing the file descriptor.

connect

defn

(Fn [(Ref String a)] (Result UnixStream String))

                        (connect path)
                    

connects to a Unix domain socket at the given path. Returns (Result UnixStream String).

copy

external

(Fn [(Ref UnixStream a)] UnixStream)

peer-path

external

(Fn [(Ref UnixStream a)] String)

returns the path of the remote peer socket.

poll-fd

defn

(Fn [(Ref UnixStream a)] Int)

                        (poll-fd s)
                    

read

defn

(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

defn

(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

defn

(Fn [(Ref UnixStream a)] (Result (Array Byte) b))

                        (read-bytes stream)
                    

reads up to 4096 bytes as a byte array.

send

defn

(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

defn

(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.

set-timeout

external

(Fn [(Ref UnixStream a), Int] ())

sets read and write timeouts in seconds.

shutdown

defn

(Fn [(Ref UnixStream a), Int] ())

                        (shutdown stream how)
                    

shuts down the stream. 0 = reads, 1 = writes, 2 = both.

shutdown-

external

(Fn [(Ref UnixStream a), Int] ())

shutdown-read

external

(Fn [(Ref UnixStream a)] ())

shuts down the read side of the stream.

shutdown-write

external

(Fn [(Ref UnixStream a)] ())

shuts down the write side of the stream.

with-stream

macro

Macro

                        (with-stream name path :rest forms)
                    

connects, executes forms, then closes the stream.