[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1 API

The following is the list of modules provided by this library.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1 (knots non-blocking)


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1.1 Procedures

Procedure: non-blocking-open-socket-for-uri uri KEY: #:verify-certificate?

Undocumented procedure.

Procedure: non-blocking-port port

Make PORT non-blocking and return it.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2 (knots parallelism)


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2.1 Macros

Macro: fibers-let x

Undocumented macro.

Macro: fibers-parallel x

Undocumented macro.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2.2 Procedures

Procedure: fiberize proc KEY: #:parallelism #:input-channel #:process-channel

Undocumented procedure.

Procedure: fibers-batch-for-each proc parallelism-limit . lists

Undocumented procedure.

Procedure: fibers-batch-map proc parallelism-limit . lists

Undocumented procedure.

Procedure: fibers-for-each proc . lists

Undocumented procedure.

Procedure: fibers-map proc . lists

Undocumented procedure.

Procedure: fibers-map-with-progress proc lists KEY: #:report

Undocumented procedure.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3 (knots promise)


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3.1 Macros

Macro: fibers-promise? x

Undocumented macro.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3.2 Procedures

Procedure: fibers-delay thunk

Undocumented procedure.

Procedure: fibers-force fp

Undocumented procedure.

Procedure: fibers-promise-reset fp

Undocumented procedure.

Procedure: fibers-promise-result-available? fp

Undocumented procedure.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.4 (knots queue)


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.4.1 Procedures

Procedure: spawn-queueing-fiber dest-channel

Undocumented procedure.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5 (knots resource-pool)


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5.1 Macros

Macro: resource-pool-channel x

Undocumented macro.

Macro: resource-pool-configuration x

Undocumented macro.

Macro: resource-pool-name x

Undocumented macro.

Macro: resource-pool? x

Undocumented macro.

Macro: with-resource-from-pool x

Undocumented macro.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5.2 Parameters

Parameter: resource-pool-default-timeout-handler

Default value:

#f

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5.3 Procedures

Procedure: call-with-resource-from-pool pool proc KEY: #:timeout #:timeout-handler #:max-waiters #:channel #:destroy-resource-on-exception?

Call PROC with a resource from POOL, blocking until a resource becomes available. Return the resource once PROC has returned.

Procedure: destroy-resource-pool pool

Undocumented procedure.

Procedure: make-resource-pool return-new-resource max-size KEY: #:min-size #:idle-seconds #:delay-logger #:duration-logger #:destructor #:lifetime #:scheduler #:name #:add-resources-parallelism #:default-checkout-timeout #:default-max-waiters

Undocumented procedure.

Procedure: make-resource-pool-destroy-resource-exception

Undocumented procedure.

Procedure: resource-pool-destroy-resource-exception? obj

Undocumented procedure.

Procedure: resource-pool-destroyed-error-pool obj

Undocumented procedure.

Procedure: resource-pool-destroyed-error? obj

Undocumented procedure.

Procedure: resource-pool-stats pool KEY: #:timeout

Undocumented procedure.

Procedure: resource-pool-timeout-error-pool obj

Undocumented procedure.

Procedure: resource-pool-timeout-error? obj

Undocumented procedure.

Procedure: resource-pool-too-many-waiters-error-pool obj

Undocumented procedure.

Procedure: resource-pool-too-many-waiters-error-waiters-count obj

Undocumented procedure.

Procedure: resource-pool-too-many-waiters-error? obj

Undocumented procedure.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5.4 Record Types

Record type: &resource-pool-destroy-resource

This record type has the following fields:

Record type: &resource-pool-destroyed

This record type has the following fields:

Record type: &resource-pool-timeout

This record type has the following fields:

Record type: &resource-pool-too-many-waiters

This record type has the following fields:


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.6 (knots thread-pool)


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.6.1 Macros

Macro: fixed-size-thread-pool-channel x

Undocumented macro.

Macro: fixed-size-thread-pool-current-procedures x

Undocumented macro.

Macro: fixed-size-thread-pool? x

Undocumented macro.

Macro: thread-pool-resource-pool x

Undocumented macro.

Macro: thread-pool? x

Undocumented macro.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.6.2 Procedures

Procedure: call-with-thread thread-pool proc KEY: #:duration-logger #:checkout-timeout #:channel #:destroy-thread-on-exception? #:max-waiters

Send PROC to the thread pool through CHANNEL. Return the result of PROC. If already in the thread pool, call PROC immediately.

Procedure: destroy-thread-pool pool

Undocumented procedure.

Procedure: make-fixed-size-thread-pool size KEY: #:thread-initializer #:thread-destructor #:delay-logger #:duration-logger #:thread-lifetime #:expire-on-exception? #:name #:use-default-io-waiters? #:default-checkout-timeout

Undocumented procedure.

Procedure: make-thread-pool max-size KEY: #:min-size #:scheduler #:thread-initializer #:thread-destructor #:delay-logger #:duration-logger #:thread-lifetime #:expire-on-exception? #:name #:use-default-io-waiters? #:default-checkout-timeout

Return a channel used to offload work to a dedicated thread. ARGS are the arguments of the thread pool procedure.

Procedure: set-thread-name name

Set the name of the calling thread to NAME. NAME is truncated to 15 bytes.

Procedure: thread-name

Return the name of the calling thread as a string.

Procedure: thread-pool-arguments-parameter pool

Undocumented procedure.

Procedure: thread-pool-default-checkout-timeout pool

Undocumented procedure.

Procedure: thread-pool-timeout-error-pool obj

Undocumented procedure.

Procedure: thread-pool-timeout-error? obj

Undocumented procedure.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.6.3 Record Types

Record type: &thread-pool-timeout-error

This record type has the following fields:


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.7 (knots timeout)


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.7.1 Procedures

Procedure: port-read-timeout-error? obj

Undocumented procedure.

Procedure: port-timeout-error? obj

Undocumented procedure.

Procedure: port-write-timeout-error? obj

Undocumented procedure.

Procedure: wait-until-port-readable-operation port

Make an operation that will succeed when PORT is readable.

Procedure: wait-until-port-writable-operation port

Make an operation that will succeed when PORT is writable.

Procedure: with-fibers-timeout thunk KEY: #:timeout #:on-timeout

Undocumented procedure.

Procedure: with-port-timeouts thunk KEY: #:timeout #:read-timeout #:write-timeout

Undocumented procedure.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.7.2 Record Types

Record type: &port-read-timeout-error

This record type has the following fields:

Record type: &port-timeout-error

This record type has the following fields:

Record type: &port-write-timeout-error

This record type has the following fields:


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.8 (knots web-server)


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.8.1 Macros

Macro: web-server-port x

Undocumented macro.

Macro: web-server-socket x

Undocumented macro.

Macro: web-server? x

Undocumented macro.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.8.2 Procedures

Procedure: default-write-response-exception-handler exn request

Undocumented procedure.

Procedure: make-chunked-output-port/knots port KEY: #:keep-alive? #:buffering

Returns a new port which translates non-encoded data into a HTTP chunked transfer encoded data and writes this to PORT. Data written to this port is buffered until the port is flushed, at which point it is all sent as one chunk. The port will otherwise be flushed every BUFFERING bytes, which defaults to 1200. Take care to close the port when done, as it will output the remaining data, and encode the final zero chunk. When the port is closed it will also close PORT, unless KEEP-ALIVE? is true.

Procedure: read-request-body/knots r

Undocumented procedure.

Procedure: request-body-ended-prematurely-error? obj

Undocumented procedure.

Procedure: request-body-port/knots r

Undocumented procedure.

Procedure: run-knots-web-server handler KEY: #:host #:family #:addr #:port #:socket #:read-request-exception-handler #:write-response-exception-handler #:connection-idle-timeout #:connection-buffer-size

Run the knots web server.

HANDLER should be a procedure that takes one argument, the HTTP request and returns two values, the response and response body.

For example, here is a simple "Hello, World!" server:

 (define (handler request)
   (let ((body (read-request-body request)))
     (values '((content-type . (text/plain)))
             "Hello, World!")))
 (run-knots-web-server handler)

The response and body will be run through ‘sanitize-response’ before sending back to the client.

Procedure: sanitize-response request response body

"Sanitize" the given response and body, making them appropriate for the given request.

As a convenience to web handler authors, RESPONSE may be given as an alist of headers, in which case it is used to construct a default response. Ensures that the response version corresponds to the request version. If BODY is a string, encodes the string to a bytevector, in an encoding appropriate for RESPONSE. Adds a ‘content-length’ and ‘content-type’ header, as necessary.

If BODY is a procedure, it is called with a port as an argument, and the output collected as a bytevector. In the future we might try to instead use a compressing, chunk-encoded port, and call this procedure later, in the write-client procedure. Authors are advised not to rely on the procedure being called at any particular time.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.8.3 Record Types

Record type: &request-body-ended-prematurely

This record type has the following fields:


[Top] [Contents] [Index] [ ? ]

About This Document

This document was generated on June 24, 2025 using texi2html 5.0.

The buttons in the navigation panels have the following meaning:

Button Name Go to From 1.2.3 go to
[ << ] FastBack Beginning of this chapter or previous chapter 1
[ < ] Back Previous section in reading order 1.2.2
[ Up ] Up Up section 1.2
[ > ] Forward Next section in reading order 1.2.4
[ >> ] FastForward Next chapter 2
[Top] Top Cover (top) of document  
[Contents] Contents Table of contents  
[Index] Index Index  
[ ? ] About About (help)  

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:


This document was generated on June 24, 2025 using texi2html 5.0.