All pastes #924352 Raw Edit

Something

public shellscript v1 · immutable
·published 2008-03-01 07:28 UTC
rendered paste body
# notes# socket, file and size are set elsewhereproc sockConnected {sock file} {   global total done size chunk   fileevent $sock writable {}   if {![eof $sock]&&[fconfigure $sock -error]==""} {      # connected... open the file and start fcopy	# FCOPY	set out [open /tmp/[clock-seconds]-$file w]	set in $sock        putlog "in: $in | out: $out"        set chunk [expr $size / 2]        set total 0        putlog "chunk is $chunk, size is $size, starting fcopy"        fcopy $in $out -command [list CopyMore $in $out] -size $chunk        vwait done        putlog "done?"           } else {      # complain   }}proc CopyMore {in out bytes {error {}}} {    set timestamp [clock format [clock seconds]]    set fl [open CopyMore {WRONLY CREAT APPEND}]    puts $fl "$timestamp: CopyMore started (chunk: $chunk)"    close $fl    global total done size chunk    putlog "CopyMore chunk is $chunk and bytes is $bytes"    incr total $bytes    if {([string length $error] != 0)} {        putlog "no error"        if {[eof $in]} {           putlog "in ($in) EOF"        }        if {$total >= $size} {         putlog "file saved. total is $total and size is $size"	 set done $total	 close $in	 close $out        }    } else {        putlog "total is now $total (of $size) bytes - chunk is $chunk"	fcopy $in $out -command [list CopyMore $in $out $chunk] -size $chunk    }}proc bgerror {message} {    set timestamp [clock format [clock seconds]]    set fl [open bgerror.txt {WRONLY CREAT APPEND}]    puts $fl "$timestamp: bgerror in $::argv '$message'"    close $fl}