Doc for Tcl 7.5 Channel IO system

From: Jacob Levy (jyl@eng.sun.com)
Date: 11 Apr 96 07:29:15

The information contained below may be useful if you are writing new channel drivers for channels of types not yet supported by Tcl. The idea of the new IO system is to make this easy. Let me know if you run into any issues for which you believe there is not adequate support currently.

The relevant man pages for the C APIs are: The relevant man pages for the Tcl commands are: A Tcl_Channel is the external representation of a communication channel in the new IO subsystem. It is mostly opaque, and Tcl provides APIs to get some of its fields out:

The real definition of a Tcl_Channel (the concrete data type is called Channel, i.e without the Tcl_) is in generic/tclIO.c. Do not depend on its structure or fields to stay the same - this is an INTERNAL data structure.

To set up so that the notifier delivers events for your channel, use Tcl_CreateChannelHandler and Tcl_DeleteChannelHandler. This should work automatically with new types of channels unless you require the notifier to watch a new type of event source (i.e. an event source other than OS level files, pipes, sockets and timers) that it does not already know about. Currently the API does not let you do that. Contact us for help if you need this.

Tcl_Files are abstractions to wrap around OS specific data types for files, pipes etc. They provide a level of indirection that allows the IO system to be split into generic and type specific levels. Tcl_Files also provide ways to get at the data in them:

The functionality provided by Tcl_Files is implemented in generic/tclFHandle.c which also provides the concrete data type for Tcl_Files (the name of which is FileHandle). Again this is an internal data structure which should not be relied on in any way.

It's also possible to interface with the notifier at the level of Tcl_File data structures, although you should not need to - you should be able to do most of what you want at the level of Tcl_Channel data structures. If you find this is really needed, you can use Tcl_CreateFileHandler and Tcl_DeleteFileHandler.


Some Conversion Functions

Abstractions:
    channel  - Exposed Tcl IO structure
    Tcl_File - Tcl Internal IO abstraction
        fd   - OS IO handle