diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/nonblocking-gets.tcl | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/nonblocking-gets.tcl b/examples/nonblocking-gets.tcl new file mode 100644 index 0000000..a9ac4bd --- /dev/null +++ b/examples/nonblocking-gets.tcl @@ -0,0 +1,38 @@ +#!/usr/bin/env jimsh + +# Tests that 'gets' on a non-blocking socket +# does not return partial lines + +lassign [socket pipe] r w + +if {[os.fork] == 0} { + # The child will be our client + $r close + # Output increasingly long lines + loop i 10000 { + $w puts [string repeat a $i] + } +} else { + # The server reads lines with gets. + # Each one should be one longer than the last + $w close + + set exp 0 + $r ndelay 1 + $r readable { + while {[$r gets buf] >= 0} { + set len [string length $buf] + if {$len != $exp} { + puts "Read line of length $len but expected $exp" + incr done + break + } + incr exp + } + if {[$r eof]} { + incr done + } + } + + vwait done +} |