Liking cljdoc? Tell your friends :D

teensyp.server


CLOSEclj

A unique identifier that can be passed to the write function of a handler in order to close the connection.

A unique identifier that can be passed to the write function of a handler
in order to close the connection.
sourceraw docstring

PAUSE-READSclj

A unique identifier that can be passed to the write function of a handler in order to pause reads. See: RESUME-READS.

A unique identifier that can be passed to the write function of a handler
in order to pause reads. See: RESUME-READS.
sourceraw docstring

RESUME-READSclj

A unique identifier that can be passed to the write function of a handler in order to pause reads. See: RESUME-READS.

A unique identifier that can be passed to the write function of a handler
in order to pause reads. See: RESUME-READS.
sourceraw docstring

start-serverclj

(start-server {:keys [port executor] :as opts})

Start a TCP server with the supplied map of options:

  • :port - the port number to listen on (mandatory)
  • :handler - a handler function (mandatory, see below)
  • :executor - a custom ExecutorService to supply worker threads
  • :buffer-size - the buffer size in bytes (default 8K)

The handler function must have three arities:

(fn handler
  ([write] initial-state)           ;; on socket accept
  ([state buffer write] new-state)  ;; on socket read data
  ([state exception]))              ;; on socket close

The buffer is a java.nio.ByteBuffer instance, and write is a function that takes a buffer as an argument and will queue it to send to the client. To close the channel, pass teensyp.server/CLOSE to the write function.

The state is a custom data structure that is returned when the accept or read arities are triggered. A different state is associated with each connection.

When closing, the exception may contain the exception that terminated the channel, or nil if the channel were terminated gracefully.

The handler function is guaranteed to execute in serial per channel. That is, the accept will always be first, the close will always be last, and reads will always be sequential.

Start a TCP server with the supplied map of options:

- `:port` - the port number to listen on (mandatory)
- `:handler` - a handler function (mandatory, see below)
- `:executor` - a custom ExecutorService to supply worker threads
- `:buffer-size` - the buffer size in bytes (default 8K)

The handler function must have three arities:

    (fn handler
      ([write] initial-state)           ;; on socket accept
      ([state buffer write] new-state)  ;; on socket read data
      ([state exception]))              ;; on socket close

The `buffer` is a java.nio.ByteBuffer instance, and `write` is a function
that takes a buffer as an argument and will queue it to send to the client.
To close the channel, pass `teensyp.server/CLOSE` to the write function.

The `state` is a custom data structure that is returned when the accept or
read arities are triggered. A different state is associated with each
connection.

When closing, the `exception` may contain the exception that terminated the
channel, or `nil` if the channel were terminated gracefully.

The handler function is guaranteed to execute in serial per channel. That is,
the accept will always be first, the close will always be last, and reads
will always be sequential.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close