- set state(begin) [clock seconds]
- set state(state) waiting
- after cancel $watchtimer
- lappend watchlist $token
- Poll
-}
-
-proc ::ole::http::Poll {} {
- variable watchlist
- variable watchtimer
- if {[llength $watchlist] > 0} {
- set newlist {}
- foreach token $watchlist {
- upvar #0 $token state
- if {$state(state) eq "waiting"} {
- if {[$state(xmlhttp) readyState] == 4} {
- set state(state) ok
- set state(ncode) [$state(xmlhttp) status]
- set state(code) [$state(xmlhttp) statusText]
- set state(meta) {}
- foreach line [split [$state(xmlhttp) getAllResponseHeaders] "\n"] {
- if {[regexp {^([^:]+): ?(.*)} $line -> h v]} {
- lappend state(meta) $h [string trimright $v]
- }
- }
- if {$state(-command) ne ""} {
- if {[catch {eval $state(-command) $token} err]} {
- ::bgerror $err
- }
- }
- break
- }
- if {$state(-timeout) ne ""
- && ([clock seconds] - $state(begin)) > $state(-timeout)} {
- set state(state) timeout
- $state(xmlhttp) abort
- if {$state(-command) ne ""} {
- if {[catch {eval $state(-command) $token} err]} {
- ::bgerror $err
- }
- }
- break
- }
- lappend newlist $token
- }
+ after cancel $state(afterid)
+ set state(ncode) [$state(xmlhttp) status]
+ set state(code) [$state(xmlhttp) statusText]
+ set state(meta) {}
+ foreach line [split [$state(xmlhttp) getAllResponseHeaders] "\n"] {
+ if {[regexp {^([^:]+): ?(.*)} $line -> h v]} {
+ lappend state(meta) $h [string trimright $v]