Trf: Technical background
Author: Andreas Kupries,,,

# Technical background of trf

[ Introduction | Sitemap ]

Let us do short review of the I/O subsystem first:

The important points are:

- Every interpreter contains a registry of all channels he knows about.
- Each channel is divided into a generic part, managed by `generic/tclIO.c`, and a system-dependent driver realizing the connection between the generic layer and the operating system.
- The current `tcl` distribution implements drivers for files, sockets and pipes, for Un*x, Windows and MacOS.
- Buffer management is the responsibility of the generic layer.

Now that does Trf do ?

1. It implements a driver forwarding all data of a channel to a another channel. Read requests to the original channel are forwarded to the second one too. As the forwarding channel intercepts all information flowing into and out of the second one it is now able to change this information at will. Possibilities are encryption, encoding into a different representation, additional computations like hash generation, etc. Because of this such a channel is often called a `filtering` channel too.
2. The problem with the structure above is that the second channel is still accessible from its containing intepreter, which might cause disruption of the filtered information. To prevent that some tricks (which do require a patch to the tcl core distribution) are used, causing the filter to take the place of the original channel, effectively hiding that one from the interpreter.

Visualized it looks like this:

An alternative description of the same concept is that the filter channel wraps itself around the filtered one and encapsulates it.

The picture for that:

Last update at Mon Aug 20 22:52:27 PDT 2001