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



On Mar 29, 4:08 pm, Alexandre Ferrieux <alexandre.ferri...@xxxxxxxxx>
wrote:
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

I was not trying to go back to the "while" loop :). It is the code
that started it all. I was just curious why it didn't work. The
process seemed to be very similar to the correct code (calling fcopy
repeatedly) and that's what made me confused. But your explanation
makes it clear.

Thanks,

----Victor
.



Relevant Pages