Posted to tcl by crshults at Mon Jun 15 18:46:57 GMT 2015view raw
- set port 9000
- set sock ""
- proc read_data {sock} {
- puts [read $sock]
- if {[chan eof $sock]} {
- puts "chan is eof"
- chan event $sock readable {}
- chan close $sock
- }
- }
- proc uniform {str} {
- global port
- set ::sock [socket localhost $port]
- chan configure $::sock -translation binary -buffering none -blocking no
- set msg "RCTL\nBEGIN\n${str}\nEND"
- chan event $::sock readable "read_data $::sock"
- chan puts $::sock $msg
- }
- uniform "some task"
- set dead no
- proc heartbeat {} {
- if {[catch {puts $::sock .}]} {
- set ::dead yes
- }
- after 1000 heartbeat
- }
- proc check_for_death {args} {
- if {$::dead eq "yes"} {
- puts "yeah,... we're dead."
- }
- }
- trace add variable dead write check_for_death
- heartbeat