diff options
author | kjnash <k.j.nash@usa.net> | 2018-03-27 08:52:40 (GMT) |
---|---|---|
committer | kjnash <k.j.nash@usa.net> | 2018-03-27 08:52:40 (GMT) |
commit | e9bb0992b0f392798d2d978f2bdcbc62aa6ea602 (patch) | |
tree | a7c85124093d495f192a6c4fa472eed5acc1bda9 /library/http | |
parent | f35c0dc2edcc96ff38d150cd621cea7b771c9a4c (diff) | |
download | tcl-e9bb0992b0f392798d2d978f2bdcbc62aa6ea602.zip tcl-e9bb0992b0f392798d2d978f2bdcbc62aa6ea602.tar.gz tcl-e9bb0992b0f392798d2d978f2bdcbc62aa6ea602.tar.bz2 |
First step for implementing concurrent requests using the same connection. Define namespace variables socket* and http where they will (eventually) be used. Leave them unused except in http::init where they are initialised.
Diffstat (limited to 'library/http')
-rw-r--r-- | library/http/http.tcl | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/library/http/http.tcl b/library/http/http.tcl index 485498a..8b4d714 100644 --- a/library/http/http.tcl +++ b/library/http/http.tcl @@ -62,14 +62,35 @@ namespace eval http { # Create a map for HTTP/1.1 open sockets variable socketMapping + variable socketRdState + variable socketWrState + variable socketRdQueue + variable socketWrQueue + variable socketClosing + variable socketPlayCmd if {[info exists socketMapping]} { # Close open sockets on re-init foreach {url sock} [array get socketMapping] { catch {close $sock} } } + + # Traces on "unset socketRdState(*)" will cancel any queued responses. + # Traces on "unset socketWrState(*)" will cancel any queued requests. array unset socketMapping + array unset socketRdState + array unset socketWrState + array unset socketRdQueue + array unset socketWrQueue + array unset socketClosing + array unset socketPlayCmd array set socketMapping {} + array set socketRdState {} + array set socketWrState {} + array set socketRdQueue {} + array set socketWrQueue {} + array set socketClosing {} + array set socketPlayCmd {} return } init @@ -208,6 +229,14 @@ proc http::config {args} { # May close the socket. proc http::Finish {token {errormsg ""} {skipCB 0}} { + variable socketMapping + variable socketRdState + variable socketWrState + variable socketRdQueue + variable socketWrQueue + variable socketClosing + variable socketPlayCmd + variable $token upvar 0 $token state global errorInfo errorCode @@ -246,6 +275,13 @@ proc http::Finish {token {errormsg ""} {skipCB 0}} { proc http::CloseSocket {s {token {}}} { variable socketMapping + variable socketRdState + variable socketWrState + variable socketRdQueue + variable socketWrQueue + variable socketClosing + variable socketPlayCmd + catch {fileevent $s readable {}} set connId {} if {$token ne ""} { @@ -600,6 +636,13 @@ proc http::geturl {url args} { # See if we are supposed to use a previously opened channel. if {$state(-keepalive)} { variable socketMapping + variable socketRdState + variable socketWrState + variable socketRdQueue + variable socketWrQueue + variable socketClosing + variable socketPlayCmd + if {[info exists socketMapping($state(socketinfo))]} { if {[catch {fconfigure $socketMapping($state(socketinfo))}]} { Log "WARNING: socket for $state(socketinfo) was closed\ @@ -685,6 +728,13 @@ proc http::geturl {url args} { proc http::Connected {token proto phost srvurl} { variable http variable urlTypes + variable socketMapping + variable socketRdState + variable socketWrState + variable socketRdQueue + variable socketWrQueue + variable socketClosing + variable socketPlayCmd variable $token upvar 0 $token state @@ -962,6 +1012,15 @@ proc http::Connect {token proto phost srvurl} { # Write the socket and handle callbacks. proc http::Write {token} { + variable http + variable socketMapping + variable socketRdState + variable socketWrState + variable socketRdQueue + variable socketWrQueue + variable socketClosing + variable socketPlayCmd + variable $token upvar 0 $token state set sock $state(sock) @@ -1027,6 +1086,15 @@ proc http::Write {token} { # Read the socket and handle callbacks. proc http::Event {sock token} { + variable http + variable socketMapping + variable socketRdState + variable socketWrState + variable socketRdQueue + variable socketWrQueue + variable socketClosing + variable socketPlayCmd + variable $token upvar 0 $token state |