Liking cljdoc? Tell your friends :D

teensyp.stream

A namespace of utility functions for integrating streams into Teensyp.

A namespace of utility functions for integrating streams into Teensyp.
raw docstring

input-streamclj

(input-stream readf)
(input-stream readf closef)

Create an InputStream from a read and optional close function. The read function maps to the .read method on the InputStream class and takes 3 arguments: a byte array to receive the data, an offset and a length. The read function should return the number of bytes read, or -1 if the stream is closed. The close function maps to the .close method and takes zero arguments.

Create an InputStream from a read and optional close function. The read
function maps to the `.read` method on the InputStream class and takes 3
arguments: a byte array to receive the data, an offset and a length. The read
function should return the number of bytes read, or -1 if the stream is
closed. The close function maps to the `.close` method and takes zero
arguments.
sourceraw docstring

input-stream-handlerclj

(input-stream-handler f)
(input-stream-handler f
                      {:keys [executor on-close read-buffer-size]
                       :or {executor (new-default-executor)
                            on-close (fn [_sock])
                            read-buffer-size 8192}})

Create a TeensyP server handler from a function f that takes an InputStream and a TeensyP Socket as arguments. The function will be executed in a separate thread when the 1-argument accept arity of the handler is called.

Accepts an options map with the following keys:

:executor - an executor for running the supplied function, defaults to a fixed thread pool of 32 threads :on-close - a function called when the InputStream is closed, takes a single socket argument :read-buffer-size - the size in bytes of the read buffer, defaults to 8K

Triggering the 2-argument close arity of the handler will close the associated InputStream.

Create a TeensyP server handler from a function f that takes an InputStream
and a TeensyP Socket as arguments. The function will be executed in a
separate thread when the 1-argument accept arity of the handler is called.

Accepts an options map with the following keys:

:executor - an executor for running the supplied function, defaults to a
            fixed thread pool of 32 threads
:on-close - a function called when the InputStream is closed, takes a
            single socket argument
:read-buffer-size - the size in bytes of the read buffer, defaults to 8K

Triggering the 2-argument close arity of the handler will close the
associated InputStream.
sourceraw docstring

output-streamclj

(output-stream writef)
(output-stream writef closef)
(output-stream writef closef flushf)

Create an OutputStream from a write function and optional close and flush functions. The write function maps to the .write method on the OutputStream class and takes 3 arguments: a byte array with the data to send, an offset and a length. The close function maps to the .close method and takes zero arguments. Similarly the flush function maps to the .flush method and also takes zero arguments.

Create an OutputStream from a write function and optional close and
flush functions. The write function maps to the `.write` method on the
OutputStream class and takes 3 arguments: a byte array with the data to send,
an offset and a length. The close function maps to the `.close` method and
takes zero arguments. Similarly the flush function maps to the `.flush`
method and also takes zero arguments.
sourceraw docstring

socket->output-streamclj

(socket->output-stream socket)
(socket->output-stream socket {:keys [on-close]})

Create a blocking OutputStream from a TeensyP Socket. Writing to the stream will queue a write to the socket, and block until that write had been sent.

Closing the stream will close the socket by default, but this behavior can be overridden by supplying a custom close function that takes the socket as its argument, via the :on-close option.

Create a blocking OutputStream from a TeensyP Socket. Writing to the stream
will queue a write to the socket, and block until that write had been sent.

Closing the stream will close the socket by default, but this behavior can be
overridden by supplying a custom close function that takes the socket as
its argument, via the :on-close option.
sourceraw docstring

stream-handlerclj

(stream-handler f)
(stream-handler f options)

Create a Teensyp server handler from a function that takes an InputStream and OutputStream as arguments. This combines the socket->output-stream and input-stream-handler functions.

Accepts an options map with the following keys:

:executor - an executor for running the handler function, defaults to a fixed thread pool of 32 threads :read-buffer-size - the size in bytes of the read buffer, defaults to 8K

The socket will be closed when both the InputStream and OutputStream are closed, or when the 'close' 2-arity of the returned function is called. Closing the OutputStream will prevent further writes, and closing the InputStream will prevent further reads. Data received after the InputStream has been closed will be silently dropped.

Create a Teensyp server handler from a function that takes an InputStream
and OutputStream as arguments. This combines the [[socket->output-stream]]
and [[input-stream-handler]] functions.

Accepts an options map with the following keys:

:executor - an executor for running the handler function, defaults to a fixed
            thread pool of 32 threads
:read-buffer-size - the size in bytes of the read buffer, defaults to 8K

The socket will be closed when both the InputStream and OutputStream are
closed, or when the 'close' 2-arity of the returned function is called.
Closing the OutputStream will prevent further writes, and closing the
InputStream will prevent further reads. Data received after the InputStream
has been closed will be silently dropped.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close