This is not necessarily the current version of this TIP.
| TIP: | 301 |
| Title: | Split Bidirectional Channels For Half-Close |
| Version: | $Revision: 1.2 $ |
| Author: | Alexandre Ferrieux <alexandre dot ferrieux at gmail dot com> |
| State: | Withdrawn |
| Type: | Project |
| Tcl-Version: | 8.6 |
| Vote: | Pending |
| Created: | Monday, 11 December 2006 |
| Obsoleted-By: | TIP #332 |
This TIP proposes to introduce a chan split command allowing to access both sides of a bidirectional channel (r+ pipe, or socket) as separate Tcl channels, in order to be able to close them separately. This would give Tcl the same level of control that the OS enjoys on the lifetime of such bidirectional connections.
Bidirectional channels allow Tcl to make an efficient use of a "filter process", by exchanging data back and forth over an abstract "single" channel.
However, this single channel abstraction comes with a too coarse-grained close primitive. Indeed, it closes both directions simultaneously, while it is often desirable to close "gracefully" the half-connection to the filter process, leaving the return path open. The effect of such a half-close is that the filter receives a bona fide EOF alone, without a nearly simultaneous SIGPIPE on its write end if it happens to be writing at that time. Moreover, if the filter is itself comprised of a pipeline of processes, some of which doing buffered I/O, then this graceful EOF may be the only way of flushing the chain and receiving back precious data.
This technique is supported by all modern OSes: for pipes there are actually two separate file descriptors/handles, and it suffices to close() the write side; for sockets, a single fd is used, but a specific syscall, shutdown(), brings back the ability to half-close. Hence it is fairly natural for a universal "OS glove" like Tcl to expose this universal feature.
This TIP proposes to add a chan split subcommand to chan, with the syntax:
chan split channel
The channel argument indicates the bidirectional channel to be split. The command returns a two element list, with the first element being the name of the channel that is open for reading only, and the second element being the name of the channel that i