Version 0.1
A very serious, industrial web framework in Tcl
 All Data Structures Namespaces Files Functions Variables Pages
Public Member Functions | Static Public Attributes
tanzer::session Class Reference

Public Member Functions

 constructor newServer newSock newProto
 monitor args
 error e
 cleanup args
 delegate args
 handle event
 request args
 config args
 write data
 bind eventType args
 reset ?event?
 send newResponse
 response args
 redirect uri
 keepalive args

Static Public Attributes


Constructor & Destructor Documentation

tanzer::session::constructor   newServer newSock newProto  

Create a new session handler to service an incoming request from server $newServer, inbound from channel $newSock, in the request protocol specified in $newProto.

Member Function Documentation

tanzer::session::bind   eventType args  

Using [chan event] on the current session's socket, bind all events of the type specified in $eventType to the command specified in $args.

tanzer::session::cleanup   args  

When $args is not empty, specify a callback to be dispatched whenever the current session handler is ready to clean any associated state and prepare to handle a new request, or to end. Otherwise, when no arguments are specified, any previously provided cleanup callbacks are executed precisely once, in the order in which they were registered, and are subsequently cleared.

Each successive call to this method results in another cleanup task queued to be executed upon session termination.

If -reset is specified in the first argument, then all cleanup tasks are cleared for the current session.

tanzer::session::config   args  

Return the value of configuration variable $name as set at object instantiation time. If $value is also provided, then set or replace the configuration option $name with $value. Otherwise, return a list of key-value pairs containing all current configuration data.

tanzer::session::delegate   args  

Delegate events to a different request handler as specified in $args.


Returns true if no data has been parsed for the current request, and if the remote socket has reached end-of-file status.

tanzer::session::error   e  

Report the error $e to the server, and end the current session, resulting in the destruction of the current object.

tanzer::session::handle   event  

Handle the read or write event as specified in $event. Upon the receipt of read events, continue to buffer and retain request data until enough data is present to parse a full request message, route the request to the appropriate request handler, and delegate all subsequent write events to the new handler.

Event handlers are called with the following form when dispatching read events:

1 {*}$handler $event $session $data

Event handlers are called with the following form when dispatching write events:

1 {*}$handler $event $session
tanzer::session::keepalive   args  

Return true if the current session is to be kept alive. If a boolean argument is provided, the keepalive setting is set to its value.

tanzer::session::monitor   args  

Install the watchdog timer for the current session.


Clear any state associated with the session's current request, and prepare the session handler to handle a new request.


Read a block of data from the current session's socket. The read buffer size is the readsize configuration option in tanzer::server.

tanzer::session::redirect   uri  

Send a 301 Redirect to the client, referring them to the new location $uri.

tanzer::session::request   args  

When no arguments are specified in $args, return a reference to the most recent request parsed by the current session handler. Otherwise, if the flag -new is specified, then create a new request object to parse an inbound request of the protocol for which this session handler is servicing, save the reference to the new request object, and return that.

tanzer::session::reset   ?event?  

Reset the socket attached to the current session to monitor for the event type specified in $event as per the following:

  • read
  • write
  • any

    Implies both read and write

  • none

    Implies neither read nor write

I/O readiness events will be dispatched by the server once again, which shall then dispatch the handler specified in the last call to the method tanzer::session::delegate. If either read or write is not specified explicitly or implicitly by any, then I/O event response is canceled for that event type.

$event defaults to any if it is not specified.


If a response was previously queued by a call to tanzer::session::response, then send that response using tanzer::session::send.


Returns true if a response has been sent for the last request handled by this session.

tanzer::session::response   args  

This method yields different behaviors when called in any of the following ways.

  • [$session response]

    Return the last response recorded for this session, if any.

  • [$session response -new $response]

    Record the new response provided in $response in the current session.

  • [$session response $args]

    Call the response object command last recorded for the current session, passing the arguments in $args in expanded form with {*} prepended. The result of this response command invocation is returned.


Search through the server's route table in order for the first route that matches the current request, make note of that route, and return the route to the caller. If a route has already been selected for the current request, then return that immediately. Otherwise, if no suitable route can be matched to the current request, then throw a 404 error.

tanzer::session::send   newResponse  

Send the response object in $newResponse to the client. If the session handler has determined that the session can and should be kept alive, then a Connection: header is set with the Keep-Alive value, otherwise Close. Then, all headers are sent down the wire, and any response data buffered in $newResponse is sent as well.

After sending the response, $newResponse is kept by the session handler for future reference by callers, and log the current session's request and new response with the server.


Return a reference to the server for which the current session handler is open.


Return a reference to the socket channel the current request handler is reading from and writing to.

tanzer::session::write   data  

Write $data to the current session's socket, and return the number of bytes written. If the session has a response object already prepared, and that response contains a Transfer-Encoding: header which indicates the chunked encoding, then $data will be written to the remote end in a chunked transfer encoded fragment.

The documentation for this class was generated from the following file: