lappend auto_path ../..
package require Debug
package require Chan


proc accept {args} {
    puts stderr "Accepting $args"
}
proc readsome {sock args} {
    puts stderr "readsome $sock"
    read $sock 1024
}
socket -server accept 9999
set wfd [socket localhost 9999]
chan event $wfd readable [list readsome $wfd]

#lassign [chan pipe] rfd wfd
#chan configure $rfd -blocking 0 -buffersize 4096 -buffering none
#chan event $rfd readable [list readsome $rfd]

chan configure $wfd -blocking 0 -buffersize 4096 -buffering none

Debug on chan 10
#set ichan [IChan new chan $wfd]
set ichan [Socket new chan $wfd]
set tfd [chan create {read write} $ichan]
chan configure $tfd -blocking 0 -buffersize 4096 -buffering none

set zfd [open /dev/zero r]
after 0 chan copy $zfd $tfd -size 1000000000

set done 1
vwait done
