OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / SGI / util / SGI / man / man3 / Tcl_GetChannelName.3
1 '\"
2 '\" Copyright (c) 1996-1997 Sun Microsystems, Inc.
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 '\" SCCS: @(#) CrtChannel.3 1.29 97/06/20 13:37:45
8 '\" The definitions below are for supplemental macros used in Tcl/Tk
9 '\" manual entries.
10 '\"
11 '\" .AP type name in/out ?indent?
12 '\"     Start paragraph describing an argument to a library procedure.
13 '\"     type is type of argument (int, etc.), in/out is either "in", "out",
14 '\"     or "in/out" to describe whether procedure reads or modifies arg,
15 '\"     and indent is equivalent to second arg of .IP (shouldn't ever be
16 '\"     needed;  use .AS below instead)
17 '\"
18 '\" .AS ?type? ?name?
19 '\"     Give maximum sizes of arguments for setting tab stops.  Type and
20 '\"     name are examples of largest possible arguments that will be passed
21 '\"     to .AP later.  If args are omitted, default tab stops are used.
22 '\"
23 '\" .BS
24 '\"     Start box enclosure.  From here until next .BE, everything will be
25 '\"     enclosed in one large box.
26 '\"
27 '\" .BE
28 '\"     End of box enclosure.
29 '\"
30 '\" .CS
31 '\"     Begin code excerpt.
32 '\"
33 '\" .CE
34 '\"     End code excerpt.
35 '\"
36 '\" .VS ?version? ?br?
37 '\"     Begin vertical sidebar, for use in marking newly-changed parts
38 '\"     of man pages.  The first argument is ignored and used for recording
39 '\"     the version when the .VS was added, so that the sidebars can be
40 '\"     found and removed when they reach a certain age.  If another argument
41 '\"     is present, then a line break is forced before starting the sidebar.
42 '\"
43 '\" .VE
44 '\"     End of vertical sidebar.
45 '\"
46 '\" .DS
47 '\"     Begin an indented unfilled display.
48 '\"
49 '\" .DE
50 '\"     End of indented unfilled display.
51 '\"
52 '\" .SO
53 '\"     Start of list of standard options for a Tk widget.  The
54 '\"     options follow on successive lines, in four columns separated
55 '\"     by tabs.
56 '\"
57 '\" .SE
58 '\"     End of list of standard options for a Tk widget.
59 '\"
60 '\" .OP cmdName dbName dbClass
61 '\"     Start of description of a specific option.  cmdName gives the
62 '\"     option's name as specified in the class command, dbName gives
63 '\"     the option's name in the option database, and dbClass gives
64 '\"     the option's class in the option database.
65 '\"
66 '\" .UL arg1 arg2
67 '\"     Print arg1 underlined, then print arg2 normally.
68 '\"
69 '\" SCCS: @(#) man.macros 1.9 97/08/22 18:50:59
70 '\"
71 '\"     # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
72 .if t .wh -1.3i ^B
73 .nr ^l \n(.l
74 .ad b
75 '\"     # Start an argument description
76 .de AP
77 .ie !"\\$4"" .TP \\$4
78 .el \{\
79 .   ie !"\\$2"" .TP \\n()Cu
80 .   el          .TP 15
81 .\}
82 .ie !"\\$3"" \{\
83 .ta \\n()Au \\n()Bu
84 \&\\$1  \\fI\\$2\\fP    (\\$3)
85 .\".b
86 .\}
87 .el \{\
88 .br
89 .ie !"\\$2"" \{\
90 \&\\$1  \\fI\\$2\\fP
91 .\}
92 .el \{\
93 \&\\fI\\$1\\fP
94 .\}
95 .\}
96 ..
97 '\"     # define tabbing values for .AP
98 .de AS
99 .nr )A 10n
100 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
101 .nr )B \\n()Au+15n
102 .\"
103 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
104 .nr )C \\n()Bu+\\w'(in/out)'u+2n
105 ..
106 .AS Tcl_Interp Tcl_CreateInterp in/out
107 '\"     # BS - start boxed text
108 '\"     # ^y = starting y location
109 '\"     # ^b = 1
110 .de BS
111 .br
112 .mk ^y
113 .nr ^b 1u
114 .if n .nf
115 .if n .ti 0
116 .if n \l'\\n(.lu\(ul'
117 .if n .fi
118 ..
119 '\"     # BE - end boxed text (draw box now)
120 .de BE
121 .nf
122 .ti 0
123 .mk ^t
124 .ie n \l'\\n(^lu\(ul'
125 .el \{\
126 .\"     Draw four-sided box normally, but don't draw top of
127 .\"     box if the box started on an earlier page.
128 .ie !\\n(^b-1 \{\
129 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
130 .\}
131 .el \}\
132 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
133 .\}
134 .\}
135 .fi
136 .br
137 .nr ^b 0
138 ..
139 '\"     # VS - start vertical sidebar
140 '\"     # ^Y = starting y location
141 '\"     # ^v = 1 (for troff;  for nroff this doesn't matter)
142 .de VS
143 .if !"\\$2"" .br
144 .mk ^Y
145 .ie n 'mc \s12\(br\s0
146 .el .nr ^v 1u
147 ..
148 '\"     # VE - end of vertical sidebar
149 .de VE
150 .ie n 'mc
151 .el \{\
152 .ev 2
153 .nf
154 .ti 0
155 .mk ^t
156 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
157 .sp -1
158 .fi
159 .ev
160 .\}
161 .nr ^v 0
162 ..
163 '\"     # Special macro to handle page bottom:  finish off current
164 '\"     # box/sidebar if in box/sidebar mode, then invoked standard
165 '\"     # page bottom macro.
166 .de ^B
167 .ev 2
168 'ti 0
169 'nf
170 .mk ^t
171 .if \\n(^b \{\
172 .\"     Draw three-sided box if this is the box's first page,
173 .\"     draw two sides but no top otherwise.
174 .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
175 .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
176 .\}
177 .if \\n(^v \{\
178 .nr ^x \\n(^tu+1v-\\n(^Yu
179 \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
180 .\}
181 .bp
182 'fi
183 .ev
184 .if \\n(^b \{\
185 .mk ^y
186 .nr ^b 2
187 .\}
188 .if \\n(^v \{\
189 .mk ^Y
190 .\}
191 ..
192 '\"     # DS - begin display
193 .de DS
194 .RS
195 .nf
196 .sp
197 ..
198 '\"     # DE - end display
199 .de DE
200 .fi
201 .RE
202 .sp
203 ..
204 '\"     # SO - start of list of standard options
205 .de SO
206 .SH "STANDARD OPTIONS"
207 .LP
208 .nf
209 .ta 4c 8c 12c
210 .ft B
211 ..
212 '\"     # SE - end of list of standard options
213 .de SE
214 .fi
215 .ft R
216 .LP
217 See the \\fBoptions\\fR manual entry for details on the standard options.
218 ..
219 '\"     # OP - start of full description for a single option
220 .de OP
221 .LP
222 .nf
223 .ta 4c
224 Command-Line Name:      \\fB\\$1\\fR
225 Database Name:  \\fB\\$2\\fR
226 Database Class: \\fB\\$3\\fR
227 .fi
228 .IP
229 ..
230 '\"     # CS - begin code excerpt
231 .de CS
232 .RS
233 .nf
234 .ta .25i .5i .75i 1i
235 ..
236 '\"     # CE - end code excerpt
237 .de CE
238 .fi
239 .RE
240 ..
241 .de UL
242 \\$1\l'|0\(ul'\\$2
243 ..
244 .TH Tcl_CreateChannel 3 8.0 Tcl "Tcl Library Procedures"
245 .BS
246 '\" Note:  do not modify the .SH NAME line immediately below!
247 .SH NAME
248 Tcl_CreateChannel, Tcl_GetChannelInstanceData, Tcl_GetChannelType, Tcl_GetChannelName, Tcl_GetChannelHandle, Tcl_GetChannelMode, Tcl_GetChannelBufferSize, Tcl_SetDefaultTranslation, Tcl_SetChannelBufferSize, Tcl_NotifyChannel, Tcl_BadChannelOption \- procedures for creating and manipulating channels
249 .SH SYNOPSIS
250 .nf
251 \fB#include <tcl.h>\fR
252 .sp
253 Tcl_Channel
254 \fBTcl_CreateChannel\fR(\fItypePtr, channelName, instanceData, mask\fR)
255 .sp
256 ClientData
257 \fBTcl_GetChannelInstanceData\fR(\fIchannel\fR)
258 .sp
259 Tcl_ChannelType *
260 \fBTcl_GetChannelType\fR(\fIchannel\fR)
261 .sp
262 char *
263 \fBTcl_GetChannelName\fR(\fIchannel\fR)
264 .VS
265 .sp
266 int
267 \fBTcl_GetChannelHandle\fR(\fIchannel, direction, handlePtr\fR)
268 .VE
269 .sp
270 int
271 \fBTcl_GetChannelFlags\fR(\fIchannel\fR)
272 .sp
273 \fBTcl_SetDefaultTranslation\fR(\fIchannel, transMode\fR)
274 .sp
275 int
276 \fBTcl_GetChannelBufferSize\fR(\fIchannel\fR)
277 .sp
278 \fBTcl_SetChannelBufferSize\fR(\fIchannel, size\fR)
279 .sp
280 .VS
281 \fBTcl_NotifyChannel\fR(\fIchannel, mask\fR)
282 .sp
283 int
284 \fBTcl_BadChannelOption\fR(\fIinterp, optionName, optionList\fR)
285 .VE
286 .sp
287 .SH ARGUMENTS
288 .AS Tcl_EolTranslation *channelName in
289 .AP Tcl_ChannelType *typePtr in
290 Points to a structure containing the addresses of procedures that
291 can be called to perform I/O and other functions on the channel.
292 .AP char *channelName in
293 The name of this channel, such as \fBfile3\fR; must not be in use
294 by any other channel. Can be NULL, in which case the channel is
295 created without a name.
296 .AP ClientData instanceData in
297 Arbitrary one-word value to be associated with this channel.  This
298 value is passed to procedures in \fItypePtr\fR when they are invoked.
299 .AP int mask in
300 OR-ed combination of \fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR to indicate
301 whether a channel is readable and writable.
302 .AP Tcl_Channel channel in
303 The channel to operate on.
304 .VS
305 .AP int direction in
306 \fBTCL_READABLE\fR means the input handle is wanted; \fBTCL_WRITABLE\fR
307 means the output handle is wanted.
308 .AP ClientData *handlePtr out
309 Points to the location where the desired OS-specific handle should be
310 stored.
311 .VE
312 .AP Tcl_EolTranslation transMode in
313 The translation mode; one of the constants \fBTCL_TRANSLATE_AUTO\fR,
314 \fBTCL_TRANSLATE_CR\fR, \fBTCL_TRANSLATE_LF\fR and \fBTCL_TRANSLATE_CRLF\fR.
315 .AP int size in
316 The size, in bytes, of buffers to allocate in this channel.
317 .VS
318 .AP int mask in
319 An OR-ed combination of \fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR
320 and \fBTCL_EXCEPTION\fR that indicates events that have occurred on
321 this channel.
322 .AP Tcl_Interp *interp in
323 Current interpreter. (can be NULL)
324 .AP char *optionName in
325 Name of the invalid option.
326 .AP char *optionList in
327 Specific options list (space separated words, without "-") 
328 to append to the standard generic options list.
329 Can be NULL for generic options error message only.
330 .VE
331
332 .BE
333
334 .SH DESCRIPTION
335 .PP
336 Tcl uses a two-layered channel architecture. It provides a generic upper
337 layer to enable C and Tcl programs to perform input and output using the
338 same APIs for a variety of files, devices, sockets etc. The generic C APIs
339 are described in the manual entry for \fBTcl_OpenFileChannel\fR.
340 .PP
341 The lower layer provides type-specific channel drivers for each type
342 of device supported on each platform.  This manual entry describes the
343 C APIs used to communicate between the generic layer and the
344 type-specific channel drivers.  It also explains how new types of
345 channels can be added by providing new channel drivers.
346 .PP
347 Channel drivers consist of a number of components: First, each channel
348 driver provides a \fBTcl_ChannelType\fR structure containing pointers to
349 functions implementing the various operations used by the generic layer to
350 communicate with the channel driver. The \fBTcl_ChannelType\fR structure
351 and the functions referenced by it are described in the section
352 TCL_CHANNELTYPE, below.
353 .PP
354 Second, channel drivers usually provide a Tcl command to create
355 instances of that type of channel. For example, the Tcl \fBopen\fR
356 command creates channels that use the file and command channel
357 drivers, and the Tcl \fBsocket\fR command creates channels that use
358 TCP sockets for network communication.
359 .PP
360 Third, a channel driver optionally provides a C function to open
361 channel instances of that type. For example, \fBTcl_OpenFileChannel\fR
362 opens a channel that uses the file channel driver, and
363 \fBTcl_OpenTcpClient\fR opens a channel that uses the TCP network
364 protocol.  These creation functions typically use
365 \fBTcl_CreateChannel\fR internally to open the channel.
366 .PP
367 To add a new type of channel you must implement a C API or a Tcl command
368 that opens a channel by invoking \fBTcl_CreateChannel\fR.
369 When your driver calls \fBTcl_CreateChannel\fR it passes in
370 a \fBTcl_ChannelType\fR structure describing the driver's I/O
371 procedures.
372 The generic layer will then invoke the functions referenced in that
373 structure to perform operations on the channel.
374 .PP
375 \fBTcl_CreateChannel\fR opens a new channel and associates the supplied
376 \fItypePtr\fR and \fIinstanceData\fR with it. The channel is opened in the
377 mode indicated by \fImask\fR.
378 For a discussion of channel drivers, their operations and the
379 \fBTcl_ChannelType\fR structure, see the section TCL_CHANNELTYPE, below.
380 .PP
381 \fBTcl_GetChannelInstanceData\fR returns the instance data associated with
382 the channel in \fIchannel\fR. This is the same as the \fIinstanceData\fR
383 argument in the call to \fBTcl_CreateChannel\fR that created this channel.
384 .PP
385 \fBTcl_GetChannelType\fR returns a pointer to the \fBTcl_ChannelType\fR
386 structure used by the channel in the \fIchannel\fR argument. This is
387 the same as the \fItypePtr\fR argument in the call to
388 \fBTcl_CreateChannel\fR that created this channel.
389 .PP
390 \fBTcl_GetChannelName\fR returns a string containing the name associated
391 with the channel, or NULL if the \fIchannelName\fR argument to
392 \fBTcl_CreateChannel\fR was NULL.
393 .PP
394 .VS
395 \fBTcl_GetChannelHandle\fR places the OS-specific device handle
396 associated with \fIchannel\fR for the given \fIdirection\fR in the
397 location specified by \fIhandlePtr\fR and returns \fBTCL_OK\fR.  If
398 the channel does not have a device handle for the specified direction,
399 then \fBTCL_ERROR\fR is returned instead.  Different channel drivers
400 will return different types of handle.  Refer to the manual entries
401 for each driver to determine what type of handle is returned.
402 .VE
403 .PP
404 \fBTcl_GetChannelMode\fR returns an OR-ed combination of \fBTCL_READABLE\fR
405 and \fBTCL_WRITABLE\fR, indicating whether the channel is open for input
406 and output.
407 .PP
408 \fBTcl_SetDefaultTranslation\fR sets the default end of line translation
409 mode. This mode will be installed as the translation mode for the channel
410 if an attempt is made to output on the channel while it is still in
411 \fBTCL_TRANSLATE_AUTO\fR mode. For a description of end of line translation
412 modes, see the manual entry for \fBfconfigure\fR.
413 .PP
414 \fBTcl_GetChannelBufferSize\fR returns the size, in bytes, of buffers
415 allocated to store input or output in \fIchan\fR. If the value was not set
416 by a previous call to \fBTcl_SetChannelBufferSize\fR, described below, then
417 the default value of 4096 is returned.
418 .PP
419 \fBTcl_SetChannelBufferSize\fR sets the size, in bytes, of buffers that
420 will be allocated in subsequent operations on the channel to store input or
421 output. The \fIsize\fR argument should be between ten and one million,
422 allowing buffers of ten bytes to one million bytes. If \fIsize\fR is
423 outside this range, \fBTcl_SetChannelBufferSize\fR sets the buffer size to
424 4096.
425 .PP
426 .VS
427 \fBTcl_NotifyChannel\fR is called by a channel driver to indicate to
428 the generic layer that the events specified by \fImask\fR have
429 occurred on the channel.  Channel drivers are responsible for invoking
430 this function whenever the channel handlers need to be called for the
431 channel.  See \fBWATCHPROC\fR below for more details.
432 .VE
433 .PP
434 .VS
435 \fBTcl_BadChannelOption\fR is called from driver specific set or get option
436 procs to generate a complete error message.
437 .VE
438
439 .SH TCL_CHANNELTYPE
440 .PP
441 A channel driver provides a \fBTcl_ChannelType\fR structure that contains
442 pointers to functions that implement the various operations on a channel;
443 these operations are invoked as needed by the generic layer. The
444 \fBTcl_ChannelType\fR structure contains the following fields:
445 .PP
446 .VS
447 .CS
448 typedef struct Tcl_ChannelType {
449         char *\fItypeName\fR;
450         Tcl_DriverBlockModeProc *\fIblockModeProc\fR;   
451         Tcl_DriverCloseProc *\fIcloseProc\fR;
452         Tcl_DriverInputProc *\fIinputProc\fR;
453         Tcl_DriverOutputProc *\fIoutputProc\fR;
454         Tcl_DriverSeekProc *\fIseekProc\fR;
455         Tcl_DriverSetOptionProc *\fIsetOptionProc\fR;
456         Tcl_DriverGetOptionProc *\fIgetOptionProc\fR;
457         Tcl_DriverWatchProc *\fIwatchProc\fR;
458         Tcl_DriverGetHandleProc *\fIgetHandleProc\fR;
459 } Tcl_ChannelType;
460 .CE
461 .VE
462 .PP
463 The driver must provide implementations for all functions except
464 \fIblockModeProc\fR, \fIseekProc\fR, \fIsetOptionProc\fR, and
465 \fIgetOptionProc\fR, which may be specified as NULL to indicate that the
466 channel does not support seeking.  Other functions that can not be
467 implemented for this type of device should return \fBEINVAL\fR when invoked
468 to indicate that they are not implemented.
469
470 .SH TYPENAME
471 .PP
472 The \fItypeName\fR field contains a null-terminated string that
473 identifies the type of the device implemented by this driver, e.g.
474 \fBfile\fR or \fBsocket\fR.
475
476 .SH BLOCKMODEPROC
477 .PP
478 The \fIblockModeProc\fR field contains the address of a function called by
479 the generic layer to set blocking and nonblocking mode on the device.
480 \fIBlockModeProc\fR should match the following prototype:
481 .PP
482 .CS
483 typedef int Tcl_DriverBlockModeProc(
484         ClientData \fIinstanceData\fR,
485         int \fImode\fR);
486 .CE
487 .PP
488 The \fIinstanceData\fR is the same as the value passed to
489 \fBTcl_CreateChannel\fR when this channel was created.  The \fImode\fR
490 argument is either \fBTCL_MODE_BLOCKING\fR or \fBTCL_MODE_NONBLOCKING\fR to
491 set the device into blocking or nonblocking mode. The function should
492 return zero if the operation was successful, or a nonzero POSIX error code
493 if the operation failed.
494 .PP
495 If the operation is successful, the function can modify the supplied
496 \fIinstanceData\fR to record that the channel entered blocking or
497 nonblocking mode and to implement the blocking or nonblocking behavior.
498 For some device types, the blocking and nonblocking behavior can be
499 implemented by the underlying operating system; for other device types, the
500 behavior must be emulated in the channel driver.
501
502 .SH CLOSEPROC
503 .PP
504 The \fIcloseProc\fR field contains the address of a function called by the
505 generic layer to clean up driver-related information when the channel is
506 closed. \fICloseProc\fR must match the following prototype:
507 .PP
508 .CS
509 typedef int Tcl_DriverCloseProc(
510         ClientData \fIinstanceData\fR,
511         Tcl_Interp *\fIinterp\fR);
512 .CE
513 .PP
514 The \fIinstanceData\fR argument is the same as the value provided to
515 \fBTcl_CreateChannel\fR when the channel was created. The function should
516 release any storage maintained by the channel driver for this channel, and
517 close the input and output devices encapsulated by this channel. All queued
518 output will have been flushed to the device before this function is called,
519 and no further driver operations will be invoked on this instance after
520 calling the \fIcloseProc\fR. If the close operation is successful, the
521 procedure should return zero; otherwise it should return a nonzero POSIX
522 error code. In addition, if an error occurs and \fIinterp\fR is not NULL,
523 the procedure should store an error message in \fIinterp->result\fR.
524
525 .SH INPUTPROC
526 .PP
527 The \fIinputProc\fR field contains the address of a function called by the
528 generic layer to read data from the file or device and store it in an
529 internal buffer. \fIInputProc\fR must match the following prototype:
530 .PP
531 .CS
532 typedef int Tcl_DriverInputProc(
533         ClientData \fIinstanceData\fR,
534         char *\fIbuf\fR,
535         int \fIbufSize\fR,
536         int *\fIerrorCodePtr\fR);
537 .CE
538 .PP
539 \fIInstanceData\fR is the same as the value passed to
540 \fBTcl_CreateChannel\fR when the channel was created.  The \fIbuf\fR
541 argument points to an array of bytes in which to store input from the
542 device, and the \fIbufSize\fR argument indicates how many bytes are
543 available at \fIbuf\fR.
544 .PP
545 The \fIerrorCodePtr\fR argument points to an integer variable provided by
546 the generic layer. If an error occurs, the function should set the variable
547 to a POSIX error code that identifies the error that occurred.
548 .PP
549 The function should read data from the input device encapsulated by the
550 channel and store it at \fIbuf\fR.  On success, the function should return
551 a nonnegative integer indicating how many bytes were read from the input
552 device and stored at \fIbuf\fR. On error, the function should return -1. If
553 an error occurs after some data has been read from the device, that data is
554 lost.
555 .PP
556 If \fIinputProc\fR can determine that the input device has some data
557 available but less than requested by the \fIbufSize\fR argument, the
558 function should only attempt to read as much data as is available and
559 return without blocking. If the input device has no data available
560 whatsoever and the channel is in nonblocking mode, the function should
561 return an \fBEAGAIN\fR error. If the input device has no data available
562 whatsoever and the channel is in blocking mode, the function should block
563 for the shortest possible time until at least one byte of data can be read
564 from the device; then, it should return as much data as it can read without
565 blocking.
566
567 .SH OUTPUTPROC
568 .PP
569 The \fIoutputProc\fR field contains the address of a function called by the
570 generic layer to transfer data from an internal buffer to the output device.
571 \fIOutputProc\fR must match the following prototype:
572 .PP
573 .CS
574 typedef int Tcl_DriverOutputProc(
575         ClientData \fIinstanceData\fR,
576         char *\fIbuf\fR,
577         int \fItoWrite\fR,
578         int *\fIerrorCodePtr\fR);
579 .CE
580 .PP
581 \fIInstanceData\fR is the same as the value passed to
582 \fBTcl_CreateChannel\fR when the channel was created. The \fIbuf\fR
583 argument contains an array of bytes to be written to the device, and the
584 \fItoWrite\fR argument indicates how many bytes are to be written from the
585 \fIbuf\fR argument.
586 .PP
587 The \fIerrorCodePtr\fR argument points to an integer variable provided by
588 the generic layer. If an error occurs, the function should set this
589 variable to a POSIX error code that identifies the error.
590 .PP
591 The function should write the data at \fIbuf\fR to the output device
592 encapsulated by the channel. On success, the function should return a
593 nonnegative integer indicating how many bytes were written to the output
594 device.  The return value is normally the same as \fItoWrite\fR, but may be
595 less in some cases such as if the output operation is interrupted by a
596 signal. If an error occurs the function should return -1.  In case of
597 error, some data may have been written to the device.
598 .PP
599 If the channel is nonblocking and the output device is unable to absorb any
600 data whatsoever, the function should return -1 with an \fBEAGAIN\fR error
601 without writing any data.
602
603 .SH SEEKPROC
604 .PP
605 The \fIseekProc\fR field contains the address of a function called by the
606 generic layer to move the access point at which subsequent input or output
607 operations will be applied. \fISeekProc\fR must match the following
608 prototype:
609 .PP
610 .CS
611 typedef int Tcl_DriverSeekProc(
612         ClientData \fIinstanceData\fR,
613         long \fIoffset\fR,
614         int \fIseekMode\fR,
615         int *\fIerrorCodePtr\fR);
616 .CE
617 .PP
618 The \fIinstanceData\fR argument is the same as the value given to
619 \fBTcl_CreateChannel\fR when this channel was created.  \fIOffset\fR and
620 \fIseekMode\fR have the same meaning as for the \fBTcl_SeekChannel\fR
621 procedure (described in the manual entry for \fBTcl_OpenFileChannel\fR).
622 .PP
623 The \fIerrorCodePtr\fR argument points to an integer variable provided by
624 the generic layer for returning \fBerrno\fR values from the function.  The
625 function should set this variable to a POSIX error code if an error occurs.
626 The function should store an \fBEINVAL\fR error code if the channel type
627 does not implement seeking.
628 .PP
629 The return value is the new access point or -1 in case of error. If an
630 error occurred, the function should not move the access point.
631
632 .SH SETOPTIONPROC
633 .PP
634 The \fIsetOptionProc\fR field contains the address of a function called by
635 the generic layer to set a channel type specific option on a channel.
636 \fIsetOptionProc\fR must match the following prototype:
637 .PP
638 .CS
639 typedef int Tcl_DriverSetOptionProc(
640         ClientData \fIinstanceData\fR,
641         Tcl_Interp *\fIinterp\fR,
642         char *\fIoptionName\fR,
643         char *\fIoptionValue\fR);
644 .CE
645 .PP
646 \fIoptionName\fR is the name of an option to set, and \fIoptionValue\fR is
647 the new value for that option, as a string. The \fIinstanceData\fR is the
648 same as the value given to \fBTcl_CreateChannel\fR when this channel was
649 created. The function should do whatever channel type specific action is
650 required to implement the new value of the option.
651 .PP
652 Some options are handled by the generic code and this function is never
653 called to set them, e.g. \fB-blockmode\fR. Other options are specific to
654 each channel type and the \fIsetOptionProc\fR procedure of the channel
655 driver will get called to implement them. The \fIsetOptionProc\fR field can
656 be NULL, which indicates that this channel type supports no type specific
657 options. 
658 .PP
659 If the option value is successfully modified to the new value, the function
660 returns \fBTCL_OK\fR.
661 .VS
662 It should call \fBTcl_BadChannelOption\fR which itself returns
663 \fBTCL_ERROR\fR if the \fIoptionName\fR is
664 unrecognized. 
665 .VE
666 If \fIoptionValue\fR specifies a value for the option that
667 is not supported or if a system call error occurs,
668 the function should leave an error message in the
669 \fIresult\fR field of \fIinterp\fR if \fIinterp\fR is not NULL. The
670 function should also call \fBTcl_SetErrno\fR to store an appropriate POSIX
671 error code.
672
673 .SH GETOPTIONPROC
674 .PP
675 The \fIgetOptionProc\fR field contains the address of a function called by
676 the generic layer to get the value of a channel type specific option on a
677 channel. \fIgetOptionProc\fR must match the following prototype:
678 .PP
679 .CS
680 typedef int Tcl_DriverGetOptionProc(
681         ClientData \fIinstanceData\fR,
682 .VS
683         Tcl_Interp *\fIinterp\fR,
684 .VE
685         char *\fIoptionName\fR,
686         Tcl_DString *\fIdsPtr\fR);
687 .CE
688 .PP
689 \fIOptionName\fR is the name of an option supported by this type of
690 channel. If the option name is not NULL, the function stores its current
691 value, as a string, in the Tcl dynamic string \fIdsPtr\fR.
692 If \fIoptionName\fR is NULL, the function stores in \fIdsPtr\fR an
693 alternating list of all supported options and their current values.
694 On success, the function returns \fBTCL_OK\fR. 
695 .VS
696 It should call \fBTcl_BadChannelOption\fR which itself returns
697 \fBTCL_ERROR\fR if the \fIoptionName\fR is
698 unrecognized. If a system call error occurs,
699 the function should leave an error message in the
700 \fIresult\fR field of \fIinterp\fR if \fIinterp\fR is not NULL. The
701 function should also call \fBTcl_SetErrno\fR to store an appropriate POSIX
702 error code.
703 .VE
704 .PP
705 Some options are handled by the generic code and this function is never
706 called to retrieve their value, e.g. \fB-blockmode\fR. Other options are
707 specific to each channel type and the \fIgetOptionProc\fR procedure of the
708 channel driver will get called to implement them. The \fIgetOptionProc\fR
709 field can be NULL, which indicates that this channel type supports no type
710 specific options.
711
712 .SH WATCHPROC
713 .VS
714 .PP
715 The \fIwatchProc\fR field contains the address of a function called
716 by the generic layer to initialize the event notification mechanism to
717 notice events of interest on this channel.
718 \fIWatchProc\fR should match the following prototype:
719 .PP
720 .CS
721 typedef void Tcl_DriverWatchProc(
722         ClientData \fIinstanceData\fR,
723         int \fImask\fR);
724 .CE
725 .VE
726 .PP
727 The \fIinstanceData\fR is the same as the value passed to
728 \fBTcl_CreateChannel\fR when this channel was created. The \fImask\fR
729 argument is an OR-ed combination of \fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR
730 and \fBTCL_EXCEPTION\fR; it indicates events the caller is interested in
731 noticing on this channel.
732 .PP
733 .VS
734 The function should initialize device type specific mechanisms to
735 notice when an event of interest is present on the channel.  When one
736 or more of the designated events occurs on the channel, the channel
737 driver is responsible for calling \fBTcl_NotifyChannel\fR to inform
738 the generic channel module.  The driver should take care not to starve
739 other channel drivers or sources of callbacks by invoking
740 Tcl_NotifyChannel too frequently.  Fairness can be insured by using
741 the Tcl event queue to allow the channel event to be scheduled in sequence
742 with other events.  See the description of \fBTcl_QueueEvent\fR for
743 details on how to queue an event.
744
745 .SH GETHANDLEPROC
746 .PP
747 The \fIgetHandleProc\fR field contains the address of a function called by
748 the generic layer to retrieve a device-specific handle from the channel.
749 \fIGetHandleProc\fR should match the following prototype:
750 .PP
751 .CS
752 typedef int Tcl_DriverGetHandleProc(
753         ClientData \fIinstanceData\fR,
754         int \fIdirection\fR,
755         ClientData *\fIhandlePtr\fR);
756 .CE
757 .PP
758 \fIInstanceData is the same as the value passed to
759 \fBTcl_CreateChannel\fR when this channel was created. The \fIdirection\fR
760 argument is either \fBTCL_READABLE\fR to retrieve the handle used
761 for input, or \fBTCL_WRITABLE\fR to retrieve the handle used for
762 output.
763 .PP
764 If the channel implementation has device-specific handles, the
765 function should retrieve the appropriate handle associated with the
766 channel, according the \fIdirection\fR argument.  The handle should be
767 stored in the location referred to by \fIhandlePtr\fR, and
768 \fBTCL_OK\fR should be returned.  If the channel is not open for the
769 specified direction, or if the channel implementation does not use
770 device handles, the function should return \fBTCL_ERROR\fR.
771 .VE
772
773 .VS
774 .SH TCL_BADCHANNELOPTION
775 .PP
776 This procedure generates a "bad option" error message in an
777 (optional) interpreter.  It is used by channel drivers when 
778 a invalid Set/Get option is requested. Its purpose is to concatenate
779 the generic options list to the specific ones and factorize
780 the generic options error message string.
781 .PP
782 It always return \fBTCL_ERROR\fR
783 .PP
784 An error message is generated in interp's result object to
785 indicate that a command was invoked with the a bad option
786 The message has the form
787 .CS
788     bad option "blah": should be one of 
789     <...generic options...>+<...specific options...>
790 so you get for instance:
791     bad option "-blah": should be one of -blocking,
792     -buffering, -buffersize, -eofchar, -translation,
793     -peername, or -sockname
794 when called with optionList="peername sockname"
795 .CE
796 "blah" is the optionName argument and "<specific options>"
797 is a space separated list of specific option words.
798 The function takes good care of inserting minus signs before
799 each option, commas after, and an "or" before the last option.
800 .VE
801
802 .SH "SEE ALSO"
803 Tcl_Close(3), Tcl_OpenFileChannel(3), Tcl_SetErrno(3), Tcl_QueueEvent(3)
804
805 .SH KEYWORDS
806 blocking, channel driver, channel registration, channel type, nonblocking