On Mon, 16 Jan 1995 13:31:54 +0000 (GMT),
Ross Wakelin <rossw@march.co.uk> said:
Ross> Here is the output from the test script. As you can see, the
Ross> "Bad file number" error has appeared. The "advice" about the
Ross> seek between gets/puts in in the man page on this platform
Ross> (see below)
Sorry, I was blind when I wrote the test script. The order of the test
must be inversed to get reasonable results. Below is the corrected
version. Please run this version again and let me know what happens.
I will collect the results. Perhaps we can get an automatic flush()
whenever the input/output direction on a Tcl file handle changes if
this fixes the problem on a large number of machines (what ever that
is).
Ross> Man page for fopen (also fdopen, which is what tcl does)
Ross> When a file is opened for update, both input and output may
Ross> -> be done on the resulting stream. However, output may not be
Ross> -> directly followed by input without an intervening fflush,
Ross> -> fseek, fsetpos, or rewind, and input may not be directly
Ross> -> followed by output without an intervening fseek, fsetpos, or
Ross> -> rewind, or an input operation that encounters end-of-file.
That's the usual blurb mostly meant for FILE streams that point to
real files. This does not automatically apply to FILE stream on
sockets, at least not on all variants of UNIX.
Juergen
proc getsputs {{flush ""}} {
set f [tcp listen]
set p [lindex [tcp info $f] 1]
set A [tcp connect localhost $p]
set B [tcp accept $f]
puts $A does; gets $B r1; eval $flush
puts $B it; gets $A r2; eval $flush
puts $A work; gets $B r3; eval $flush
puts $B ?; gets $A r4
tcp close $B
tcp close $A
tcp close $f
return "$r1 $r2 $r3 $r4"
}
set uname [exec uname -a]
set ok "does it work ?"
catch {
if {[getsputs "seek \$A 0 current; seek \$B 0 current"] == $ok} {
puts "($uname) accepts seek"
} else {
puts "($uname) fails with seek"
}
}
catch {
if {[getsputs "flush \$A; flush \$B"] == $ok} {
puts "($uname) accepts flush"
} else {
puts "($uname) fails with flush"
}
}
catch {
if {[getsputs ""] == $ok} {
puts "($uname) is happy without special attention"
} else {
puts "($uname) needs special attention"
}
}
exit