ns_sls - Socket local storage for connections
TABLE OF CONTENTS
SYNOPSIS
DESCRIPTION
COMMANDS
EXAMPLES
SEE ALSO
KEYWORDS
|
The underlying TCP socket used by a NaviServer connection may be kept open and reused for further connections, e.g. during HTTP keep-alive . The ns_sls commands associate data with the socket, which will be available to future connections on that socket. The data is freed automatically when the socket closes.
The data is saved as a string, both for thread safety and to allow easy sharing with C code using the Ns_SlsGetKeyed and Ns_SlsSetKeyed API.
Per-socket data is often used by socket drivers and protocol drivers. It may be tempting to save HTTP session data here, but beware: intermediate HTTP proxies may send multiple, unrelated requests using a single TCP socket. You may be looking for Ns_Cls -- connection local storage.
All the ns_sls commands require an active connection.
Log the number of connections handled by a single TCP socket:
set n [ns_sls get connections 0]
incr n
ns_sls set connections $n
if {$n > 1} {
ns_log notice connections: $n
}
|
(NB: Does not include C module data set via the Ns_SlsSet API)
foreach {k v} [ns_sls array] {
ns_log notice sls: $k: $v
}
|
Ns_Cls, Ns_Sls