OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / HP / util / HP / man / man3 / Tcl_GetChannelType.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 '\" RCS: @(#) $Id: CrtChannel.3,v 1.5 2000/04/14 23:01:49 hobbs Exp $
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 '\" RCS: @(#) $Id: man.macros,v 1.3 1999/04/16 00:46:35 stanton Exp $
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 .ta \\n()Au \\n()Bu
83 .ie !"\\$3"" \{\
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_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_GetChannelBufferSize\fR(\fIchannel\fR)
272 .sp
273 \fBTcl_SetChannelBufferSize\fR(\fIchannel, size\fR)
274 .sp
275 .VS
276 \fBTcl_NotifyChannel\fR(\fIchannel, mask\fR)
277 .sp
278 int
279 \fBTcl_BadChannelOption\fR(\fIinterp, optionName, optionList\fR)
280 .VE
281 .sp
282 .SH ARGUMENTS
283 .AS Tcl_EolTranslation *channelName in
284 .AP Tcl_ChannelType *typePtr in
285 Points to a structure containing the addresses of procedures that
286 can be called to perform I/O and other functions on the channel.
287 .AP char *channelName in
288 The name of this channel, such as \fBfile3\fR; must not be in use
289 by any other channel. Can be NULL, in which case the channel is
290 created without a name.
291 .AP ClientData instanceData in
292 Arbitrary one-word value to be associated with this channel.  This
293 value is passed to procedures in \fItypePtr\fR when they are invoked.
294 .AP int mask in
295 OR-ed combination of \fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR to indicate
296 whether a channel is readable and writable.
297 .AP Tcl_Channel channel in
298 The channel to operate on.
299 .VS
300 .AP int direction in
301 \fBTCL_READABLE\fR means the input handle is wanted; \fBTCL_WRITABLE\fR
302 means the output handle is wanted.
303 .AP ClientData *handlePtr out
304 Points to the location where the desired OS-specific handle should be
305 stored.
306 .VE
307 .AP Tcl_EolTranslation transMode in
308 The translation mode; one of the constants \fBTCL_TRANSLATE_AUTO\fR,
309 \fBTCL_TRANSLATE_CR\fR, \fBTCL_TRANSLATE_LF\fR and \fBTCL_TRANSLATE_CRLF\fR.
310 .AP int size in
311 The size, in bytes, of buffers to allocate in this channel.
312 .VS
313 .AP int mask in
314 An OR-ed combination of \fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR
315 and \fBTCL_EXCEPTION\fR that indicates events that have occurred on
316 this channel.
317 .AP Tcl_Interp *interp in
318 Current interpreter. (can be NULL)
319 .AP char *optionName in
320 Name of the invalid option.
321 .AP char *optionList in
322 Specific options list (space separated words, without "-") 
323 to append to the standard generic options list.
324 Can be NULL for generic options error message only.
325 .VE
326
327 .BE
328
329 .SH DESCRIPTION
330 .PP
331 Tcl uses a two-layered channel architecture. It provides a generic upper
332 layer to enable C and Tcl programs to perform input and output using the
333 same APIs for a variety of files, devices, sockets etc. The generic C APIs
334 are described in the manual entry for \fBTcl_OpenFileChannel\fR.
335 .PP
336 The lower layer provides type-specific channel drivers for each type
337 of device supported on each platform.  This manual entry describes the
338 C APIs used to communicate between the generic layer and the
339 type-specific channel drivers.  It also explains how new types of
340 channels can be added by providing new channel drivers.
341 .PP
342 Channel drivers consist of a number of components: First, each channel
343 driver provides a \fBTcl_ChannelType\fR structure containing pointers to
344 functions implementing the various operations used by the generic layer to
345 communicate with the channel driver. The \fBTcl_ChannelType\fR structure
346 and the functions referenced by it are described in the section
347 TCL_CHANNELTYPE, below.
348 .PP
349 Second, channel drivers usually provide a Tcl command to create
350 instances of that type of channel. For example, the Tcl \fBopen\fR
351 command creates channels that use the file and command channel
352 drivers, and the Tcl \fBsocket\fR command creates channels that use
353 TCP sockets for network communication.
354 .PP
355 Third, a channel driver optionally provides a C function to open
356 channel instances of that type. For example, \fBTcl_OpenFileChannel\fR
357 opens a channel that uses the file channel driver, and
358 \fBTcl_OpenTcpClient\fR opens a channel that uses the TCP network
359 protocol.  These creation functions typically use
360 \fBTcl_CreateChannel\fR internally to open the channel.
361 .PP
362 To add a new type of channel you must implement a C API or a Tcl command
363 that opens a channel by invoking \fBTcl_CreateChannel\fR.
364 When your driver calls \fBTcl_CreateChannel\fR it passes in
365 a \fBTcl_ChannelType\fR structure describing the driver's I/O
366 procedures.
367 The generic layer will then invoke the functions referenced in that
368 structure to perform operations on the channel.
369 .PP
370 \fBTcl_CreateChannel\fR opens a new channel and associates the supplied
371 \fItypePtr\fR and \fIinstanceData\fR with it. The channel is opened in the
372 mode indicated by \fImask\fR.
373 For a discussion of channel drivers, their operations and the
374 \fBTcl_ChannelType\fR structure, see the section TCL_CHANNELTYPE, below.
375 .PP
376 \fBTcl_GetChannelInstanceData\fR returns the instance data associated with
377 the channel in \fIchannel\fR. This is the same as the \fIinstanceData\fR
378 argument in the call to \fBTcl_CreateChannel\fR that created this channel.
379 .PP
380 \fBTcl_GetChannelType\fR returns a pointer to the \fBTcl_ChannelType\fR
381 structure used by the channel in the \fIchannel\fR argument. This is
382 the same as the \fItypePtr\fR argument in the call to
383 \fBTcl_CreateChannel\fR that created this channel.
384 .PP
385 \fBTcl_GetChannelName\fR returns a string containing the name associated
386 with the channel, or NULL if the \fIchannelName\fR argument to
387 \fBTcl_CreateChannel\fR was NULL.
388 .PP
389 .VS
390 \fBTcl_GetChannelHandle\fR places the OS-specific device handle
391 associated with \fIchannel\fR for the given \fIdirection\fR in the
392 location specified by \fIhandlePtr\fR and returns \fBTCL_OK\fR.  If
393 the channel does not have a device handle for the specified direction,
394 then \fBTCL_ERROR\fR is returned instead.  Different channel drivers
395 will return different types of handle.  Refer to the manual entries
396 for each driver to determine what type of handle is returned.
397 .VE
398 .PP
399 \fBTcl_GetChannelMode\fR returns an OR-ed combination of \fBTCL_READABLE\fR
400 and \fBTCL_WRITABLE\fR, indicating whether the channel is open for input
401 and output.
402 .PP
403  \fBTcl_GetChannelBufferSize\fR returns the size, in bytes, of buffers
404 allocated to store input or output in \fIchan\fR. If the value was not set
405 by a previous call to \fBTcl_SetChannelBufferSize\fR, described below, then
406 the default value of 4096 is returned.
407 .PP
408 \fBTcl_SetChannelBufferSize\fR sets the size, in bytes, of buffers that
409 will be allocated in subsequent operations on the channel to store input or
410 output. The \fIsize\fR argument should be between ten and one million,
411 allowing buffers of ten bytes to one million bytes. If \fIsize\fR is
412 outside this range, \fBTcl_SetChannelBufferSize\fR sets the buffer size to
413 4096.
414 .PP
415 .VS
416 \fBTcl_NotifyChannel\fR is called by a channel driver to indicate to
417 the generic layer that the events specified by \fImask\fR have
418 occurred on the channel.  Channel drivers are responsible for invoking
419 this function whenever the channel handlers need to be called for the
420 channel.  See \fBWATCHPROC\fR below for more details.
421 .VE
422 .PP
423 .VS
424 \fBTcl_BadChannelOption\fR is called from driver specific set or get option
425 procs to generate a complete error message.
426 .VE
427
428 .SH TCL_CHANNELTYPE
429 .PP
430 A channel driver provides a \fBTcl_ChannelType\fR structure that contains
431 pointers to functions that implement the various operations on a channel;
432 these operations are invoked as needed by the generic layer. The
433 \fBTcl_ChannelType\fR structure contains the following fields:
434 .PP
435 .VS
436 .CS
437 typedef struct Tcl_ChannelType {
438         char *\fItypeName\fR;
439         Tcl_DriverBlockModeProc *\fIblockModeProc\fR;   
440         Tcl_DriverCloseProc *\fIcloseProc\fR;
441         Tcl_DriverInputProc *\fIinputProc\fR;
442         Tcl_DriverOutputProc *\fIoutputProc\fR;
443         Tcl_DriverSeekProc *\fIseekProc\fR;
444         Tcl_DriverSetOptionProc *\fIsetOptionProc\fR;
445         Tcl_DriverGetOptionProc *\fIgetOptionProc\fR;
446         Tcl_DriverWatchProc *\fIwatchProc\fR;
447         Tcl_DriverGetHandleProc *\fIgetHandleProc\fR;
448         Tcl_DriverClose2Proc *\fIclose2Proc\fR;
449 } Tcl_ChannelType;
450 .CE
451 .VE
452 .PP
453 The driver must provide implementations for all functions except
454 \fIblockModeProc\fR, \fIseekProc\fR, \fIsetOptionProc\fR,
455 .VS
456 \fIgetOptionProc\fR, and \fIclose2Proc\fR, which may be specified as
457 .VE
458 NULL.  Other functions that can not be implemented for this type of
459 device should return \fBEINVAL\fR when invoked to indicate that they
460 are not implemented.
461
462 .SH TYPENAME
463 .PP
464 The \fItypeName\fR field contains a null-terminated string that
465 identifies the type of the device implemented by this driver, e.g.
466 \fBfile\fR or \fBsocket\fR.
467
468 .SH BLOCKMODEPROC
469 .PP
470 The \fIblockModeProc\fR field contains the address of a function called by
471 the generic layer to set blocking and nonblocking mode on the device.
472 \fIBlockModeProc\fR should match the following prototype:
473 .PP
474 .CS
475 typedef int Tcl_DriverBlockModeProc(
476         ClientData \fIinstanceData\fR,
477         int \fImode\fR);
478 .CE
479 .PP
480 The \fIinstanceData\fR is the same as the value passed to
481 \fBTcl_CreateChannel\fR when this channel was created.  The \fImode\fR
482 argument is either \fBTCL_MODE_BLOCKING\fR or \fBTCL_MODE_NONBLOCKING\fR to
483 set the device into blocking or nonblocking mode. The function should
484 return zero if the operation was successful, or a nonzero POSIX error code
485 if the operation failed.
486 .PP
487 If the operation is successful, the function can modify the supplied
488 \fIinstanceData\fR to record that the channel entered blocking or
489 nonblocking mode and to implement the blocking or nonblocking behavior.
490 For some device types, the blocking and nonblocking behavior can be
491 implemented by the underlying operating system; for other device types, the
492 behavior must be emulated in the channel driver.
493
494 .SH "CLOSEPROC AND CLOSE2PROC"
495 .PP
496 The \fIcloseProc\fR field contains the address of a function called by the
497 generic layer to clean up driver-related information when the channel is
498 closed. \fICloseProc\fR must match the following prototype:
499 .PP
500 .CS
501 typedef int Tcl_DriverCloseProc(
502         ClientData \fIinstanceData\fR,
503         Tcl_Interp *\fIinterp\fR);
504 .CE
505 .PP
506 The \fIinstanceData\fR argument is the same as the value provided to
507 \fBTcl_CreateChannel\fR when the channel was created. The function should
508 release any storage maintained by the channel driver for this channel, and
509 close the input and output devices encapsulated by this channel. All queued
510 output will have been flushed to the device before this function is called,
511 and no further driver operations will be invoked on this instance after
512 calling the \fIcloseProc\fR. If the close operation is successful, the
513 procedure should return zero; otherwise it should return a nonzero POSIX
514 error code. In addition, if an error occurs and \fIinterp\fR is not NULL,
515 the procedure should store an error message in the interpreter's result.
516 .PP
517 .VS
518 Alternatively, channels that support closing the read and write sides
519 independently may set \fIcloseProc\fR to \fBTCL_CLOSE2PROC\fR and set
520 \fIclose2Proc\fR to the address of a function that matches the
521 following prototype:
522 .PP
523 .CS
524 typedef int Tcl_DriverClose2Proc(
525         ClientData \fIinstanceData\fR,
526         Tcl_Interp *\fIinterp\fR,
527         int \fIflags\fR);
528 .CE
529 .PP
530 The \fIclose2Proc\fR will be called with \fIflags\fR set to an OR'ed
531 combination of \fBTCL_CLOSE_READ\fR or \fBTCL_CLOSE_WRITE\fR to
532 indicate that the driver should close the read and/or write side of
533 the channel.  The channel driver may be invoked to perform
534 additional operations on the channel after \fIclose2Proc\fR is
535 called to close one or both sides of the channel.  If \fIflags\fR is
536 \fB0\fR (zero), the driver should close the channel in the manner
537 described above for \fIcloseProc\fR.  No further operations will be
538 invoked on this instance after \fIclose2Proc\fR is called with all
539 flags cleared.  In all cases, the \fIclose2Proc\fR function should
540 return zero if the close operation was successful; otherwise it should
541 return a nonzero POSIX error code. In addition, if an error occurs and
542 \fIinterp\fR is not NULL, the procedure should store an error message
543 in the interpreter's result.
544 .VE
545
546 .SH INPUTPROC
547 .PP
548 The \fIinputProc\fR field contains the address of a function called by the
549 generic layer to read data from the file or device and store it in an
550 internal buffer. \fIInputProc\fR must match the following prototype:
551 .PP
552 .CS
553 typedef int Tcl_DriverInputProc(
554         ClientData \fIinstanceData\fR,
555         char *\fIbuf\fR,
556         int \fIbufSize\fR,
557         int *\fIerrorCodePtr\fR);
558 .CE
559 .PP
560 \fIInstanceData\fR is the same as the value passed to
561 \fBTcl_CreateChannel\fR when the channel was created.  The \fIbuf\fR
562 argument points to an array of bytes in which to store input from the
563 device, and the \fIbufSize\fR argument indicates how many bytes are
564 available at \fIbuf\fR.
565 .PP
566 The \fIerrorCodePtr\fR argument points to an integer variable provided by
567 the generic layer. If an error occurs, the function should set the variable
568 to a POSIX error code that identifies the error that occurred.
569 .PP
570 The function should read data from the input device encapsulated by the
571 channel and store it at \fIbuf\fR.  On success, the function should return
572 a nonnegative integer indicating how many bytes were read from the input
573 device and stored at \fIbuf\fR. On error, the function should return -1. If
574 an error occurs after some data has been read from the device, that data is
575 lost.
576 .PP
577 If \fIinputProc\fR can determine that the input device has some data
578 available but less than requested by the \fIbufSize\fR argument, the
579 function should only attempt to read as much data as is available and
580 return without blocking. If the input device has no data available
581 whatsoever and the channel is in nonblocking mode, the function should
582 return an \fBEAGAIN\fR error. If the input device has no data available
583 whatsoever and the channel is in blocking mode, the function should block
584 for the shortest possible time until at least one byte of data can be read
585 from the device; then, it should return as much data as it can read without
586 blocking.
587
588 .SH OUTPUTPROC
589 .PP
590 The \fIoutputProc\fR field contains the address of a function called by the
591 generic layer to transfer data from an internal buffer to the output device.
592 \fIOutputProc\fR must match the following prototype:
593 .PP
594 .CS
595 typedef int Tcl_DriverOutputProc(
596         ClientData \fIinstanceData\fR,
597         char *\fIbuf\fR,
598         int \fItoWrite\fR,
599         int *\fIerrorCodePtr\fR);
600 .CE
601 .PP
602 \fIInstanceData\fR is the same as the value passed to
603 \fBTcl_CreateChannel\fR when the channel was created. The \fIbuf\fR
604 argument contains an array of bytes to be written to the device, and the
605 \fItoWrite\fR argument indicates how many bytes are to be written from the
606 \fIbuf\fR argument.
607 .PP
608 The \fIerrorCodePtr\fR argument points to an integer variable provided by
609 the generic layer. If an error occurs, the function should set this
610 variable to a POSIX error code that identifies the error.
611 .PP
612 The function should write the data at \fIbuf\fR to the output device
613 encapsulated by the channel. On success, the function should return a
614 nonnegative integer indicating how many bytes were written to the output
615 device.  The return value is normally the same as \fItoWrite\fR, but may be
616 less in some cases such as if the output operation is interrupted by a
617 signal. If an error occurs the function should return -1.  In case of
618 error, some data may have been written to the device.
619 .PP
620 If the channel is nonblocking and the output device is unable to absorb any
621 data whatsoever, the function should return -1 with an \fBEAGAIN\fR error
622 without writing any data.
623
624 .SH SEEKPROC
625 .PP
626 The \fIseekProc\fR field contains the address of a function called by the
627 generic layer to move the access point at which subsequent input or output
628 operations will be applied. \fISeekProc\fR must match the following
629 prototype:
630 .PP
631 .CS
632 typedef int Tcl_DriverSeekProc(
633         ClientData \fIinstanceData\fR,
634         long \fIoffset\fR,
635         int \fIseekMode\fR,
636         int *\fIerrorCodePtr\fR);
637 .CE
638 .PP
639 The \fIinstanceData\fR argument is the same as the value given to
640 \fBTcl_CreateChannel\fR when this channel was created.  \fIOffset\fR and
641 \fIseekMode\fR have the same meaning as for the \fBTcl_Seek\fR
642 procedure (described in the manual entry for \fBTcl_OpenFileChannel\fR).
643 .PP
644 The \fIerrorCodePtr\fR argument points to an integer variable provided by
645 the generic layer for returning \fBerrno\fR values from the function.  The
646 function should set this variable to a POSIX error code if an error occurs.
647 The function should store an \fBEINVAL\fR error code if the channel type
648 does not implement seeking.
649 .PP
650 The return value is the new access point or -1 in case of error. If an
651 error occurred, the function should not move the access point.
652
653 .SH SETOPTIONPROC
654 .PP
655 The \fIsetOptionProc\fR field contains the address of a function called by
656 the generic layer to set a channel type specific option on a channel.
657 \fIsetOptionProc\fR must match the following prototype:
658 .PP
659 .CS
660 typedef int Tcl_DriverSetOptionProc(
661         ClientData \fIinstanceData\fR,
662         Tcl_Interp *\fIinterp\fR,
663         char *\fIoptionName\fR,
664         char *\fIoptionValue\fR);
665 .CE
666 .PP
667 \fIoptionName\fR is the name of an option to set, and \fIoptionValue\fR is
668 the new value for that option, as a string. The \fIinstanceData\fR is the
669 same as the value given to \fBTcl_CreateChannel\fR when this channel was
670 created. The function should do whatever channel type specific action is
671 required to implement the new value of the option.
672 .PP
673 Some options are handled by the generic code and this function is never
674 called to set them, e.g. \fB-blockmode\fR. Other options are specific to
675 each channel type and the \fIsetOptionProc\fR procedure of the channel
676 driver will get called to implement them. The \fIsetOptionProc\fR field can
677 be NULL, which indicates that this channel type supports no type specific
678 options. 
679 .PP
680 If the option value is successfully modified to the new value, the function
681 returns \fBTCL_OK\fR.
682 .VS
683 It should call \fBTcl_BadChannelOption\fR which itself returns
684 \fBTCL_ERROR\fR if the \fIoptionName\fR is
685 unrecognized. 
686 .VE
687 If \fIoptionValue\fR specifies a value for the option that
688 is not supported or if a system call error occurs,
689 the function should leave an error message in the
690 \fIresult\fR field of \fIinterp\fR if \fIinterp\fR is not NULL. The
691 function should also call \fBTcl_SetErrno\fR to store an appropriate POSIX
692 error code.
693
694 .SH GETOPTIONPROC
695 .PP
696 The \fIgetOptionProc\fR field contains the address of a function called by
697 the generic layer to get the value of a channel type specific option on a
698 channel. \fIgetOptionProc\fR must match the following prototype:
699 .PP
700 .CS
701 typedef int Tcl_DriverGetOptionProc(
702         ClientData \fIinstanceData\fR,
703 .VS
704         Tcl_Interp *\fIinterp\fR,
705 .VE
706         char *\fIoptionName\fR,
707         Tcl_DString *\fIdsPtr\fR);
708 .CE
709 .PP
710 \fIOptionName\fR is the name of an option supported by this type of
711 channel. If the option name is not NULL, the function stores its current
712 value, as a string, in the Tcl dynamic string \fIdsPtr\fR.
713 If \fIoptionName\fR is NULL, the function stores in \fIdsPtr\fR an
714 alternating list of all supported options and their current values.
715 On success, the function returns \fBTCL_OK\fR. 
716 .VS
717 It should call \fBTcl_BadChannelOption\fR which itself returns
718 \fBTCL_ERROR\fR if the \fIoptionName\fR is
719 unrecognized. If a system call error occurs,
720 the function should leave an error message in the
721 \fIresult\fR field of \fIinterp\fR if \fIinterp\fR is not NULL. The
722 function should also call \fBTcl_SetErrno\fR to store an appropriate POSIX
723 error code.
724 .VE
725 .PP
726 Some options are handled by the generic code and this function is never
727 called to retrieve their value, e.g. \fB-blockmode\fR. Other options are
728 specific to each channel type and the \fIgetOptionProc\fR procedure of the
729 channel driver will get called to implement them. The \fIgetOptionProc\fR
730 field can be NULL, which indicates that this channel type supports no type
731 specific options.
732
733 .SH WATCHPROC
734 .VS
735 .PP
736 The \fIwatchProc\fR field contains the address of a function called
737 by the generic layer to initialize the event notification mechanism to
738 notice events of interest on this channel.
739 \fIWatchProc\fR should match the following prototype:
740 .PP
741 .CS
742 typedef void Tcl_DriverWatchProc(
743         ClientData \fIinstanceData\fR,
744         int \fImask\fR);
745 .CE
746 .VE
747 .PP
748 The \fIinstanceData\fR is the same as the value passed to
749 \fBTcl_CreateChannel\fR when this channel was created. The \fImask\fR
750 argument is an OR-ed combination of \fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR
751 and \fBTCL_EXCEPTION\fR; it indicates events the caller is interested in
752 noticing on this channel.
753 .PP
754 .VS
755 The function should initialize device type specific mechanisms to
756 notice when an event of interest is present on the channel.  When one
757 or more of the designated events occurs on the channel, the channel
758 driver is responsible for calling \fBTcl_NotifyChannel\fR to inform
759 the generic channel module.  The driver should take care not to starve
760 other channel drivers or sources of callbacks by invoking
761 Tcl_NotifyChannel too frequently.  Fairness can be insured by using
762 the Tcl event queue to allow the channel event to be scheduled in sequence
763 with other events.  See the description of \fBTcl_QueueEvent\fR for
764 details on how to queue an event.
765
766 .SH GETHANDLEPROC
767 .PP
768 The \fIgetHandleProc\fR field contains the address of a function called by
769 the generic layer to retrieve a device-specific handle from the channel.
770 \fIGetHandleProc\fR should match the following prototype:
771 .PP
772 .CS
773 typedef int Tcl_DriverGetHandleProc(
774         ClientData \fIinstanceData\fR,
775         int \fIdirection\fR,
776         ClientData *\fIhandlePtr\fR);
777 .CE
778 .PP
779 \fIInstanceData is the same as the value passed to
780 \fBTcl_CreateChannel\fR when this channel was created. The \fIdirection\fR
781 argument is either \fBTCL_READABLE\fR to retrieve the handle used
782 for input, or \fBTCL_WRITABLE\fR to retrieve the handle used for
783 output.
784 .PP
785 If the channel implementation has device-specific handles, the
786 function should retrieve the appropriate handle associated with the
787 channel, according the \fIdirection\fR argument.  The handle should be
788 stored in the location referred to by \fIhandlePtr\fR, and
789 \fBTCL_OK\fR should be returned.  If the channel is not open for the
790 specified direction, or if the channel implementation does not use
791 device handles, the function should return \fBTCL_ERROR\fR.
792 .VE
793
794 .VS
795 .SH TCL_BADCHANNELOPTION
796 .PP
797 This procedure generates a "bad option" error message in an
798 (optional) interpreter.  It is used by channel drivers when 
799 a invalid Set/Get option is requested. Its purpose is to concatenate
800 the generic options list to the specific ones and factorize
801 the generic options error message string.
802 .PP
803 It always return \fBTCL_ERROR\fR
804 .PP
805 An error message is generated in interp's result object to
806 indicate that a command was invoked with the a bad option
807 The message has the form
808 .CS
809     bad option "blah": should be one of 
810     <...generic options...>+<...specific options...>
811 so you get for instance:
812     bad option "-blah": should be one of -blocking,
813     -buffering, -buffersize, -eofchar, -translation,
814     -peername, or -sockname
815 when called with optionList="peername sockname"
816 .CE
817 "blah" is the optionName argument and "<specific options>"
818 is a space separated list of specific option words.
819 The function takes good care of inserting minus signs before
820 each option, commas after, and an "or" before the last option.
821 .VE
822
823 .SH "SEE ALSO"
824 Tcl_Close(3), Tcl_OpenFileChannel(3), Tcl_SetErrno(3), Tcl_QueueEvent(3)
825
826 .SH KEYWORDS
827 blocking, channel driver, channel registration, channel type, nonblocking