Can't flush one line through a socket when using zlib compression/decompression
For example, when we have: socket -server server 1501
vwait die
server.tcl
proc server {sock ip port} {
fconfigure $sock -buffering none -blocking 1
zlib push deflate $sock
puts $sock "qwertyuiop"
chan configure $sock -flush sync
flush $sock
puts "done!"
}
and client.tcl
set sock [socket "127.0.0.1" 1501]
fconfigure $sock -buffering none -blocking 1
zlib push inflate $sock
puts "reading.."
puts [gets $sock]
close $sock
If you start server.tcl and then start client.tcl, you will find that "qwertyuiop" from server.tcl never gets flushed. Client.tcl will simply wait to read in a line from the socket even though we see that server.tcl has indicated, "done!"
If you remove the compression, we do not see this issue. Here are the same server.tcl and client.tcl files with no compression.
server.tcl socket -server server 1501
vwait die
proc server {sock ip port} {
fconfigure $sock -buffering none -blocking 1
puts $sock "qwertyuiop"
flush $sock
puts "done!"
}
and client.tcl
set sock [socket "127.0.0.1" 1501]
fconfigure $sock -buffering none -blocking 1
puts "reading.."
puts [gets $sock]
close $sock
If you start this new server.tcl and then the new start client.tcl, you will see that the client.tcl prints "qwertyuiop" correctly, indicating that it was flushed correctly. This is how I know that this issue is specific to zlib compression.
During my individual testing, I found that I could force the flush to happen correctly by increasing the number of "puts" operations in server.tcl. If I ran "puts $sock "qwertyuiop" 1000 times in server.tcl, I could read "qwertyuiop" correctly in client.tcl.
The bug here is that flush does not appear to be working correctly for one line with zlib compression on a socket.