Skip to main content

Module server

Module server 

Source
Expand description

JSON-RPC server loop.

Accepts connections on a [tokio::net::TcpListener] or Unix socket and serves each with a task that reads length-prefixed JSON-RPC messages, dispatches them, and writes responses.

Framing: each message is a 4-byte big-endian length prefix followed by that many bytes of UTF-8 JSON. This is the same framing used by LSP / DAP and most production JSON-RPC daemons; it avoids the ambiguity of newline-delimited JSON when payloads contain embedded newlines.

Threading: the Confium engine holds Rc<dyn Any> plugin interfaces, which makes it !Send. The server therefore runs on a single [tokio::task::LocalSet] and keeps the engine behind Rc<RefCell<Confium>>. Connections are driven concurrently by the LocalSet’s cooperative scheduler; Confium access is serialized by the RefCell borrow. This is the right shape for a skeleton — the engine is single-threaded by construction (the C FFI assumes it), and moving to a multi-threaded actor model is a later optimization.

Structs§

Server
The daemon’s shared state: the engine, the dispatch table, and a shutdown signal.

Type Aliases§

SharedConfium
Type alias for the shared engine handle. Rc<RefCell<...>> because Confium is !Send (plugin interfaces are Rc<dyn Any>).