Posted to tcl by evilotto at Fri Feb 03 20:51:11 GMT 2012view raw
- Program 1, the server:
- socket -server acceptit 12345
- proc acceptit {chan ca cp} {
- after 100 "sendit $chan"
- }
- proc sendit {chan} {
- puts $chan hi!
- close $chan
- }
- vwait forever
- Program 2, the proxy (the one that exhibits bad behavior):
- socket -server proxyit 12344
- proc proxyit {chan ca cp} {
- fconfigure $chan -blocking 0
- set ds [socket -async localhost 12345]
- fconfigure $ds -blocking 0
- fileevent $ds readable "writeit $ds $chan"
- }
- proc writeit {ds chan} {
- puts stderr "write $ds -> $chan"
- set d [read $ds]
- if {[eof $ds]} {
- puts "eof read $ds"
- close $ds
- close $chan
- } else {
- puts stderr "not eof $ds, data = '$d'"
- puts -nonewline $chan $d
- if {[eof $chan]} {
- puts "eof puts $chan"
- close $chan
- close $ds
- }
- }
- }
- vwait forever
- Program 3, the trigger:
- for {set i 0} {$i < 16} {incr i} {lappend s [socket localhost 12344]}
- using 15 here doesn't trigger the bug, 16 does