On this page:
connection
connection-manager?
start-connection-manager
new-connection
kill-connection!
adjust-connection-timeout!
reset-connection-timeout!

5.2 Connection Manager🔗ℹ

This module provides functionality for managing pairs of input and output ports. We have plans to allow a number of different strategies for doing this.

struct

(struct connection (timer i-port o-port custodian close?)
    #:extra-constructor-name make-connection)
  timer : timer?
  i-port : input-port?
  o-port : output-port?
  custodian : custodian?
  close? : boolean?
A connection is a pair of ports (i-port and o-port) that is ready to close after the current job if close? is #t. Resources associated with the connection should be allocated under custodian. The connection will last until timer triggers.

Construct connection instances using new-connection, which cooperates with connection managers. Constructing connections by other means (e.g. make-connection or struct-copy) may have undesirable consequences, such as circumventing safety limits.

Changed in version 1.6 of package web-server-lib: Deprecate construction other than via new-connection.

procedure

(connection-manager? v)  boolean?

  v : any/c

procedure

(start-connection-manager [#:safety-limits safety-limits])

  connection-manager?
  safety-limits : safety-limits?
   = (make-unlimited-safety-limits)
A connection manager is an opaque value, recognized by the predicate connection-manager?, which cooperates with new-connection to control the creation and behavior of connection instances. It encapsulates a timer manager (see Timers), safety limits policies, and other internal data. Use start-connection-manager to create a connection manager.

Note that, if the safety-limits argument is not given, the default safety limits value offers minimal protection against malicious or misbehaving clients and servlets: see make-unlimited-safety-limits. Most programs should not not use start-connection-manager or new-connection directly: higher-level interfaces, such as dispatch-server-with-connect@ and serve, incorporate connection management and provide more protections by default. The permissive default safety limits of start-connection-manager maximize backwards-compatability for low-level programs that use these functions directly. See the safety limits compatability note for more information.

Changed in version 1.6 of package web-server-lib: Added safety-limits argument.

procedure

(new-connection cm i-port o-port cust close?)  connection?

  cm : connection-manager?
  i-port : input-port?
  o-port : output-port?
  cust : custodian?
  close? : boolean?
(new-connection cm    
  timeout    
  i-port    
  o-port    
  cust    
  close?)  connection?
  cm : connection-manager?
  timeout : number?
  i-port : input-port?
  o-port : output-port?
  cust : custodian?
  close? : boolean?
Cooperates with the connection manager cm to construct a new connection instance. The connection is created with a timer that effectively calls kill-connection!. The initial timeout is determened by the safety limits encapsulated in cm.

The six-argument form with a timeout argument is provided for backwards compatability. In that case, timeout is used for the initial value of the connection’s timer, regardless of cm’s safety limits. Other aspects of the safety limits still apply to the resulting connection.

Changed in version 1.6 of package web-server-lib: Added five-argument form using cm’s safety limits instead of a timeout argument.

procedure

(kill-connection! c)  any

  c : connection?
Closes the ports associated with c, kills the timer, and shuts down the custodian.

procedure

(adjust-connection-timeout! c t)  any

  c : connection?
  t : number?
Calls increment-timer! with the timer behind c with t.

procedure

(reset-connection-timeout! c t)  any

  c : connection?
  t : number?
Calls reset-timer! with the timer behind c with t.

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