develooper Front page | perl.perl5.porters | Postings from September 2000

(random) musings on I/O disciplines

Thread Next
From:
Benjamin Stuhl
Date:
September 23, 2000 19:28
Subject:
(random) musings on I/O disciplines
Message ID:
20000924022807.10799.qmail@web6303.mail.yahoo.com
So I'm once again musing on I/O channels and disciplines,
and I have some random ideas that I think are worth raising
to see if they get shot down. Basically, I'm thinking a 5
layer system for I/O channels:

  * Layer 0 - OS and input type specific (implements
    sysread, syswrite, sysseek, & co. (and $/ = \128 ?)),
    as well as buffering
    on file-ish sources - outputs raw bytes 
  * Layer 1 - arbitrary transformations on the raw bytes -
    also outputs raw bytes (CRLF translation, etc.)
  * Layer 2 - to UTF-8: this layer converts bytes into
UTF-8
    (anything with a high bit is converted, since this
layer
    also handles codepage conversions & co.) - outputs
UTF-8
  * Layer 3 - arbitrary transformations on the UTF-8 
    (s/Hello World!/Greetings, mortals!/g, etc.) - outputs
    UTF-8
  * Layer 4 - implements concepts of "records" (enhanced
    $/ = "foo")

Layers 0, 2, and 4 are nonstackable (it makes no sense to
treat a set of bytes as both latin1 and shift-JIS or to
have three different ideas of what a record is). Layers 1
and 3 are stackable and called in FIFO order (oldest layer
called first).

Addition and removal of layers is handled by a layer
registration system for everything but layer 0, which must
be attached by the channel's open() procedure. Modules (and
the core, for that matter) register a function table with a
name:

PerlIO_register_discipline("shift-JIS", 2, &jis_fn_tbl,
(void *)jis_data);

which is then used for all binmode($fh, "+:shift-JIS")
calls. This brings me to my belief that 
binmode($fh, ":foo") needs more power, so I propose 
binmode($fh, "+:foo") and binmode($fh, "-:foo") to add and
remove disciplines as needed.

I think that's it, and at any rate, I need more sleep
before I can put together much more in the way of (at least
marginally) intelligable thoughts.

-- BKS

__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About