Posted to tcl by evilotto at Fri Feb 03 20:51:11 GMT 2012view raw

  1. Program 1, the server:
  2. socket -server acceptit 12345
  3. proc acceptit {chan ca cp} {
  4. after 100 "sendit $chan"
  5. }
  6. proc sendit {chan} {
  7. puts $chan hi!
  8. close $chan
  9. }
  10. vwait forever
  11.  
  12. Program 2, the proxy (the one that exhibits bad behavior):
  13. socket -server proxyit 12344
  14. proc proxyit {chan ca cp} {
  15. fconfigure $chan -blocking 0
  16. set ds [socket -async localhost 12345]
  17. fconfigure $ds -blocking 0
  18. fileevent $ds readable "writeit $ds $chan"
  19. }
  20. proc writeit {ds chan} {
  21. puts stderr "write $ds -> $chan"
  22. set d [read $ds]
  23. if {[eof $ds]} {
  24. puts "eof read $ds"
  25. close $ds
  26. close $chan
  27. } else {
  28. puts stderr "not eof $ds, data = '$d'"
  29. puts -nonewline $chan $d
  30. if {[eof $chan]} {
  31. puts "eof puts $chan"
  32. close $chan
  33. close $ds
  34. }
  35. }
  36. }
  37. vwait forever
  38.  
  39. Program 3, the trigger:
  40. for {set i 0} {$i < 16} {incr i} {lappend s [socket localhost 12344]}
  41.  
  42. using 15 here doesn't trigger the bug, 16 does