Re: serving a file to a client --- background fcopy read fileevent event puts socket channel blocking nonblocking



On Mar 29, 11:42 pm, vit...@xxxxxxxxx wrote:
while {$check} {
fcopy $in $out -command [list CopyMore $in $out $size] -size $size
}
vwait done

When I run it I get the following error:  channel "file3" is busy

Well, maybe you could read that manpage once more :-)
When fcopy has a -command, it is *asynchronous*, which means:
- sets up internal fileevents and nonblocking modes
- (also prevents any further fileevents and IO on the two channels)
- returns immediately

Your [while] loop (which by the way at least two persons have asked
you to remove) then tries to repeatedly register that asynchronous
operation. Of course the [fcopy] here runs exactly twice: one which
works, and one which raises the "busy" error you reported.

What you want is rather:

proc StartOneChunk s {
fcopy -command CopyMore -size $s ...
}
# prime the pump, just once
StartOneChunk $size

proc CopyMore args {
if {finished} {set ::done 1;return}
StartOneChunk $::size
}
vwait done

-Alex
.



Relevant Pages