The "rchan" command is now part of CritLib [L1 ] and it is now called "rechan".
This package defines an "rchan" command, which lets you create Tcl-style channels that are completely handled by Tcl scripts, instead of C code.
The rchan extension itself is written in C, and requires CriTcl to turn it into an extension (on the fly)
Rchan must be called with two arguments to create a new channel:
rchan cmd mode
Where:
cmd = the name of the "callback" that will process requests mode = the open mode (6 is R/W, the normal case)
The callback cmd can be one or more words (i.e. a list). Depending on the operation, a request name and some args will be tacked on before invoking it. The following requests are implemented:
$cmd seek $chan <offset> ?<seekmode>? called when a "seek $chan <offset> ?<seekmode>?" is done $cmd read $chan <count> called when a "read $chan <count>" request is made $cmd write $chan <data> called when a "write $chan <data>" request is made
Other operations are not supported (close, for example, so the caller must keep track of this channel and clean up as appropriate - which is messy).
Rchan is not all that capable, it does not work well with fileevents, and in general it definitely could use some re-work and modernization. But it has been invaluable in TclKit to implement its database-backed VFS design.
Without some sort of "reflection", the Virtual File System (whether the original one by Matt Newman or the C-based on in the core by Vince Darley) could not have been implemented. It is hoped that one day, some sort of channel reflection becomes part of standard Tcl, and included in the core.
Nov 2003 status - close is now also tracked, and file-event friendliness is ok now. (This is not new, but as this page appears to have been edited recently, I thought I'd update the facts about it as well) -jcw