Skip to content
Tcl Source Code Artifact [abe2dec82d]
Login

Artifact [abe2dec82d]

Artifact abe2dec82ddb88b3a707e73e34c433ebcc388cbe:

Attachment "refchan.n" to ticket [1428976fff] added by andreas_kupries on 2006-03-17 05:36:07.
'\" 
'\" Copyright (c) 2006 Andreas Kupries
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
'\" RCS: @(#) $Id: chan.n,v 1.2 2005/06/10 15:22:43 dkf Exp $
.so man.macros
.TH reflectedchan n 8.5 Tcl "Tcl Built-In Commands"
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
reflectedchan \- Command handler API of reflected channels, version 1
.SH SYNOPSIS
\fBhandler \fIoption\fR ?\fIarg arg ...\fR?
.BE
.SH DESCRIPTION
.PP
The Tcl-level handler command for a reflected channel has to be
ensemble command that has to support the following subcommands, as
listed below. Note that the term \fIensemble\fR is used to generically
describe all command (prefixes) which are able to process
subcommands. The implementation is handlers for reflected channel
\fBis not\fR tied to the \fBnamespace ensemble\fRs.
.PP
Of all the possible subcommand the handler \fBhas to\fR support
\fBinitialize\fR, \fBfinalize\fR, and \fBwatch\fR,
always. Implementation of the other subcommands is optional.
.TP
\fIhandlerCmd \fBinitialize \fIchannel mode\fR
.
An invokation of this subcommand will be the first call the
\fIhandlerCmd\fR will receive for the specified new \fBchannel\fR. It
is his responsibility to set up any internal data structures it needs
to keep track of the channel and its state.
.RS
.PP
The return value of the method has to be a list containing the names
of all subcommand which are supported by the \fIhandlerCmd\fR. This
alos tells the Tcl core which version of the API for reflected channel
is used by this command handler.
.PP
Any error thrown by the method will abort the creation of the channel
and no channel will be created. The thrown error will appear as error
thrown by \fBchan create\fR.
.PP
Any exception beyond \fBerror\fR, like \fBbreak\fR, etc. is treated as
and converted to an error.
.PP
\fBNote:\fR If the creation of the channel was aborted due to failures
here, then the subcommand \fBfinalize\fR will not be called.
.PP
The argument \fImode\fR tells the handler if the channel was opened
for reading, writing, or both. It is a list containing any of the
strings "read" or "write". The list will always contain at least
one element.
.PP
The subcommand has to throw an error if the chosen mode is not
supported by the \fIhandlerCmd\fR.
.RE
.TP
\fIhandlerCmd \fBfinalize \fIchannel\fR
.
An invokation of this subcommand will be the last call the
\fIhandlerCmd\fR will receive for the specified new \fBchannel\fR. It
will be generated just before the destruction of the data structures
of the channel held by the Tcl core. Still, the command handler
\fBmust not\fR access the \fIchannel\fR anymore in no way. It is now
his responsibility to clean up any internal resources it allocated to
this channel.
.RS
.PP
The return value of the subcommand is ignored.
.PP
If the subcommand throws an error the command which caused its
invocation (usually \fBclose\fR) will appear to have thrown this
error.
.PP
Any exception beyond \fIerror\fR, like \fIbreak\fR, etc. is treated as
and converted to an error.
.PP
This subcommand is not invoked if the creation of the channel was
aborted during \fBinitialize\fR (See above).
.RE
.TP
\fIhandlerCmd \fBread \fIchannel count\fR
.
This subcommand is \fBoptional\fR. It is called when the user requests
data from a channel. \fIcount\fR specifies how many \fBbytes\fR have
been requested. If the subcommand is not supported then it is not
possible to read from the channel handled by the command.
.RS
.PP
The return value of the subcommand is taken as the requested data. If
the returned data contains more bytes than requested an error will be
signaled and later thrown by the command which performed the read
(usually \fBgets\fR or \fBread\fR). Returning less bytes than
requested is acceptable however.
.PP
If the subcommand throws an error the command which caused its
invocation (usually \fBgets\fR, or \fBread\fR) will appear to have
thrown this error.
.PP
Any exception beyond \fIerror\fR, like \fIbreak\fR, etc. is treated as
and converted to an error.
.RE
.TP
\fIhandlerCmd \fBwrite \fIchannel data\fR
.
This subcommand is \fBoptional\fR. It is called when the user writes
data to the channel. Note that the \fIdata\fR argument contains
\fBbytes\fR, not characters. Any type of transformation (EOL,
encoding) configured for the channel has already been applied at this
point. If the subcommand is not supported then it is not possible to
write to the channel handled by the command.
.RS
.PP
The return value of the subcommand is taken as the number of bytes
written by the channel. Anything non-numeric will cause an error to be
signaled and later thrown by the command which performed the write. A
negative value implies that the write failed. Returning a value
greater than the number of bytes given to the handler, or zero, is
forbidden and will cause the Tcl core to throw an error.
.PP
If the subcommand throws an error the command which caused its
invocation (usually \fBputs\fR) will appear to have thrown this error.
.PP
Any exception beyond \fIerror\fR, like \fIbreak\fR, etc. is treated as
and converted to an error.
.RE
.TP
\fIhandlerCmd \fBseek \fIchannel offset base\fR
.
This subcommand is \fBoptional\fR. It is responsible for the handling
of \fBseek\fR and \fBtell\fR requests on the channel. If it is not
supported then seeking will not be possible for the channel.
.RS
.PP
\fIbase\fR is one of
.TP 10
\fBstart\fR
.
Seeking is relative to the beginning of the channel.
.TP 10
\fBcurrent\fR
.
Seeking is relative to the current seek position.
.TP 10
\fBend	\fR
.
Seeking is relative to the end of the channel.
.PP
The base argument of the builtin \fBseek\fR command takes the same
names.
.PP
The \fIoffset\fR is an integer number specifying the amount of
\fBbytes\fR to seek forward or backward. A positive number will seek
forward, and a negative number will seek backward.
.PP
A channel may provide only limited seeking. For example sockets can
seek forward, but not backward.
.PP
The return value of the subcommand is taken as the (new) location of
the channel, counted from the start. This has to be an integer number
greater than or equal to zero.
.PP
If the subcommand throws an error the command which caused its
invocation (usually \fBseek\fR, or \fBtell\fR) will appear to have
thrown this error.
.PP
Any exception beyond \fIerror\fR, like \fIbreak\fR, etc. is treated as
and converted to an error.
.PP
The offset/base combination of 0/"current" signals a \fBtell\fR
request, i.e. seek nothing relative to the current location, making
the new location identical to the current one, which is then returned.
.RE
.TP
\fIhandlerCmd \fBconfigure \fIchannel option value\fR
.
This subcommand is \fBoptional\fR. It is for writing the type specific
options.
.RS
.PP
Per call one option will be written.
.PP
The return value of the subcommand is ignored.
.PP
If the subcommand throws an error the command which performed the
(re)configuration or query (usually \fBfconfigure\fR) will appear to
have thrown this error.
.PP
Any exception beyond \fIerror\fR, like \fIbreak\fR, etc. is treated as
and converted to an error.
.RE
.TP
\fIhandlerCmd \fBcget \fIchannel option\fR
.
This subcommand is \fBoptional\fR. It is used when reading a single
type specific option. If this subcommand is supported then the
subcommand \fBcgetall\fR has to be supported as well.
.RS
.PP
The call has to return the value of the specified \fIoption\fR.
.PP
If the subcommand throws an error the command which performed the
(re)configuration or query (usually \fBfconfigure\fR) will appear to
have thrown this error.
.RE
.TP
\fIhandlerCmd \fBcgetall \fIchannel\fR
.
This subcommand is \fBoptional\fR. It is used for reading all type
specific options. If this subcommand is supported then the subcommand
\fBcget\fR has to be supported as well.
.RS
.PP
It has to return a list of all options and their values. This list has
to have an even number of elements.
.PP
If the subcommand throws an error the command which performed the
(re)configuration or query (usually \fBfconfigure\fR) will appear to
have thrown this error.
.PP
Any exception beyond \fIerror\fR, like \fIbreak\fR, etc. is treated as
and converted to an error.
.RE
.TP
\fIhandlerCmd \fBwatch \fIchannel eventspec\fR
.
This subcommands notifies the \fIhandlerCmd\fR that the specified
\fIchannel\fR is interested in the events listed in the
\fIeventspec\fR. This argument is a list containing any of \fBread\fR
and \fBwrite\fR. The list can be empty. This signals that the channel
does not wish to be notified of any events. In other words, the
handler has to disable event generation completely.
.RS
.PP
Any return value of the subcommand is ignored. This includes errors
thrown by the subcommand, break, continue, and custom return codes.
.PP
This subcommand interacts with \fBchan postevent\fR. Trying to post an
event which was not listed in the last call to \fBwatch\fR will cause
\fBchan postenvent\fR to throw an error.
.RE
.TP
\fIhandlerCmd \fBblocking \fIchannel mode\fR
.
This subcommand is \fBoptional\fR. It handles changes to the blocking
mode of the channel. The \fImode\fR is a boolean flag. True means that
the channel has to be set to blocking. False means that the channel
should be non-blocking.
.RS
.PP
The return value of the subcommand is ignored.
.PP
If the subcommand throws an error the command which caused its
invocation (usually \fBfconfigure\fR) will appear to have thrown this
error.
.PP
Any exception beyond \fIerror\fR, like \fIbreak\fR, etc. is treated as
and converted to an error.
.RE
.SH NOTES
The function \fBTcl_DriverGetHandleProc\fR is not
supported. I.e. reflected channels do not have OS specific handles.
.PP
The function \fBTcl_DriverHandlerProc\fI is not supported. This driver
function is relevant only for stacked channels, i.e. transformations.
A reflected channel however is a base channel, not a transformation.
.PP
The function \fBTcl_DriverFlushProc\fR is not supported. The reason
for this: The current generic I/O layer of Tcl does not use this
function at all, nowhere. Therefore support at the Tcl level makes no
sense either. We can always extend the API defined here (and change
its version number) should the function be used at some time in the
future.
.SH "SEE ALSO"
chan(n)
.SH KEYWORDS
channel, reflection