Attachment "http-fix1-for--69687a01db.patch" to
ticket [3581754fff]
added by
kjnash
2012-10-30 09:57:49.
Index: library/http/http.tcl
==================================================================
--- library/http/http.tcl
+++ library/http/http.tcl
@@ -193,10 +193,19 @@
if {
($state(status) eq "timeout") || ($state(status) eq "error") ||
([info exists state(connection)] && ($state(connection) eq "close"))
} then {
CloseSocket $state(sock) $token
+ } elseif {
+ ([info exists state(connection)] && ($state(connection) eq ""))
+ } then {
+ # The HTTP Response is complete, but the connection is Keep-Alive.
+ # The socket is no longer associated with $token, and so the fileevents
+ # that are part of this association should be removed or replaced.
+ Log "Keep-Alive socket $state(sock) is free for next request"
+ catch {fileevent $state(sock) readable [list ::http::KeepAlive $state(sock)]}
+ catch {fileevent $state(sock) writable {}}
}
if {[info exists state(after)]} {
after cancel $state(after)
}
if {[info exists state(-command)] && !$skipCB} {
@@ -208,10 +217,42 @@
}
# Command callback may already have unset our state
unset -nocomplain state(-command)
}
}
+
+
+# http::KeepAlive
+#
+# Handle input on a "Keep-Alive" socket when it is not in
+# use for an HTTP request/response.
+#
+# The main purpose is to handle the eof case when the server
+# closes the connection after a timeout.
+#
+# Catch in case the the socket is closed already.
+#
+# Arguments
+# sock The socket receiving input.
+#
+# Side Effects
+# Read the socket and handle callbacks.
+
+proc ::http::KeepAlive {sock} {
+ if {[catch {eof $sock} eof] || $eof} {
+ Log "Keep-Alive socket $sock has been closed by the server"
+ CloseSocket $sock
+ } else {
+ # Socket is open and is not EOF.
+ if {[read $sock] ne ""} {
+ Log "WARNING: Keep-Alive socket $sock is still sending data"
+ } else {
+ }
+ }
+ return
+}
+
# http::CloseSocket -
#
# Close a socket and remove it from the persistent sockets table. If
# possible an http token is included here but when we are called from a