Posted to tcl by crshults at Wed Dec 03 19:10:45 GMT 2014view raw

  1. #I tried to whittle this as small as I could
  2.  
  3. #This works in all versions (see below for non-working version):
  4. proc read_sock {channel} {puts [chan read $channel]}
  5.  
  6. proc accept {channel address port} {
  7. puts "accept $channel $address $port"
  8. chan configure $channel -blocking no -buffering none -encoding iso8859-1 -translation binary
  9. chan event $channel readable "read_sock $channel"
  10. }
  11.  
  12. set ssock [socket -server accept 9900]
  13.  
  14. proc connection_result {channel} {
  15. puts -nonewline "connection_result: "
  16. if {[chan configure $channel -error] == ""} {
  17. puts connected
  18. } else {
  19. puts "not connected"
  20. chan event $channel readable {}
  21. }
  22. chan event $channel writable {}
  23. }
  24.  
  25. set csock1 [socket -async localhost 9901]
  26. chan configure $csock1 -blocking no -buffering none -encoding iso8859-1 -translation binary
  27. chan event $csock1 readable "read_sock $csock1"
  28. chan event $csock1 writable "connection_result $csock1"
  29.  
  30. after 10000 {puts "This message will appear in 10 seconds"}
  31.  
  32. vwait forever
  33. #end of working version
  34.  
  35. #Begin broken version
  36. #This works in:
  37. #ActiveTcl8.6.1.0.297577-win32-ix86-threaded
  38. #but is broken in:
  39. #ActiveTcl8.6.2.0.298433-win32-ix86-threaded
  40. #ActiveTcl8.6.3.0.298612-win32-ix86-threaded
  41. proc read_sock {channel} {puts [chan read $channel]}
  42.  
  43. proc accept {channel address port} {
  44. puts "accept $channel $address $port"
  45. chan configure $channel -blocking no -buffering none -encoding iso8859-1 -translation binary
  46. chan event $channel readable "read_sock $channel"
  47. }
  48.  
  49. set ssock [socket -server accept 9902]
  50.  
  51. proc connection_result {channel} {
  52. puts -nonewline "connection_result: "
  53. if {[chan configure $channel -error] == ""} {
  54. puts connected
  55. } else {
  56. puts "not connected"
  57. chan event $channel readable {}
  58. }
  59. chan event $channel writable {}
  60. }
  61.  
  62. set csock1 [socket -async localhost 9903]
  63. chan configure $csock1 -blocking no -buffering none -encoding iso8859-1 -translation binary
  64. chan event $csock1 readable "read_sock $csock1"
  65. chan event $csock1 writable "connection_result $csock1"
  66.  
  67. #connect up a client prior to entering the vwait
  68. set csock2 [socket localhost 9902]
  69. chan configure $csock2 -blocking no -buffering none -encoding iso8859-1 -translation binary
  70. chan event $csock2 readable "read_sock $csock2"
  71.  
  72. after 10000 {puts "This message will never appear"}
  73.  
  74. vwait forever
  75.  

Comments

Posted by crshults at Wed Dec 03 19:36:48 GMT 2014 [text] [code]

after 1100 { set csock2 [socket localhost 9902] chan configure $csock2 -blocking no -buffering none -encoding iso8859-1 -translation binary chan event $csock2 readable "read_sock $csock2" } after 10000 {puts "This message will appear now because the delay was added"}