[REBOL] Re: [BUG?] read-io & write-io or Wait or is TCL better?
From: g:santilli:tiscalinet:it at: 7-Aug-2003 12:35
Hi Petr,
On Thursday, August 7, 2003, 10:41:04 AM, you wrote:
PK> request. And why? Because docs don't state that in the case of read-io
PK> we should clear the buffer. If it would lead only to buffer size
PK> increase, then OK, but it leads into completly broken communication with
PK> unexpected results ...
Actually, you're wrong. First of all, READ-IO and WRITE-IO are
lowlevel functions; you should use COPY and INSERT whenever
possible if you don't want to bother with these kind of details.
READ-IO and WRITE-IO *DON'T* enlarge the buffer. You have to
provide a large enough buffer for them, and a correct length value
too. Furthermore, READ-IO *DOESN'T* overwrite the buffer you
provide, but instead it appends to it if there is already some
data (this is a useful feature and not a bug). For this reason, if
you don't want it do behave this way you have to provide it an
empty buffer. If the docs are not clear about this then this is a
bug in the docs, not in REBOL (Carl is using READ-IO and WRITE-IO
this way so I'm pretty sure it's not a bug ;-).
What was happening to Norman is that he was resending the first
packet every time. His proxy worked for other services because, by
chance, they didn't happen to send two packets at once. SSH did,
and his code instead of resending the two packets sent the first
two times.
PK> What do other think? Should write-io clear the buffer after succesfull
PK> write automatically?
I don't think this would be a great idea, as the buffer could be
needed for something else after the write. For example I may want
to send the data in smaller pieces instead of all at once, so I
don't want the buffer to be cleared as I only send a small part of
it each time. (If you look at the source for async:// you'll see
I'm doing exactly this.)
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/