- serve inport outport handlersprocedure
The 9p-server module exports a single procedure, serve, which provides the 9p server protocol on a provided pair of ports (one for input, one for output). The caller must provide an alist mapping symbolic names of 9p protocol operations to closures that implement those operations. Some operations are optional, and default implementations will be used if they are not provided, but some are essential and must be provided or an error will be raised.
The 9p protocol is somewhat asynchronous; multiple requests may be submitted without the client waiting for responses, and the server may respond to open requests in any order. In order to support this, the handler procedures do not issue replies by returning a value, but by calling one of a number of closures they are passed as arguments. Most have a reply! argument to send a normal reply and an error! argument to send an error response, but there may be others, which will be discussed below.
Most handlers that originate from a 9p protocol message are passed the contents of the 9p request, which is a list, the format of which depends on the request.
The main exceptions are the initial version request that is part of the connection setup process, which does block until the handler directly returns the required value, and the disconnect request that is called when a connection is closed and has no reply. When the connection is closed, as soon as the disconnect handler returns, serve returns to its caller.