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

#I tried to whittle this as small as I could

#This works in all versions (see below for non-working version):
proc read_sock {channel} {puts [chan read $channel]}

proc accept {channel address port} {
	puts "accept $channel $address $port"
	chan configure $channel -blocking no -buffering none -encoding iso8859-1 -translation binary
	chan event $channel readable "read_sock $channel"
}

set ssock [socket -server accept 9900]

proc connection_result {channel} {
	puts -nonewline "connection_result: "
	if {[chan configure $channel -error] == ""} {
		puts connected
	} else {
		puts "not connected"
		chan event $channel readable {}
	}
	chan event $channel writable {}
}

set csock1 [socket -async localhost 9901]
chan configure $csock1 -blocking no -buffering none -encoding iso8859-1 -translation binary
chan event $csock1 readable "read_sock $csock1"
chan event $csock1 writable "connection_result $csock1"

after 10000 {puts "This message will appear in 10 seconds"}

vwait forever
#end of working version

#Begin broken version
#This works in:
#ActiveTcl8.6.1.0.297577-win32-ix86-threaded
#but is broken in:
#ActiveTcl8.6.2.0.298433-win32-ix86-threaded
#ActiveTcl8.6.3.0.298612-win32-ix86-threaded
proc read_sock {channel} {puts [chan read $channel]}

proc accept {channel address port} {
	puts "accept $channel $address $port"
	chan configure $channel -blocking no -buffering none -encoding iso8859-1 -translation binary
	chan event $channel readable "read_sock $channel"
}

set ssock [socket -server accept 9902]

proc connection_result {channel} {
	puts -nonewline "connection_result: "
	if {[chan configure $channel -error] == ""} {
		puts connected
	} else {
		puts "not connected"
		chan event $channel readable {}
	}
	chan event $channel writable {}
}

set csock1 [socket -async localhost 9903]
chan configure $csock1 -blocking no -buffering none -encoding iso8859-1 -translation binary
chan event $csock1 readable "read_sock $csock1"
chan event $csock1 writable "connection_result $csock1"

#connect up a client prior to entering the vwait
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 never appear"}

vwait forever

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"}