All pastes #924278 Raw Edit

Miscellany

public shellscript v1 · immutable
·published 2008-03-01 05:21 UTC
rendered paste body
proc sockConnected {sock file} {   global total done size   fileevent $sock writable {}   if {![eof $sock]&&[fconfigure $sock -error]==""} {      # connected... open the file and start fcopy	set out [open /tmp/[unixtime]-$file w]	set in $sock        set chunk 1024        set total 0        fcopy $in $out -command [list CopyMore $in $out $size $chunk] -size $chunk        vwait done   } else {      # errors   }}proc CopyMore {in out chunk bytes {error {}}} {    global total done size    incr total $chunk    if {([string length $error] != 0) || [eof $in] || $total >= $size} {        # file transfer is completed!	set done $total	close $in	close $out    } else {        # continue copying	fcopy $in $out -command [list CopyMore $in $out $chunk] \	    -size $chunk    }}