On this page:
1.1 Dispatching Server Signatures
dispatch-server^
serve
serve-ports
dispatch-server-connect^
port->real-ports
dispatch-server-config^
port
listen-ip
max-waiting
initial-connection-timeout
read-request
dispatch
1.2 Dispatching Server Unit
dispatch-server-with-[email protected]
dispatch-[email protected]
1.3 Threads and Custodians

1 Dispatching Server

The Web Server is just a configuration of a dispatching server.

1.1 Dispatching Server Signatures

 (require web-server/private/dispatch-server-sig)
  package: web-server-lib
The web-server/private/dispatch-server-sig library provides two signatures.

signature

dispatch-server^ : signature

The dispatch-server^ signature is an alias for web-server^.

procedure

(serve)

  (->* () (#:confirmation-channel (or/c false/c async-channel?)) (-> void))
Runs the server—the confirmation channel will be send an exception if one occurs starting the server or the port number if there is none—and returns a procedure that shuts down the server.

procedure

(serve-ports ip op)  void

  ip : input-port?
  op : output-port?
Serves a single connection represented by the ports ip and op.

signature

dispatch-server-connect^ : signature

The dispatch-server-connect^ signature abstracts the conversion of connection ports (e.g., to implement SSL) as used by the dispatch server.

procedure

(port->real-ports ip op)  
input-port? output-port?
  ip : input-port?
  op : output-port?
Converts connection ports as necessary.

The connection ports are normally TCP ports, but an alternate implementation of tcp^ linked to the dispatcher can supply different kinds of ports.

signature

dispatch-server-config^ : signature

Specifies the port to serve on.
Passed to tcp-listen.
Passed to tcp-listen.
Specifies the initial timeout given to a connection.

procedure

(read-request c p port-addresses)  
any/c boolean?
  c : connection?
  p : listen-port-number?
  port-addresses : (input-port? . -> . (values string? string?))
Defines the way the server reads requests off connections to be passed to dispatch.
How to handle requests.

1.2 Dispatching Server Unit

 (require web-server/private/dispatch-server-unit)
  package: web-server-lib
The web-server/private/dispatch-server-unit module provides the unit that actually implements a dispatching server.

value

[email protected]

 : 
(unit/c (import tcp^
                dispatch-server-connect^
                dispatch-server-config^)
        (export dispatch-server^))
Runs the dispatching server config in a very basic way, except that it uses Connection Manager to manage connections.

Added in version 1.1 of package web-server-lib.

value

[email protected] : 
(unit/c (import tcp^
                dispatch-server-config^)
        (export dispatch-server^))

1.3 Threads and Custodians

The dispatching server runs in a dedicated thread. Every time a connection is initiated, a new thread is started to handle it. Connection threads are created inside a dedicated custodian that is a child of the server’s custodian. When the server is used to provide servlets, each servlet also receives a new custodian that is a child of the server’s custodian not the connection custodian.