chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Re: stream API (was busy-wait in tcp-connect)


From: Kon Lovett
Subject: [Chicken-users] Re: stream API (was busy-wait in tcp-connect)
Date: Wed, 23 May 2007 10:37:56 -0700


On May 23, 2007, at 9:43 AM, Dan Muresan wrote:

Not sure what you mean. As opposed to text streams?

Binary streams as in binary data, as opposed to text.

Calling read-char repeatedly is probably not efficient; besides, read-char may not be the same as read-byte (if utf8 is loaded).
Actually 'read-byte' uses the builtin 'read-char' when the utf8 egg is loaded. I was wrong about ##sys#custom-*-port not working w/ UTF8, at least in the broader sense. Excellent.

1. I can't find the documentation for read-byte. I didn't even realize that read-byte existed. What i meant was that read-char might read multiple bytes, when the programmer wanted to read a single byte of binary data.

Ha ha. An undocumented part of the utf8 egg. You have a good point. We should probably make 'read-byte' part of the library unit.


2. You did not address the other point -- calling read-char repeatedly is probably not efficient. I think being able to read binary data efficiently is mandatory for a language that's supposed to be practical, no?

Yes. Chicken currently doesn't distinguish binary/text, or uni/bi- directional in its' port concept. I will create a TRAC ticket for this.

However, you can use 'read/write-string' for binary i/o. The string type in core Chicken is treated as a byte-vector. Again, these will be replaced by the utf8 egg so a 'read/write-bytes' routine in the library unit would be nice. But you can always capture the core definition before such replacement. (Chicken internals do this trick for just the above reason.)

Unfortunately not all port classes efficiently support the "string" read/write operation, ##sys#custom & stream ports for example, but string & socket ports do.

--
;;;; byte-io.scm

(declare
  (uses extras)
  (export read-byte write-byte read-bytes write-bytes) )

(define read-byte read-char)
(define write-byte write-char)
(define read-bytes read-string)
(define write-bytes write-string)
--

It is a work in progress,
Kon


Best,
Dan





reply via email to

[Prev in Thread] Current Thread [Next in Thread]