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

(random) musings on I/O disciplines

Thread Next
Benjamin Stuhl
September 23, 2000 19:28
(random) musings on I/O disciplines
Message ID:
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
    (anything with a high bit is converted, since this
    also handles codepage conversions & co.) - outputs
  * Layer 3 - arbitrary transformations on the UTF-8 
    (s/Hello World!/Greetings, mortals!/g, etc.) - outputs
  * 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

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.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About