Tcl Source Code

Artifact [978b18e0ba]
Login

Artifact 978b18e0ba56af2c1d91d8cd2b5811fcbef56a0d:

Attachment "httpsync.patch" to ticket [3382532fff] added by ferrieux 2011-07-31 23:07:16.
Index: library/http/http.tcl
===================================================================
--- library/http/http.tcl
+++ library/http/http.tcl
@@ -745,18 +745,30 @@
 	    flush $sock
 	    fileevent $sock readable [list http::Event $sock $token]
 	}
 
 	if {![info exists state(-command)]} {
-	    # geturl does EVERYTHING asynchronously, so if the user calls it
-	    # synchronously, we just do a wait here.
+	    if {!$state(-timeout) &&  ![string length $state(-queryprogress)] && !$isQueryChannel && ![info exists state(-channel)]} {
+		# special full-sync case, avoid doing a wait
 
-	    wait $token
-	    if {$state(status) eq "error"} {
-		# Something went wrong, so throw the exception, and the
-		# enclosing catch will do cleanup.
-		return -code error [lindex $state(error) 0]
+		fconfigure $sock -blocking on
+		if {$isQuery || $isQueryChannel} {
+		    uplevel #0 [list http::Write $token]
+		}
+		while {![regexp {^(?:ok|error)$} $state(status)]} {
+		    uplevel #0 [list http::Event $sock $token]
+		}
+	    } else {
+		# otherwise, geturl does EVERYTHING asynchronously; so if the user calls it
+		# synchronously, we just do a wait here.
+		
+		wait $token
+		if {$state(status) eq "error"} {
+		    # Something went wrong, so throw the exception, and the
+		    # enclosing catch will do cleanup.
+		    return -code error [lindex $state(error) 0]
+		}
 	    }
 	}
     } err]} {
 	# The socket probably was never connected, or the connection dropped
 	# later.