Module Styx.Server

The Server functor produces a 9P server from a Filesystem implementation.

The resulting module provides a server that serves 9P on a single connection. Multiple sessions are supported, but all sessions on the same connection share a single request limit.

The server operates in a largely single-threaded fashion, answering each request in order they are received. An exception is made for read and write requests, which are completed concurrently up to a configured queue depth (see ServerConfig for details).

No caching is done; every request will result in a call to the appropriate functions defined in Filesystem. Any desired caching must be implemented by FS itself.

Two fixed-size ring buffers are allocated to store incoming requests and outgoing responses. Messages in these buffers are not copied, but passed directly to the relevant callbacks in FS. During normal operation the server should use a constant amount of memory and perform very few allocations.

Parameters

Signature

type t

An instance of a 9P server

val run : fs:FS.t -> config:ServerConfig.t -> r:Unix.file_descr -> w:Unix.file_descr -> (unit, string) Stdlib.result

run initializes a new 9P server using config and filesystem, then runs the server, reading requests from r and writing responses to w, which may be the same or different file descriptors. run will run as long as both file descriptors remain open; to initiate a graceful shutdown, close rd.

If a fatal error is encountered, such as a malformed 9P message, run will terminate with a relevant error message after closing both file descriptors.

run will spawn a small number of additional threads which are used to handle I/O system calls concurrently, up to config.queue_depth.