Tcl Source Code

Artifact [a3dcbc5e6d]
Login

Artifact a3dcbc5e6dd8125176391f2fb2415c326ba5a917:

Attachment "http.tcl.patch" to ticket [3599789fff] added by sebres 2013-01-07 20:06:50.
Index: http.tcl
===================================================================
--- http.tcl	(revision 17)
+++ http.tcl	(working copy)
@@ -249,6 +249,16 @@
 	} else {
 	    Log "Cannot close connection $conn_id - no socket in socket map"
 	}
+	# reset states of all tokens shared this connection :
+	variable sockettokenmap
+	if {[info exists sockettokenmap(s-$s)]} {
+	    foreach token $sockettokenmap(s-$s) {
+		if {[info exists $token]} {
+		    reset $token "closed"
+		}
+	    }
+	    unset sockettokenmap(s-$s)
+	}
     }
 }
 
@@ -586,6 +596,9 @@
         [expr {$state(-keepalive)?"keepalive":""}]
     if {$state(-keepalive)} {
         set socketmap($state(socketinfo)) $sock
+        # share connection via keepalive token map
+        variable sockettokenmap
+        lappend sockettokenmap(s-$sock) $token
     }
 
     # Wait for the connection to complete.
@@ -1283,6 +1296,16 @@
     variable $token
     upvar 0 $token state
 
+    # check connection was closed (ex. file event by keepalive connection) :
+    if {$state(-keepalive)} {
+	set conn_id $state(socketinfo)
+	variable socketmap
+	if {![info exists socketmap($conn_id)]} {
+	    Log "Wait: connection \"$conn_id\" was closed unexpectedly"
+	    return [status $token]
+	}
+    }
+    
     if {![info exists state(status)] || $state(status) eq ""} {
 	# We must wait on the original variable name, not the upvar alias
 	vwait ${token}(status)