Posted to tcl by jdc at Fri Oct 01 08:05:24 GMT 2010view raw
- % fconfigure stderr -buffering line
- % # Kill server when pipe closed by invoker.
- % proc bye args {
- if {![eof stdin]} { gets stdin ; return }
- puts stderr BYE
- exit
- }
- % # Server code. Bi-directional copy between 2 sockets.
- % proc geof {sok} {
- puts stderr DONE/$sok
- close $sok
- }
- % proc new {sok args} {
- puts stderr NEW/$sok
- global l srv
- fconfigure $sok -translation binary -buffering none
- lappend l $sok
- if {[llength $l]==2} {
- close $srv
- foreach {a b} $l break
- fcopy $a $b -command [list geof $a]
- fcopy $b $a -command [list geof $b]
- puts stderr 2COPY
- }
- puts stderr ...
- }
- % puts stderr SRV
- SRV
- % set l {}
- % set srv [socket -server new 9999]
- sock184
- % puts stderr WAITING
- WAITING
- % fileevent stdin readable bye
- % puts OK
- OK
- % vwait forever