Tcl Library Source Code

Artifact [679c38e68f]
Login
EuroTcl/OpenACS 11 - 12 JULY 2024, VIENNA

Artifact 679c38e68f1b1751ef1b29a7763914aef78ef3c86da49de9cce729a042218b44:

Attachment "dns.patch" to ticket [022bca0ff5] added by DasBrain 2024-04-22 15:10:18. (unpublished)
--- dns-orig.tcl        2024-04-22 16:56:14.029555400 +0200
+++ dns.tcl     2024-04-22 14:06:26.670235000 +0200
@@ -908,16 +908,16 @@
     } elseif { [string length $result] >= 0 } {
         ${log}::debug "read [string length $result] bytes for $token"
         if {[catch {
+            append state(reply) $result
             # Handle incomplete reads - check the size and keep reading.
-            if {![info exists state(size)]} {
-                binary scan $result S state(size)
-                set result [string range $result 2 end]
+            if {![info exists state(size)] && [string length $state(reply)] >= 2} {
+                binary scan $state(reply) S state(size)
+                set state(reply) [string range $state(reply) 2 end]
             }
-            append state(reply) $result

             # check the length and flags and chop off the tcp length prefix.
-            if {[string length $state(reply)] >= $state(size)} {
-                binary scan $result S id
+            if {[info exists state(size)] && [string length $state(reply)] >= $state(size)} {
+                binary scan $state(reply) S id
                 set id [expr {$id & 0xFFFF}]
                 if {$id != [expr {$state(id) & 0xFFFF}]} {
                     ${log}::error "received packed with incorrect id"
@@ -926,8 +926,10 @@
                 #Receive [namespace current]::$id
                 Receive $token
             } else {
-                ${log}::debug "Incomplete tcp read:\
-                   [string length $state(reply)] should be $state(size)"
+                if {[info exists state(size)]} {
+                    ${log}::debug "Incomplete tcp read:\
+                       [string length $state(reply)] should be $state(size)"
+                }
             }
         } err]} {
             Finish $token "Event error: $err"