A TCP server framework, like Hunchentoot for TCP.
1Weft, a simple server frameworkWeft is a simple network server framework, which handles the detailsof listening for connections and handing client connections off toworkers. Work management is done independently of the networkingstuff, and work managers can be created to use whatever strategy isappropriate for a server.
Unlike lisp-network-server, Weft does not aim to be an inetd-alike. This simplifies some of the code and allows services to use different work management strategies. At the moment, lisp-network-service's caveats about re-defining handlers still hold.
serverclass is the top-level object for the library, andholds all the pieces necessary to run the server. When created, aclient must supply or set the
Optionally, clients may set the
:manager slot, which is the task
manager for the server. Clients may also set the
slot, which will cause the server to refuse new connections when
that many concurrent connections are open. The same limit can be
applied to the threaded task manager with the
:limit option. If a
manager is supplied with
:manager, the manager's limit will take
2.1.1server-task-managerReturns or sets the task manager for the server.
2.1.2server-socketReturns or sets the
usocket:stream-server-usocketthe server islistening on. This will be NIL if the server isn't currentlyrunning, or an open socket if it's been started.
2.1.3server-addressReturns or sets the address the server will listen on (the servermust be restarted in order for any change to take affect). Can beany value acceptable to
2.1.4server-portReturns or sets the port the server will listen on (a restart isrequired for changes to take effect). Can be any value acceptableto
2.1.5server-connection-handlerReturns or sets the connection-handler function for theserver. This function will be called by a wrapper that ensures theclient socket is closed when the handler exits. The handler willbe called with a
usocket:stream-usocketobject and any
:argsarguments set when the server object was created.
runfunction is used to start the server.
run's exactbehavior will depend on the task manager used: with the defaultthreaded task manager,
runreturns immediately, but with asingle-threaded manager it would almost certainly block.
stopshuts the server down, including any open clientconnections. With some task managers client connection shutdown maybe cooperative, so this function may be blocked for sometime.
stopreturns once the server has been completely shut down.
stop, but only shuts down the listeningsocket. Client connections are allowed to continue until they areclosed by the clients.
stop-acceptingreturns as soon as thelistening socket has been shut down.
3Default ManagerWeft provides a thread-per-connection implementation of the taskmanager (
threaded-task-manager), which is used by default. Tasksbeing run on this manager obey the following protocol:
3.1shutdownThe special variable
*shutdown*will be set to
twhen thetask should be shut down. The task must make it's own arrangementsto check
*shutdown*periodically and shut down whenappropriate.
3.2thread-shutdownIf a task wants to signal that it should be shut down, it may set
tand let it's own handlers take care of it, orsignal a condition of type
thread-shutdown. The condition avoidsany delay in checking
*shutdown*, and will be handled by the taskmanager immediately.
4Task Manager ProtocolWeft can make use of any object that implements the task manager tohandle client connections. The task manager protocol consists of thefollowing functions:
(add-task manager thunk)
add-tasktakes a thunk to be run as a task and adds it to thegiven manager, returning a unique id for the task.
add-taskneednot start a task immediately, but it should at least be queued forlater execution.
If a manager has a limit on the maximum number of concurrent tasks
that can be running,
add-task should signal an error of type
(remove-task manager id)
remove-tasktakes a unique id as returned by
add-task, andremoves the corresponding task from the manager, ifpresent.
tif the task was found andremoved,
(stop-task manager id)
stop-tasktakes a unique task id and shuts that task down, ifpresent.
stop-taskreturns once the task has been stopped, whichmay be some time later if task shutdown is cooperative.