我发出一个问题,当我发出一个http :: getURL请求时,Tcl解释器的内存使用量增加了4KB。这就是我的所作所为:
sendCommand
的过程中发出请求。sendCommand
。清理命令似乎工作正常(我通过在清除令牌之后尝试访问令牌的状态数组进行检查,并且正如预期的那样,它不存在)。
我注意到对令牌(::http::1
,::http::2
等)的全局引用随着每个请求的增加而不断递增,即使它们已被清除。我觉得这很奇怪,但似乎只是http包的工作方式。
以下是sendCommand
程序和其中一个回调程序subscribeDevice
。代码在Linux环境(Angstrom)中运行。
#====================================================================================================
# sendCommand
#
# Desc: Sends a command to an HTTP server.
# Param: type - The type of HTTP request being made (GET, POST, PUT, no_options)
# url - The host url.
# query - The "payload" (For POST and PUT types only)
# callback - The procedure to call upon receiving the http response of the request.
#====================================================================================================
proc sendCommand {type url query {callbackProc "::callback::default"}} {
set token -1
switch -nocase $type {
"GET" {
if {$callbackProc == "::callback::getLatestEventID" || $callbackProc == "::callback::getEvents"} {
set token [::http::geturl $url -headers [list Authorization "Bearer $::auth::accessTokenCC"] -handler $callbackProc -timeout 8000]
} elseif {$callbackProc == "::callback::negotiateConnection"} {
set token [::http::geturl $url -headers [list Authorization "Bearer $::auth::accessToken"] -handler $callbackProc -timeout 15000]
} else {
set token [::http::geturl $url -headers [list Authorization "Bearer $::auth::accessToken" Cookie $::cookie] -handler $callbackProc -timeout 8000]
}
}
"POST" {
if {$callbackProc == "::callback::getChannelID"} {
set token [::http::geturl $url -headers [list Authorization "Bearer $::auth::accessToken" Content-Type application/x-www-form-urlencoded Cookie $::cookie] -query $query -handler $callbackProc -timeout 8000]
} else {
set token [::http::geturl $url -headers [list Authorization "Basic $::auth::BASIC_AUTH"] -query $query -handler $callbackProc -timeout 8000]
if {$callbackProc == "::callback::refreshTokens"} {
if { [::http::ncode $token] != 200} {
clearTimer "refreshTokensTID"
set ::refreshTokensTID [setTimer 10000]
}
}
}
}
"PUT" {
set token [::http::geturl $url -headers [list Authorization "Bearer $::auth::accessToken" Content-Type application/json Cookie $::cookie] -query $query -method $type -handler $callbackProc -timeout 8000]
}
}
LOG "Token: $token"
LOG "Token Status: [::http::status $token]"
LOG "Token NCode: [::http::ncode $token]"
if {$token != -1} {
::http::cleanup $token
}
}
#====================================================================================================
# subscribeDevice
#
# Desc: Callback for ::signalR::subscribeDevice
# Param: socket - The socket to read the HTTP data from (required by -handler option of ::http::geturl)
# token - The returned data (required by -handler option of ::http::geturl)
# Return: n/a
#====================================================================================================
proc subscribeDevice {socket token} {
LOG "Token: $token"
set data [read $socket]
LOG "data = $data"
}