Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/refchan.n @ 25

Last change on this file since 25 was 25, checked in by landauf, 17 years ago

added tcl to libs

File size: 11.0 KB
Line 
1'\"
2'\" Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>
3'\"
4'\" See the file "license.terms" for information on usage and redistribution
5'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6'\"
7'\" RCS: @(#) $Id: refchan.n,v 1.11 2008/03/26 09:59:22 dkf Exp $
8.so man.macros
9.TH refchan n 8.5 Tcl "Tcl Built-In Commands"
10.BS
11.\" Note:  do not modify the .SH NAME line immediately below!
12.SH NAME
13refchan \- Command handler API of reflected channels, version 1
14.SH SYNOPSIS
15\fBcmdPrefix \fIoption\fR ?\fIarg arg ...\fR?
16.BE
17.SH DESCRIPTION
18.PP
19The Tcl-level handler for a reflected channel has to be a command with
20subcommands (termed an \fIensemble\fR, as it is a command such as that
21created by \fBnamespace ensemble create\fR, though the implementation
22of handlers for reflected channel \fIis not\fR tied to \fBnamespace
23ensemble\fRs in any way). Note that \fIcmdPrefix\fR is whatever was
24specified in the call to \fBchan create\fR, and may consist of
25multiple arguments; this will be expanded to multiple words in place
26of the prefix.
27.PP
28Of all the possible subcommands, the handler \fImust\fR support
29\fBinitialize\fR, \fBfinalize\fR, and \fBwatch\fR. Support for the
30other subcommands is optional.
31.SS "MANDATORY SUBCOMMANDS"
32.TP
33\fIcmdPrefix \fBinitialize \fIchannelId mode\fR
34.
35An invocation of this subcommand will be the first call the
36\fIcmdPrefix\fR will receive for the specified new \fIchannelId\fR. It
37is the responsibility of this subcommand to set up any internal data
38structures required to keep track of the channel and its state.
39.RS
40.PP
41The return value of the method has to be a list containing the names
42of all subcommands supported by the \fIcmdPrefix\fR. This also tells
43the Tcl core which version of the API for reflected channels is used by
44this command handler.
45.PP
46Any error thrown by the method will abort the creation of the channel
47and no channel will be created. The thrown error will appear as error
48thrown by \fBchan create\fR. Any exception other than an \fBerror\fR
49(e.g. \fBbreak\fR, etc.) is treated as (and converted to) an error.
50.PP
51\fBNote:\fR If the creation of the channel was aborted due to failures
52here, then the \fBfinalize\fR subcommand will not be called.
53.PP
54The \fImode\fR argument tells the handler whether the channel was
55opened for reading, writing, or both. It is a list containing any of
56the strings \fBread\fR or \fBwrite\fR. The list will always
57contain at least one element.
58.PP
59The subcommand must throw an error if the chosen mode is not
60supported by the \fIcmdPrefix\fR.
61.RE
62.TP
63\fIcmdPrefix \fBfinalize \fIchannelId\fR
64.
65An invocation of this subcommand will be the last call the
66\fIcmdPrefix\fR will receive for the specified \fIchannelId\fR. It will
67be generated just before the destruction of the data structures of the
68channel held by the Tcl core. The command handler \fImust not\fR
69access the \fIchannelId\fR anymore in no way. Upon this subcommand being
70called, any internal resources allocated to this channel must be
71cleaned up.
72.RS
73.PP
74The return value of this subcommand is ignored.
75.PP
76If the subcommand throws an error the command which caused its
77invocation (usually \fBclose\fR) will appear to have thrown this
78error. Any exception beyond \fIerror\fR (e.g. \fIbreak\fR, etc.) is
79treated as (and converted to) an error.
80.PP
81This subcommand is not invoked if the creation of the channel was
82aborted during \fBinitialize\fR (See above).
83.RE
84.TP
85\fIcmdPrefix \fBwatch \fIchannelId eventspec\fR
86.
87This subcommand notifies the \fIcmdPrefix\fR that the specified
88\fIchannelId\fR is interested in the events listed in the
89\fIeventspec\fR. This argument is a list containing any of \fBread\fR
90and \fBwrite\fR. The list may be empty, which signals that the
91channel does not wish to be notified of any events. In that situation,
92the handler should disable event generation completely.
93.RS
94.PP
95\fBWarning:\fR Any return value of the subcommand is ignored. This
96includes all errors thrown by the subcommand, break, continue, and
97custom return codes.
98.PP
99This subcommand interacts with \fBchan postevent\fR. Trying to post an
100event which was not listed in the last call to \fBwatch\fR will cause
101\fBchan postevent\fR to throw an error.
102.RE
103.SS "OPTIONAL SUBCOMMANDS"
104.TP
105\fIcmdPrefix \fBread \fIchannelId count\fR
106.
107This \fIoptional\fR subcommand is called when the user requests data from the
108channel \fIchannelId\fR. \fIcount\fR specifies how many \fBbytes\fR have been
109requested. If the subcommand is not supported then it is not possible to read
110from the channel handled by the command.
111.RS
112.PP
113The return value of this subcommand is taken as the requested data
114\fIbytes\fR. If the returned data contains more bytes than requested,
115an error will be signaled and later thrown by the command which
116performed the read (usually \fBgets\fR or \fBread\fR). However,
117returning fewer bytes than requested is acceptable.
118.PP
119If the subcommand throws an error, the command which caused its
120invocation (usually \fBgets\fR, or \fBread\fR) will appear to have
121thrown this error. Any exception beyond \fIerror\fR, (e.g.
122\fIbreak\fR, etc.) is treated as and converted to an error.
123.RE
124.TP
125\fIcmdPrefix \fBwrite \fIchannelId data\fR
126.
127This \fIoptional\fR subcommand is called when the user writes data to
128the channel \fIchannelId\fR. The \fIdata\fR argument contains \fIbytes\fR, not
129characters. Any type of transformation (EOL, encoding) configured for
130the channel has already been applied at this point. If this subcommand
131is not supported then it is not possible to write to the channel
132handled by the command.
133.RS
134.PP
135The return value of the subcommand is taken as the number of bytes
136written by the channel. Anything non-numeric will cause an error to be
137signaled and later thrown by the command which performed the write. A
138negative value implies that the write failed. Returning a value
139greater than the number of bytes given to the handler, or zero, is
140forbidden and will cause the Tcl core to throw an error.
141.PP
142If the subcommand throws an error the command which caused its
143invocation (usually \fBputs\fR) will appear to have thrown this error.
144Any exception beyond \fIerror\fR (e.g. \fIbreak\fR, etc.) is treated
145as and converted to an error.
146.RE
147.TP
148\fIcmdPrefix \fBseek \fIchannelId offset base\fR
149.
150This \fIoptional\fR subcommand is responsible for the handling of
151\fBseek\fR and \fBtell\fR requests on the channel \fIchannelId\fR. If it is not
152supported then seeking will not be possible for the channel.
153.RS
154.PP
155The \fIbase\fR argument is one of
156.TP 10
157\fBstart\fR
158.
159Seeking is relative to the beginning of the channel.
160.TP 10
161\fBcurrent\fR
162.
163Seeking is relative to the current seek position.
164.TP 10
165\fBend\fR
166.
167Seeking is relative to the end of the channel.
168.PP
169The \fIbase\fR argument of the builtin \fBchan seek\fR command takes
170the same names.
171.PP
172The \fIoffset\fR is an integer number specifying the amount of
173\fBbytes\fR to seek forward or backward. A positive number should seek
174forward, and a negative number should seek backward.
175.PP
176A channel may provide only limited seeking. For example sockets can
177seek forward, but not backward.
178.PP
179The return value of the subcommand is taken as the (new) location of
180the channel, counted from the start. This has to be an integer number
181greater than or equal to zero.
182.PP
183If the subcommand throws an error the command which caused its
184invocation (usually \fBseek\fR, or \fBtell\fR) will appear to have
185thrown this error. Any exception beyond \fIerror\fR (e.g. \fIbreak\fR,
186etc.) is treated as and converted to an error.
187.PP
188The offset/base combination of 0/\fBcurrent\fR signals a \fBtell\fR
189request, i.e. seek nothing relative to the current location, making
190the new location identical to the current one, which is then returned.
191.RE
192.TP
193\fIcmdPrefix \fBconfigure \fIchannelId option value\fR
194.
195This \fIoptional\fR subcommand is for setting the type-specific options of
196channel \fIchannelId\fR. The \fIoption\fR argument indicates the option to be
197written, and the \fIvalue\fR argument indicates the value to set the option to.
198.RS
199.PP
200This subcommand will never try to update more than one option at a
201time; that is behavior implemented in the Tcl channel core.
202.PP
203The return value of the subcommand is ignored.
204.PP
205If the subcommand throws an error the command which performed the
206(re)configuration or query (usually \fBfconfigure\fR or \fBchan
207configure\fR) will appear to have thrown this error. Any exception
208beyond \fIerror\fR (e.g. \fIbreak\fR, etc.) is treated as and
209converted to an error.
210.RE
211.TP
212\fIcmdPrefix \fBcget \fIchannelId option\fR
213.
214This \fIoptional\fR subcommand is used when reading a single type-specific
215option of channel \fIchannelId\fR. If this subcommand is supported then the
216subcommand \fBcgetall\fR must be supported as well.
217.RS
218.PP
219The subcommand should return the value of the specified \fIoption\fR.
220.PP
221If the subcommand throws an error, the command which performed the
222(re)configuration or query (usually \fBfconfigure\fR) will appear to
223have thrown this error. Any exception beyond \fIerror\fR (e.g.
224\fIbreak\fR, etc.) is treated as and converted to an error.
225.RE
226.TP
227\fIcmdPrefix \fBcgetall \fIchannelId\fR
228.
229This \fIoptional\fR subcommand is used for reading all type-specific options
230of channel \fIchannelId\fR. If this subcommand is supported then the
231subcommand \fBcget\fR has to be supported as well.
232.RS
233.PP
234The subcommand should return a list of all options and their values.
235This list must have an even number of elements.
236.PP
237If the subcommand throws an error the command which performed the
238(re)configuration or query (usually \fBfconfigure\fR) will appear to
239have thrown this error. Any exception beyond \fIerror\fR (e.g.
240\fIbreak\fR, etc.) is treated as and converted to an error.
241.RE
242.TP
243\fIcmdPrefix \fBblocking \fIchannelId mode\fR
244.
245This \fIoptional\fR subcommand handles changes to the blocking mode of the
246channel \fIchannelId\fR. The \fImode\fR is a boolean flag. A true value means
247that the channel has to be set to blocking, and a false value means that the
248channel should be non-blocking.
249.RS
250.PP
251The return value of the subcommand is ignored.
252.PP
253If the subcommand throws an error the command which caused its
254invocation (usually \fBfconfigure\fR) will appear to have thrown this
255error. Any exception beyond \fIerror\fR (e.g. \fIbreak\fR, etc.) is
256treated as and converted to an error.
257.RE
258.SH NOTES
259Some of the functions supported in channels defined in Tcl's C
260interface are not available to channels reflected to the Tcl level.
261.PP
262The function \fBTcl_DriverGetHandleProc\fR is not supported; i.e.
263reflected channels do not have OS specific handles.
264.PP
265The function \fBTcl_DriverHandlerProc\fR is not supported. This driver
266function is relevant only for stacked channels, i.e. transformations.
267Reflected channels are always base channels, not transformations.
268.PP
269The function \fBTcl_DriverFlushProc\fR is not supported. This is
270because the current generic I/O layer of Tcl does not use this
271function anywhere at all. Therefore support at the Tcl level makes no
272sense either. This may be altered in the future (through extending the
273API defined here and changing its version number) should the function
274be used at some time in the future.
275.SH "SEE ALSO"
276chan(n)
277.SH KEYWORDS
278channel, reflection
Note: See TracBrowser for help on using the repository browser.