A namespace of utility functions for integrating streams into Teensyp.
A namespace of utility functions for integrating streams into Teensyp.
(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.
(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.(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.
(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.
(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.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |