| [25] | 1 | '\" |
|---|
| 2 | '\" Copyright (c) 1996-1997 Sun Microsystems, Inc. |
|---|
| 3 | '\" Copyright (c) 1997-2000 Ajuba Solutions. |
|---|
| 4 | '\" |
|---|
| 5 | '\" See the file "license.terms" for information on usage and redistribution |
|---|
| 6 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
|---|
| 7 | '\" |
|---|
| 8 | '\" RCS: @(#) $Id: CrtChannel.3,v 1.40 2007/12/13 15:22:30 dgp Exp $ |
|---|
| 9 | .so man.macros |
|---|
| 10 | .TH Tcl_CreateChannel 3 8.4 Tcl "Tcl Library Procedures" |
|---|
| 11 | .BS |
|---|
| 12 | '\" Note: do not modify the .SH NAME line immediately below! |
|---|
| 13 | .SH NAME |
|---|
| 14 | Tcl_CreateChannel, Tcl_GetChannelInstanceData, Tcl_GetChannelType, Tcl_GetChannelName, Tcl_GetChannelHandle, Tcl_GetChannelMode, Tcl_GetChannelBufferSize, Tcl_SetChannelBufferSize, Tcl_NotifyChannel, Tcl_BadChannelOption, Tcl_ChannelName, Tcl_ChannelVersion, Tcl_ChannelBlockModeProc, Tcl_ChannelCloseProc, Tcl_ChannelClose2Proc, Tcl_ChannelInputProc, Tcl_ChannelOutputProc, Tcl_ChannelSeekProc, Tcl_ChannelWideSeekProc, Tcl_ChannelTruncateProc, Tcl_ChannelSetOptionProc, Tcl_ChannelGetOptionProc, Tcl_ChannelWatchProc, Tcl_ChannelGetHandleProc, Tcl_ChannelFlushProc, Tcl_ChannelHandlerProc, Tcl_ChannelThreadActionProc, Tcl_IsChannelShared, Tcl_IsChannelRegistered, Tcl_CutChannel, Tcl_SpliceChannel, Tcl_IsChannelExisting, Tcl_ClearChannelHandlers, Tcl_GetChannelThread, Tcl_ChannelBuffered \- procedures for creating and manipulating channels |
|---|
| 15 | .SH SYNOPSIS |
|---|
| 16 | .nf |
|---|
| 17 | \fB#include <tcl.h>\fR |
|---|
| 18 | .sp |
|---|
| 19 | Tcl_Channel |
|---|
| 20 | \fBTcl_CreateChannel\fR(\fItypePtr, channelName, instanceData, mask\fR) |
|---|
| 21 | .sp |
|---|
| 22 | ClientData |
|---|
| 23 | \fBTcl_GetChannelInstanceData\fR(\fIchannel\fR) |
|---|
| 24 | .sp |
|---|
| 25 | Tcl_ChannelType * |
|---|
| 26 | \fBTcl_GetChannelType\fR(\fIchannel\fR) |
|---|
| 27 | .sp |
|---|
| 28 | const char * |
|---|
| 29 | \fBTcl_GetChannelName\fR(\fIchannel\fR) |
|---|
| 30 | .sp |
|---|
| 31 | int |
|---|
| 32 | \fBTcl_GetChannelHandle\fR(\fIchannel, direction, handlePtr\fR) |
|---|
| 33 | .sp |
|---|
| 34 | Tcl_ThreadId |
|---|
| 35 | \fBTcl_GetChannelThread\fR(\fIchannel\fR) |
|---|
| 36 | .sp |
|---|
| 37 | int |
|---|
| 38 | \fBTcl_GetChannelMode\fR(\fIchannel\fR) |
|---|
| 39 | .sp |
|---|
| 40 | int |
|---|
| 41 | \fBTcl_GetChannelBufferSize\fR(\fIchannel\fR) |
|---|
| 42 | .sp |
|---|
| 43 | \fBTcl_SetChannelBufferSize\fR(\fIchannel, size\fR) |
|---|
| 44 | .sp |
|---|
| 45 | \fBTcl_NotifyChannel\fR(\fIchannel, mask\fR) |
|---|
| 46 | .sp |
|---|
| 47 | int |
|---|
| 48 | \fBTcl_BadChannelOption\fR(\fIinterp, optionName, optionList\fR) |
|---|
| 49 | .sp |
|---|
| 50 | int |
|---|
| 51 | \fBTcl_IsChannelShared\fR(\fIchannel\fR) |
|---|
| 52 | .sp |
|---|
| 53 | int |
|---|
| 54 | \fBTcl_IsChannelRegistered\fR(\fIinterp, channel\fR) |
|---|
| 55 | .sp |
|---|
| 56 | int |
|---|
| 57 | \fBTcl_IsChannelExisting\fR(\fIchannelName\fR) |
|---|
| 58 | .sp |
|---|
| 59 | void |
|---|
| 60 | \fBTcl_CutChannel\fR(\fIchannel\fR) |
|---|
| 61 | .sp |
|---|
| 62 | void |
|---|
| 63 | \fBTcl_SpliceChannel\fR(\fIchannel\fR) |
|---|
| 64 | .sp |
|---|
| 65 | void |
|---|
| 66 | \fBTcl_ClearChannelHandlers\fR(\fIchannel\fR) |
|---|
| 67 | .sp |
|---|
| 68 | int |
|---|
| 69 | \fBTcl_ChannelBuffered\fR(\fIchannel\fR) |
|---|
| 70 | .sp |
|---|
| 71 | const char * |
|---|
| 72 | \fBTcl_ChannelName\fR(\fItypePtr\fR) |
|---|
| 73 | .sp |
|---|
| 74 | Tcl_ChannelTypeVersion |
|---|
| 75 | \fBTcl_ChannelVersion\fR(\fItypePtr\fR) |
|---|
| 76 | .sp |
|---|
| 77 | Tcl_DriverBlockModeProc * |
|---|
| 78 | \fBTcl_ChannelBlockModeProc\fR(\fItypePtr\fR) |
|---|
| 79 | .sp |
|---|
| 80 | Tcl_DriverCloseProc * |
|---|
| 81 | \fBTcl_ChannelCloseProc\fR(\fItypePtr\fR) |
|---|
| 82 | .sp |
|---|
| 83 | Tcl_DriverClose2Proc * |
|---|
| 84 | \fBTcl_ChannelClose2Proc\fR(\fItypePtr\fR) |
|---|
| 85 | .sp |
|---|
| 86 | Tcl_DriverInputProc * |
|---|
| 87 | \fBTcl_ChannelInputProc\fR(\fItypePtr\fR) |
|---|
| 88 | .sp |
|---|
| 89 | Tcl_DriverOutputProc * |
|---|
| 90 | \fBTcl_ChannelOutputProc\fR(\fItypePtr\fR) |
|---|
| 91 | .sp |
|---|
| 92 | Tcl_DriverSeekProc * |
|---|
| 93 | \fBTcl_ChannelSeekProc\fR(\fItypePtr\fR) |
|---|
| 94 | .sp |
|---|
| 95 | Tcl_DriverWideSeekProc * |
|---|
| 96 | \fBTcl_ChannelWideSeekProc\fR(\fItypePtr\fR) |
|---|
| 97 | .sp |
|---|
| 98 | Tcl_DriverThreadActionProc * |
|---|
| 99 | \fBTcl_ChannelThreadActionProc\fR(\fItypePtr\fR) |
|---|
| 100 | .sp |
|---|
| 101 | .VS 8.5 |
|---|
| 102 | Tcl_DriverTruncateProc * |
|---|
| 103 | \fBTcl_ChannelTruncateProc\fR(\fItypePtr\fR) |
|---|
| 104 | .VE 8.5 |
|---|
| 105 | .sp |
|---|
| 106 | Tcl_DriverSetOptionProc * |
|---|
| 107 | \fBTcl_ChannelSetOptionProc\fR(\fItypePtr\fR) |
|---|
| 108 | .sp |
|---|
| 109 | Tcl_DriverGetOptionProc * |
|---|
| 110 | \fBTcl_ChannelGetOptionProc\fR(\fItypePtr\fR) |
|---|
| 111 | .sp |
|---|
| 112 | Tcl_DriverWatchProc * |
|---|
| 113 | \fBTcl_ChannelWatchProc\fR(\fItypePtr\fR) |
|---|
| 114 | .sp |
|---|
| 115 | Tcl_DriverGetHandleProc * |
|---|
| 116 | \fBTcl_ChannelGetHandleProc\fR(\fItypePtr\fR) |
|---|
| 117 | .sp |
|---|
| 118 | Tcl_DriverFlushProc * |
|---|
| 119 | \fBTcl_ChannelFlushProc\fR(\fItypePtr\fR) |
|---|
| 120 | .sp |
|---|
| 121 | Tcl_DriverHandlerProc * |
|---|
| 122 | \fBTcl_ChannelHandlerProc\fR(\fItypePtr\fR) |
|---|
| 123 | .sp |
|---|
| 124 | .SH ARGUMENTS |
|---|
| 125 | .AS "const Tcl_ChannelType" *channelName |
|---|
| 126 | .AP "const Tcl_ChannelType" *typePtr in |
|---|
| 127 | Points to a structure containing the addresses of procedures that |
|---|
| 128 | can be called to perform I/O and other functions on the channel. |
|---|
| 129 | .AP "const char" *channelName in |
|---|
| 130 | The name of this channel, such as \fBfile3\fR; must not be in use |
|---|
| 131 | by any other channel. Can be NULL, in which case the channel is |
|---|
| 132 | created without a name. |
|---|
| 133 | .AP ClientData instanceData in |
|---|
| 134 | Arbitrary one-word value to be associated with this channel. This |
|---|
| 135 | value is passed to procedures in \fItypePtr\fR when they are invoked. |
|---|
| 136 | .AP int mask in |
|---|
| 137 | OR-ed combination of \fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR to indicate |
|---|
| 138 | whether a channel is readable and writable. |
|---|
| 139 | .AP Tcl_Channel channel in |
|---|
| 140 | The channel to operate on. |
|---|
| 141 | .AP int direction in |
|---|
| 142 | \fBTCL_READABLE\fR means the input handle is wanted; \fBTCL_WRITABLE\fR |
|---|
| 143 | means the output handle is wanted. |
|---|
| 144 | .AP ClientData *handlePtr out |
|---|
| 145 | Points to the location where the desired OS-specific handle should be |
|---|
| 146 | stored. |
|---|
| 147 | .AP int size in |
|---|
| 148 | The size, in bytes, of buffers to allocate in this channel. |
|---|
| 149 | .AP int mask in |
|---|
| 150 | An OR-ed combination of \fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR |
|---|
| 151 | and \fBTCL_EXCEPTION\fR that indicates events that have occurred on |
|---|
| 152 | this channel. |
|---|
| 153 | .AP Tcl_Interp *interp in |
|---|
| 154 | Current interpreter. (can be NULL) |
|---|
| 155 | .AP "const char" *optionName in |
|---|
| 156 | Name of the invalid option. |
|---|
| 157 | .AP "const char" *optionList in |
|---|
| 158 | Specific options list (space separated words, without |
|---|
| 159 | .QW \- ) |
|---|
| 160 | to append to the standard generic options list. |
|---|
| 161 | Can be NULL for generic options error message only. |
|---|
| 162 | |
|---|
| 163 | .BE |
|---|
| 164 | |
|---|
| 165 | .SH DESCRIPTION |
|---|
| 166 | .PP |
|---|
| 167 | Tcl uses a two-layered channel architecture. It provides a generic upper |
|---|
| 168 | layer to enable C and Tcl programs to perform input and output using the |
|---|
| 169 | same APIs for a variety of files, devices, sockets etc. The generic C APIs |
|---|
| 170 | are described in the manual entry for \fBTcl_OpenFileChannel\fR. |
|---|
| 171 | .PP |
|---|
| 172 | The lower layer provides type-specific channel drivers for each type |
|---|
| 173 | of device supported on each platform. This manual entry describes the |
|---|
| 174 | C APIs used to communicate between the generic layer and the |
|---|
| 175 | type-specific channel drivers. It also explains how new types of |
|---|
| 176 | channels can be added by providing new channel drivers. |
|---|
| 177 | .PP |
|---|
| 178 | Channel drivers consist of a number of components: First, each channel |
|---|
| 179 | driver provides a \fBTcl_ChannelType\fR structure containing pointers to |
|---|
| 180 | functions implementing the various operations used by the generic layer to |
|---|
| 181 | communicate with the channel driver. The \fBTcl_ChannelType\fR structure |
|---|
| 182 | and the functions referenced by it are described in the section |
|---|
| 183 | \fBTCL_CHANNELTYPE\fR, below. |
|---|
| 184 | .PP |
|---|
| 185 | Second, channel drivers usually provide a Tcl command to create |
|---|
| 186 | instances of that type of channel. For example, the Tcl \fBopen\fR |
|---|
| 187 | command creates channels that use the file and command channel |
|---|
| 188 | drivers, and the Tcl \fBsocket\fR command creates channels that use |
|---|
| 189 | TCP sockets for network communication. |
|---|
| 190 | .PP |
|---|
| 191 | Third, a channel driver optionally provides a C function to open |
|---|
| 192 | channel instances of that type. For example, \fBTcl_OpenFileChannel\fR |
|---|
| 193 | opens a channel that uses the file channel driver, and |
|---|
| 194 | \fBTcl_OpenTcpClient\fR opens a channel that uses the TCP network |
|---|
| 195 | protocol. These creation functions typically use |
|---|
| 196 | \fBTcl_CreateChannel\fR internally to open the channel. |
|---|
| 197 | .PP |
|---|
| 198 | To add a new type of channel you must implement a C API or a Tcl command |
|---|
| 199 | that opens a channel by invoking \fBTcl_CreateChannel\fR. |
|---|
| 200 | When your driver calls \fBTcl_CreateChannel\fR it passes in |
|---|
| 201 | a \fBTcl_ChannelType\fR structure describing the driver's I/O |
|---|
| 202 | procedures. |
|---|
| 203 | The generic layer will then invoke the functions referenced in that |
|---|
| 204 | structure to perform operations on the channel. |
|---|
| 205 | .PP |
|---|
| 206 | \fBTcl_CreateChannel\fR opens a new channel and associates the supplied |
|---|
| 207 | \fItypePtr\fR and \fIinstanceData\fR with it. The channel is opened in the |
|---|
| 208 | mode indicated by \fImask\fR. |
|---|
| 209 | For a discussion of channel drivers, their operations and the |
|---|
| 210 | \fBTcl_ChannelType\fR structure, see the section \fBTCL_CHANNELTYPE\fR, below. |
|---|
| 211 | .PP |
|---|
| 212 | \fBTcl_CreateChannel\fR interacts with the code managing the standard |
|---|
| 213 | channels. Once a standard channel was initialized either through a |
|---|
| 214 | call to \fBTcl_GetStdChannel\fR or a call to \fBTcl_SetStdChannel\fR |
|---|
| 215 | closing this standard channel will cause the next call to |
|---|
| 216 | \fBTcl_CreateChannel\fR to make the new channel the new standard |
|---|
| 217 | channel too. See \fBTcl_StandardChannels\fR for a general treatise |
|---|
| 218 | about standard channels and the behaviour of the Tcl library with |
|---|
| 219 | regard to them. |
|---|
| 220 | .PP |
|---|
| 221 | \fBTcl_GetChannelInstanceData\fR returns the instance data associated with |
|---|
| 222 | the channel in \fIchannel\fR. This is the same as the \fIinstanceData\fR |
|---|
| 223 | argument in the call to \fBTcl_CreateChannel\fR that created this channel. |
|---|
| 224 | .PP |
|---|
| 225 | \fBTcl_GetChannelType\fR returns a pointer to the \fBTcl_ChannelType\fR |
|---|
| 226 | structure used by the channel in the \fIchannel\fR argument. This is |
|---|
| 227 | the same as the \fItypePtr\fR argument in the call to |
|---|
| 228 | \fBTcl_CreateChannel\fR that created this channel. |
|---|
| 229 | .PP |
|---|
| 230 | \fBTcl_GetChannelName\fR returns a string containing the name associated |
|---|
| 231 | with the channel, or NULL if the \fIchannelName\fR argument to |
|---|
| 232 | \fBTcl_CreateChannel\fR was NULL. |
|---|
| 233 | .PP |
|---|
| 234 | \fBTcl_GetChannelHandle\fR places the OS-specific device handle |
|---|
| 235 | associated with \fIchannel\fR for the given \fIdirection\fR in the |
|---|
| 236 | location specified by \fIhandlePtr\fR and returns \fBTCL_OK\fR. If |
|---|
| 237 | the channel does not have a device handle for the specified direction, |
|---|
| 238 | then \fBTCL_ERROR\fR is returned instead. Different channel drivers |
|---|
| 239 | will return different types of handle. Refer to the manual entries |
|---|
| 240 | for each driver to determine what type of handle is returned. |
|---|
| 241 | .PP |
|---|
| 242 | \fBTcl_GetChannelThread\fR returns the id of the thread currently managing |
|---|
| 243 | the specified \fIchannel\fR. This allows channel drivers to send their file |
|---|
| 244 | events to the correct event queue even for a multi-threaded core. |
|---|
| 245 | .PP |
|---|
| 246 | \fBTcl_GetChannelMode\fR returns an OR-ed combination of \fBTCL_READABLE\fR |
|---|
| 247 | and \fBTCL_WRITABLE\fR, indicating whether the channel is open for input |
|---|
| 248 | and output. |
|---|
| 249 | .PP |
|---|
| 250 | \fBTcl_GetChannelBufferSize\fR returns the size, in bytes, of buffers |
|---|
| 251 | allocated to store input or output in \fIchannel\fR. If the value was not set |
|---|
| 252 | by a previous call to \fBTcl_SetChannelBufferSize\fR, described below, then |
|---|
| 253 | the default value of 4096 is returned. |
|---|
| 254 | .PP |
|---|
| 255 | \fBTcl_SetChannelBufferSize\fR sets the size, in bytes, of buffers that |
|---|
| 256 | will be allocated in subsequent operations on the channel to store input or |
|---|
| 257 | output. The \fIsize\fR argument should be between ten and one million, |
|---|
| 258 | allowing buffers of ten bytes to one million bytes. If \fIsize\fR is |
|---|
| 259 | outside this range, \fBTcl_SetChannelBufferSize\fR sets the buffer size to |
|---|
| 260 | 4096. |
|---|
| 261 | .PP |
|---|
| 262 | \fBTcl_NotifyChannel\fR is called by a channel driver to indicate to |
|---|
| 263 | the generic layer that the events specified by \fImask\fR have |
|---|
| 264 | occurred on the channel. Channel drivers are responsible for invoking |
|---|
| 265 | this function whenever the channel handlers need to be called for the |
|---|
| 266 | channel. See \fBWATCHPROC\fR below for more details. |
|---|
| 267 | .PP |
|---|
| 268 | \fBTcl_BadChannelOption\fR is called from driver specific |
|---|
| 269 | \fIsetOptionProc\fR or \fIgetOptionProc\fR to generate a complete |
|---|
| 270 | error message. |
|---|
| 271 | .PP |
|---|
| 272 | \fBTcl_ChannelBuffered\fR returns the number of bytes of input |
|---|
| 273 | currently buffered in the internal buffer (push back area) of the |
|---|
| 274 | channel itself. It does not report about the data in the overall |
|---|
| 275 | buffers for the stack of channels the supplied channel is part of. |
|---|
| 276 | .PP |
|---|
| 277 | \fBTcl_IsChannelShared\fR checks the refcount of the specified |
|---|
| 278 | \fIchannel\fR and returns whether the \fIchannel\fR was shared among |
|---|
| 279 | multiple interpreters (result == 1) or not (result == 0). |
|---|
| 280 | .PP |
|---|
| 281 | \fBTcl_IsChannelRegistered\fR checks whether the specified \fIchannel\fR is |
|---|
| 282 | registered in the given \fIinterp\fRreter (result == 1) or not |
|---|
| 283 | (result == 0). |
|---|
| 284 | .PP |
|---|
| 285 | \fBTcl_IsChannelExisting\fR checks whether a channel with the specified |
|---|
| 286 | name is registered in the (thread)-global list of all channels (result |
|---|
| 287 | == 1) or not (result == 0). |
|---|
| 288 | .PP |
|---|
| 289 | \fBTcl_CutChannel\fR removes the specified \fIchannel\fR from the |
|---|
| 290 | (thread)global list of all channels (of the current thread). |
|---|
| 291 | Application to a channel still registered in some interpreter |
|---|
| 292 | is not allowed. |
|---|
| 293 | .VS 8.5 |
|---|
| 294 | Also notifies the driver if the \fBTcl_ChannelType\fR version is |
|---|
| 295 | \fBTCL_CHANNEL_VERSION_4\fR (or higher), and |
|---|
| 296 | \fBTcl_DriverThreadActionProc\fR is defined for it. |
|---|
| 297 | .VE 8.5 |
|---|
| 298 | .PP |
|---|
| 299 | \fBTcl_SpliceChannel\fR adds the specified \fIchannel\fR to the |
|---|
| 300 | (thread)global list of all channels (of the current thread). |
|---|
| 301 | Application to a channel registered in some interpreter is not allowed. |
|---|
| 302 | .VS 8.5 |
|---|
| 303 | Also notifies the driver if the \fBTcl_ChannelType\fR version is |
|---|
| 304 | \fBTCL_CHANNEL_VERSION_4\fR (or higher), and |
|---|
| 305 | \fBTcl_DriverThreadActionProc\fR is defined for it. |
|---|
| 306 | .VE 8.5 |
|---|
| 307 | .PP |
|---|
| 308 | \fBTcl_ClearChannelHandlers\fR removes all channelhandlers and event |
|---|
| 309 | scripts associated with the specified \fIchannel\fR, thus shutting |
|---|
| 310 | down all event processing for this channel. |
|---|
| 311 | .SH TCL_CHANNELTYPE |
|---|
| 312 | .PP |
|---|
| 313 | A channel driver provides a \fBTcl_ChannelType\fR structure that contains |
|---|
| 314 | pointers to functions that implement the various operations on a channel; |
|---|
| 315 | these operations are invoked as needed by the generic layer. The structure |
|---|
| 316 | was versioned starting in Tcl 8.3.2/8.4 to correct a problem with stacked |
|---|
| 317 | channel drivers. See the \fBOLD CHANNEL TYPES\fR section below for |
|---|
| 318 | details about the old structure. |
|---|
| 319 | .PP |
|---|
| 320 | The \fBTcl_ChannelType\fR structure contains the following fields: |
|---|
| 321 | .CS |
|---|
| 322 | typedef struct Tcl_ChannelType { |
|---|
| 323 | char *\fItypeName\fR; |
|---|
| 324 | Tcl_ChannelTypeVersion \fIversion\fR; |
|---|
| 325 | Tcl_DriverCloseProc *\fIcloseProc\fR; |
|---|
| 326 | Tcl_DriverInputProc *\fIinputProc\fR; |
|---|
| 327 | Tcl_DriverOutputProc *\fIoutputProc\fR; |
|---|
| 328 | Tcl_DriverSeekProc *\fIseekProc\fR; |
|---|
| 329 | Tcl_DriverSetOptionProc *\fIsetOptionProc\fR; |
|---|
| 330 | Tcl_DriverGetOptionProc *\fIgetOptionProc\fR; |
|---|
| 331 | Tcl_DriverWatchProc *\fIwatchProc\fR; |
|---|
| 332 | Tcl_DriverGetHandleProc *\fIgetHandleProc\fR; |
|---|
| 333 | Tcl_DriverClose2Proc *\fIclose2Proc\fR; |
|---|
| 334 | Tcl_DriverBlockModeProc *\fIblockModeProc\fR; |
|---|
| 335 | Tcl_DriverFlushProc *\fIflushProc\fR; |
|---|
| 336 | Tcl_DriverHandlerProc *\fIhandlerProc\fR; |
|---|
| 337 | Tcl_DriverWideSeekProc *\fIwideSeekProc\fR; |
|---|
| 338 | Tcl_DriverThreadActionProc *\fIthreadActionProc\fR; |
|---|
| 339 | .VS 8.5 |
|---|
| 340 | Tcl_DriverTruncateProc *\fItruncateProc\fR; |
|---|
| 341 | .VE 8.5 |
|---|
| 342 | } Tcl_ChannelType; |
|---|
| 343 | .CE |
|---|
| 344 | .PP |
|---|
| 345 | It is not necessary to provide implementations for all channel |
|---|
| 346 | operations. Those which are not necessary may be set to NULL in the |
|---|
| 347 | struct: \fIblockModeProc\fR, \fIseekProc\fR, \fIsetOptionProc\fR, |
|---|
| 348 | \fIgetOptionProc\fR, and \fIclose2Proc\fR, in addition to |
|---|
| 349 | \fIflushProc\fR, \fIhandlerProc\fR, \fIthreadActionProc\fR, and |
|---|
| 350 | \fItruncateProc\fR. Other functions that cannot be implemented in a |
|---|
| 351 | meaningful way should return \fBEINVAL\fR when called, to indicate |
|---|
| 352 | that the operations they represent are not available. Also note that |
|---|
| 353 | \fIwideSeekProc\fR can be NULL if \fIseekProc\fR is. |
|---|
| 354 | .PP |
|---|
| 355 | The user should only use the above structure for \fBTcl_ChannelType\fR |
|---|
| 356 | instantiation. When referencing fields in a \fBTcl_ChannelType\fR |
|---|
| 357 | structure, the following functions should be used to obtain the values: |
|---|
| 358 | \fBTcl_ChannelName\fR, \fBTcl_ChannelVersion\fR, |
|---|
| 359 | \fBTcl_ChannelBlockModeProc\fR, \fBTcl_ChannelCloseProc\fR, |
|---|
| 360 | \fBTcl_ChannelClose2Proc\fR, \fBTcl_ChannelInputProc\fR, |
|---|
| 361 | \fBTcl_ChannelOutputProc\fR, \fBTcl_ChannelSeekProc\fR, |
|---|
| 362 | \fBTcl_ChannelWideSeekProc\fR, \fBTcl_ChannelThreadActionProc\fR, |
|---|
| 363 | .VS 8.5 |
|---|
| 364 | \fBTcl_ChannelTruncateProc\fR, |
|---|
| 365 | .VE 8.5 |
|---|
| 366 | \fBTcl_ChannelSetOptionProc\fR, \fBTcl_ChannelGetOptionProc\fR, |
|---|
| 367 | \fBTcl_ChannelWatchProc\fR, \fBTcl_ChannelGetHandleProc\fR, |
|---|
| 368 | \fBTcl_ChannelFlushProc\fR, or \fBTcl_ChannelHandlerProc\fR. |
|---|
| 369 | .PP |
|---|
| 370 | The change to the structures was made in such a way that standard channel |
|---|
| 371 | types are binary compatible. However, channel types that use stacked |
|---|
| 372 | channels (i.e. TLS, Trf) have new versions to correspond to the above change |
|---|
| 373 | since the previous code for stacked channels had problems. |
|---|
| 374 | .SS TYPENAME |
|---|
| 375 | .PP |
|---|
| 376 | The \fItypeName\fR field contains a null-terminated string that |
|---|
| 377 | identifies the type of the device implemented by this driver, e.g. |
|---|
| 378 | \fBfile\fR or \fBsocket\fR. |
|---|
| 379 | .PP |
|---|
| 380 | This value can be retrieved with \fBTcl_ChannelName\fR, which returns |
|---|
| 381 | a pointer to the string. |
|---|
| 382 | .SS VERSION |
|---|
| 383 | .PP |
|---|
| 384 | |
|---|
| 385 | The \fIversion\fR field should be set to the version of the structure |
|---|
| 386 | that you require. \fBTCL_CHANNEL_VERSION_2\fR is the minimum recommended. |
|---|
| 387 | \fBTCL_CHANNEL_VERSION_3\fR must be set to specifiy the \fIwideSeekProc\fR member. |
|---|
| 388 | \fBTCL_CHANNEL_VERSION_4\fR must be set to specifiy the \fIthreadActionProc\fR member |
|---|
| 389 | (includes \fIwideSeekProc\fR). |
|---|
| 390 | .VS 8.5 |
|---|
| 391 | \fBTCL_CHANNEL_VERSION_5\fR must be set to specifiy the |
|---|
| 392 | \fItruncateProc\fR members (includes |
|---|
| 393 | \fIwideSeekProc\fR and \fIthreadActionProc\fR). |
|---|
| 394 | .VE 8.5 |
|---|
| 395 | If it is not set to any of these, then this |
|---|
| 396 | \fBTcl_ChannelType\fR is assumed to have the original structure. See |
|---|
| 397 | \fBOLD CHANNEL TYPES\fR for more details. While Tcl will recognize |
|---|
| 398 | and function with either structures, stacked channels must be of at |
|---|
| 399 | least \fBTCL_CHANNEL_VERSION_2\fR to function correctly. |
|---|
| 400 | .PP |
|---|
| 401 | This value can be retrieved with \fBTcl_ChannelVersion\fR, which returns |
|---|
| 402 | one of |
|---|
| 403 | .VS 8.5 |
|---|
| 404 | \fBTCL_CHANNEL_VERSION_5\fR, |
|---|
| 405 | .VE 8.5 |
|---|
| 406 | \fBTCL_CHANNEL_VERSION_4\fR, |
|---|
| 407 | \fBTCL_CHANNEL_VERSION_3\fR, |
|---|
| 408 | \fBTCL_CHANNEL_VERSION_2\fR or \fBTCL_CHANNEL_VERSION_1\fR. |
|---|
| 409 | .SS BLOCKMODEPROC |
|---|
| 410 | .PP |
|---|
| 411 | The \fIblockModeProc\fR field contains the address of a function called by |
|---|
| 412 | the generic layer to set blocking and nonblocking mode on the device. |
|---|
| 413 | \fIBlockModeProc\fR should match the following prototype: |
|---|
| 414 | .PP |
|---|
| 415 | .CS |
|---|
| 416 | typedef int Tcl_DriverBlockModeProc( |
|---|
| 417 | ClientData \fIinstanceData\fR, |
|---|
| 418 | int \fImode\fR); |
|---|
| 419 | .CE |
|---|
| 420 | .PP |
|---|
| 421 | The \fIinstanceData\fR is the same as the value passed to |
|---|
| 422 | \fBTcl_CreateChannel\fR when this channel was created. The \fImode\fR |
|---|
| 423 | argument is either \fBTCL_MODE_BLOCKING\fR or \fBTCL_MODE_NONBLOCKING\fR to |
|---|
| 424 | set the device into blocking or nonblocking mode. The function should |
|---|
| 425 | return zero if the operation was successful, or a nonzero POSIX error code |
|---|
| 426 | if the operation failed. |
|---|
| 427 | .PP |
|---|
| 428 | If the operation is successful, the function can modify the supplied |
|---|
| 429 | \fIinstanceData\fR to record that the channel entered blocking or |
|---|
| 430 | nonblocking mode and to implement the blocking or nonblocking behavior. |
|---|
| 431 | For some device types, the blocking and nonblocking behavior can be |
|---|
| 432 | implemented by the underlying operating system; for other device types, the |
|---|
| 433 | behavior must be emulated in the channel driver. |
|---|
| 434 | .PP |
|---|
| 435 | This value can be retrieved with \fBTcl_ChannelBlockModeProc\fR, which returns |
|---|
| 436 | a pointer to the function. |
|---|
| 437 | .PP |
|---|
| 438 | A channel driver \fBnot\fR supplying a \fIblockModeProc\fR has to be |
|---|
| 439 | very, very careful. It has to tell the generic layer exactly which |
|---|
| 440 | blocking mode is acceptable to it, and should this also document for |
|---|
| 441 | the user so that the blocking mode of the channel is not changed to an |
|---|
| 442 | inacceptable value. Any confusion here may lead the interpreter into a |
|---|
| 443 | (spurious and difficult to find) deadlock. |
|---|
| 444 | .SS "CLOSEPROC AND CLOSE2PROC" |
|---|
| 445 | .PP |
|---|
| 446 | The \fIcloseProc\fR field contains the address of a function called by the |
|---|
| 447 | generic layer to clean up driver-related information when the channel is |
|---|
| 448 | closed. \fICloseProc\fR must match the following prototype: |
|---|
| 449 | .PP |
|---|
| 450 | .CS |
|---|
| 451 | typedef int Tcl_DriverCloseProc( |
|---|
| 452 | ClientData \fIinstanceData\fR, |
|---|
| 453 | Tcl_Interp *\fIinterp\fR); |
|---|
| 454 | .CE |
|---|
| 455 | .PP |
|---|
| 456 | The \fIinstanceData\fR argument is the same as the value provided to |
|---|
| 457 | \fBTcl_CreateChannel\fR when the channel was created. The function should |
|---|
| 458 | release any storage maintained by the channel driver for this channel, and |
|---|
| 459 | close the input and output devices encapsulated by this channel. All queued |
|---|
| 460 | output will have been flushed to the device before this function is called, |
|---|
| 461 | and no further driver operations will be invoked on this instance after |
|---|
| 462 | calling the \fIcloseProc\fR. If the close operation is successful, the |
|---|
| 463 | procedure should return zero; otherwise it should return a nonzero POSIX |
|---|
| 464 | error code. In addition, if an error occurs and \fIinterp\fR is not NULL, |
|---|
| 465 | the procedure should store an error message in the interpreter's result. |
|---|
| 466 | .PP |
|---|
| 467 | Alternatively, channels that support closing the read and write sides |
|---|
| 468 | independently may set \fIcloseProc\fR to \fBTCL_CLOSE2PROC\fR and set |
|---|
| 469 | \fIclose2Proc\fR to the address of a function that matches the |
|---|
| 470 | following prototype: |
|---|
| 471 | .PP |
|---|
| 472 | .CS |
|---|
| 473 | typedef int Tcl_DriverClose2Proc( |
|---|
| 474 | ClientData \fIinstanceData\fR, |
|---|
| 475 | Tcl_Interp *\fIinterp\fR, |
|---|
| 476 | int \fIflags\fR); |
|---|
| 477 | .CE |
|---|
| 478 | .PP |
|---|
| 479 | The \fIclose2Proc\fR will be called with \fIflags\fR set to an OR'ed |
|---|
| 480 | combination of \fBTCL_CLOSE_READ\fR or \fBTCL_CLOSE_WRITE\fR to |
|---|
| 481 | indicate that the driver should close the read and/or write side of |
|---|
| 482 | the channel. The channel driver may be invoked to perform |
|---|
| 483 | additional operations on the channel after \fIclose2Proc\fR is |
|---|
| 484 | called to close one or both sides of the channel. If \fIflags\fR is |
|---|
| 485 | \fB0\fR (zero), the driver should close the channel in the manner |
|---|
| 486 | described above for \fIcloseProc\fR. No further operations will be |
|---|
| 487 | invoked on this instance after \fIclose2Proc\fR is called with all |
|---|
| 488 | flags cleared. In all cases, the \fIclose2Proc\fR function should |
|---|
| 489 | return zero if the close operation was successful; otherwise it should |
|---|
| 490 | return a nonzero POSIX error code. In addition, if an error occurs and |
|---|
| 491 | \fIinterp\fR is not NULL, the procedure should store an error message |
|---|
| 492 | in the interpreter's result. |
|---|
| 493 | .PP |
|---|
| 494 | The \fIcloseProc\fR and \fIclose2Proc\fR values can be retrieved with |
|---|
| 495 | \fBTcl_ChannelCloseProc\fR or \fBTcl_ChannelClose2Proc\fR, which |
|---|
| 496 | return a pointer to the respective function. |
|---|
| 497 | .SS INPUTPROC |
|---|
| 498 | .PP |
|---|
| 499 | The \fIinputProc\fR field contains the address of a function called by the |
|---|
| 500 | generic layer to read data from the file or device and store it in an |
|---|
| 501 | internal buffer. \fIInputProc\fR must match the following prototype: |
|---|
| 502 | .PP |
|---|
| 503 | .CS |
|---|
| 504 | typedef int Tcl_DriverInputProc( |
|---|
| 505 | ClientData \fIinstanceData\fR, |
|---|
| 506 | char *\fIbuf\fR, |
|---|
| 507 | int \fIbufSize\fR, |
|---|
| 508 | int *\fIerrorCodePtr\fR); |
|---|
| 509 | .CE |
|---|
| 510 | .PP |
|---|
| 511 | \fIInstanceData\fR is the same as the value passed to |
|---|
| 512 | \fBTcl_CreateChannel\fR when the channel was created. The \fIbuf\fR |
|---|
| 513 | argument points to an array of bytes in which to store input from the |
|---|
| 514 | device, and the \fIbufSize\fR argument indicates how many bytes are |
|---|
| 515 | available at \fIbuf\fR. |
|---|
| 516 | .PP |
|---|
| 517 | The \fIerrorCodePtr\fR argument points to an integer variable provided by |
|---|
| 518 | the generic layer. If an error occurs, the function should set the variable |
|---|
| 519 | to a POSIX error code that identifies the error that occurred. |
|---|
| 520 | .PP |
|---|
| 521 | The function should read data from the input device encapsulated by the |
|---|
| 522 | channel and store it at \fIbuf\fR. On success, the function should return |
|---|
| 523 | a nonnegative integer indicating how many bytes were read from the input |
|---|
| 524 | device and stored at \fIbuf\fR. On error, the function should return -1. If |
|---|
| 525 | an error occurs after some data has been read from the device, that data is |
|---|
| 526 | lost. |
|---|
| 527 | .PP |
|---|
| 528 | If \fIinputProc\fR can determine that the input device has some data |
|---|
| 529 | available but less than requested by the \fIbufSize\fR argument, the |
|---|
| 530 | function should only attempt to read as much data as is available and |
|---|
| 531 | return without blocking. If the input device has no data available |
|---|
| 532 | whatsoever and the channel is in nonblocking mode, the function should |
|---|
| 533 | return an \fBEAGAIN\fR error. If the input device has no data available |
|---|
| 534 | whatsoever and the channel is in blocking mode, the function should block |
|---|
| 535 | for the shortest possible time until at least one byte of data can be read |
|---|
| 536 | from the device; then, it should return as much data as it can read without |
|---|
| 537 | blocking. |
|---|
| 538 | .PP |
|---|
| 539 | This value can be retrieved with \fBTcl_ChannelInputProc\fR, which returns |
|---|
| 540 | a pointer to the function. |
|---|
| 541 | .SS OUTPUTPROC |
|---|
| 542 | .PP |
|---|
| 543 | The \fIoutputProc\fR field contains the address of a function called by the |
|---|
| 544 | generic layer to transfer data from an internal buffer to the output device. |
|---|
| 545 | \fIOutputProc\fR must match the following prototype: |
|---|
| 546 | .PP |
|---|
| 547 | .CS |
|---|
| 548 | typedef int Tcl_DriverOutputProc( |
|---|
| 549 | ClientData \fIinstanceData\fR, |
|---|
| 550 | const char *\fIbuf\fR, |
|---|
| 551 | int \fItoWrite\fR, |
|---|
| 552 | int *\fIerrorCodePtr\fR); |
|---|
| 553 | .CE |
|---|
| 554 | .PP |
|---|
| 555 | \fIInstanceData\fR is the same as the value passed to |
|---|
| 556 | \fBTcl_CreateChannel\fR when the channel was created. The \fIbuf\fR |
|---|
| 557 | argument contains an array of bytes to be written to the device, and the |
|---|
| 558 | \fItoWrite\fR argument indicates how many bytes are to be written from the |
|---|
| 559 | \fIbuf\fR argument. |
|---|
| 560 | .PP |
|---|
| 561 | The \fIerrorCodePtr\fR argument points to an integer variable provided by |
|---|
| 562 | the generic layer. If an error occurs, the function should set this |
|---|
| 563 | variable to a POSIX error code that identifies the error. |
|---|
| 564 | .PP |
|---|
| 565 | The function should write the data at \fIbuf\fR to the output device |
|---|
| 566 | encapsulated by the channel. On success, the function should return a |
|---|
| 567 | nonnegative integer indicating how many bytes were written to the output |
|---|
| 568 | device. The return value is normally the same as \fItoWrite\fR, but may be |
|---|
| 569 | less in some cases such as if the output operation is interrupted by a |
|---|
| 570 | signal. If an error occurs the function should return -1. In case of |
|---|
| 571 | error, some data may have been written to the device. |
|---|
| 572 | .PP |
|---|
| 573 | If the channel is nonblocking and the output device is unable to absorb any |
|---|
| 574 | data whatsoever, the function should return -1 with an \fBEAGAIN\fR error |
|---|
| 575 | without writing any data. |
|---|
| 576 | .PP |
|---|
| 577 | This value can be retrieved with \fBTcl_ChannelOutputProc\fR, which returns |
|---|
| 578 | a pointer to the function. |
|---|
| 579 | .SS "SEEKPROC AND WIDESEEKPROC" |
|---|
| 580 | .PP |
|---|
| 581 | The \fIseekProc\fR field contains the address of a function called by the |
|---|
| 582 | generic layer to move the access point at which subsequent input or output |
|---|
| 583 | operations will be applied. \fISeekProc\fR must match the following |
|---|
| 584 | prototype: |
|---|
| 585 | .PP |
|---|
| 586 | .CS |
|---|
| 587 | typedef int Tcl_DriverSeekProc( |
|---|
| 588 | ClientData \fIinstanceData\fR, |
|---|
| 589 | long \fIoffset\fR, |
|---|
| 590 | int \fIseekMode\fR, |
|---|
| 591 | int *\fIerrorCodePtr\fR); |
|---|
| 592 | .CE |
|---|
| 593 | .PP |
|---|
| 594 | The \fIinstanceData\fR argument is the same as the value given to |
|---|
| 595 | \fBTcl_CreateChannel\fR when this channel was created. \fIOffset\fR and |
|---|
| 596 | \fIseekMode\fR have the same meaning as for the \fBTcl_Seek\fR |
|---|
| 597 | procedure (described in the manual entry for \fBTcl_OpenFileChannel\fR). |
|---|
| 598 | .PP |
|---|
| 599 | The \fIerrorCodePtr\fR argument points to an integer variable provided by |
|---|
| 600 | the generic layer for returning \fBerrno\fR values from the function. The |
|---|
| 601 | function should set this variable to a POSIX error code if an error occurs. |
|---|
| 602 | The function should store an \fBEINVAL\fR error code if the channel type |
|---|
| 603 | does not implement seeking. |
|---|
| 604 | .PP |
|---|
| 605 | The return value is the new access point or -1 in case of error. If an |
|---|
| 606 | error occurred, the function should not move the access point. |
|---|
| 607 | .PP |
|---|
| 608 | If there is a non-NULL \fIseekProc\fR field, the \fIwideSeekProc\fR |
|---|
| 609 | field may contain the address of an alternative function to use which |
|---|
| 610 | handles wide (i.e. larger than 32-bit) offsets, so allowing seeks |
|---|
| 611 | within files larger than 2GB. The \fIwideSeekProc\fR will be called |
|---|
| 612 | in preference to the \fIseekProc\fR, but both must be defined if the |
|---|
| 613 | \fIwideSeekProc\fR is defined. \fIWideSeekProc\fR must match the |
|---|
| 614 | following prototype: |
|---|
| 615 | .PP |
|---|
| 616 | .CS |
|---|
| 617 | typedef Tcl_WideInt Tcl_DriverWideSeekProc( |
|---|
| 618 | ClientData \fIinstanceData\fR, |
|---|
| 619 | Tcl_WideInt \fIoffset\fR, |
|---|
| 620 | int \fIseekMode\fR, |
|---|
| 621 | int *\fIerrorCodePtr\fR); |
|---|
| 622 | .CE |
|---|
| 623 | .PP |
|---|
| 624 | The arguments and return values mean the same thing as with |
|---|
| 625 | \fIseekProc\fR above, except that the type of offsets and the return |
|---|
| 626 | type are different. |
|---|
| 627 | .PP |
|---|
| 628 | The \fIseekProc\fR value can be retrieved with |
|---|
| 629 | \fBTcl_ChannelSeekProc\fR, which returns a pointer to the function, |
|---|
| 630 | and similarly the \fIwideSeekProc\fR can be retrieved with |
|---|
| 631 | \fBTcl_ChannelWideSeekProc\fR. |
|---|
| 632 | .SS 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 | const char *\fIoptionName\fR, |
|---|
| 643 | const char *\fInewValue\fR); |
|---|
| 644 | .CE |
|---|
| 645 | .PP |
|---|
| 646 | \fIoptionName\fR is the name of an option to set, and \fInewValue\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 | It should call \fBTcl_BadChannelOption\fR which itself returns |
|---|
| 662 | \fBTCL_ERROR\fR if the \fIoptionName\fR is |
|---|
| 663 | unrecognized. |
|---|
| 664 | If \fInewValue\fR specifies a value for the option that |
|---|
| 665 | is not supported or if a system call error occurs, |
|---|
| 666 | the function should leave an error message in the |
|---|
| 667 | \fIresult\fR field of \fIinterp\fR if \fIinterp\fR is not NULL. The |
|---|
| 668 | function should also call \fBTcl_SetErrno\fR to store an appropriate POSIX |
|---|
| 669 | error code. |
|---|
| 670 | .PP |
|---|
| 671 | This value can be retrieved with \fBTcl_ChannelSetOptionProc\fR, which returns |
|---|
| 672 | a pointer to the function. |
|---|
| 673 | .SS 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 | Tcl_Interp *\fIinterp\fR, |
|---|
| 683 | const char *\fIoptionName\fR, |
|---|
| 684 | Tcl_DString *\fIoptionValue\fR); |
|---|
| 685 | .CE |
|---|
| 686 | .PP |
|---|
| 687 | \fIOptionName\fR is the name of an option supported by this type of |
|---|
| 688 | channel. If the option name is not NULL, the function stores its current |
|---|
| 689 | value, as a string, in the Tcl dynamic string \fIoptionValue\fR. |
|---|
| 690 | If \fIoptionName\fR is NULL, the function stores in \fIoptionValue\fR an |
|---|
| 691 | alternating list of all supported options and their current values. |
|---|
| 692 | On success, the function returns \fBTCL_OK\fR. |
|---|
| 693 | It should call \fBTcl_BadChannelOption\fR which itself returns |
|---|
| 694 | \fBTCL_ERROR\fR if the \fIoptionName\fR is |
|---|
| 695 | unrecognized. If a system call error occurs, |
|---|
| 696 | the function should leave an error message in the |
|---|
| 697 | result of \fIinterp\fR if \fIinterp\fR is not NULL. The |
|---|
| 698 | function should also call \fBTcl_SetErrno\fR to store an appropriate POSIX |
|---|
| 699 | error code. |
|---|
| 700 | .PP |
|---|
| 701 | Some options are handled by the generic code and this function is never |
|---|
| 702 | called to retrieve their value, e.g. \fB\-blockmode\fR. Other options are |
|---|
| 703 | specific to each channel type and the \fIgetOptionProc\fR procedure of the |
|---|
| 704 | channel driver will get called to implement them. The \fIgetOptionProc\fR |
|---|
| 705 | field can be NULL, which indicates that this channel type supports no type |
|---|
| 706 | specific options. |
|---|
| 707 | .PP |
|---|
| 708 | This value can be retrieved with \fBTcl_ChannelGetOptionProc\fR, which returns |
|---|
| 709 | a pointer to the function. |
|---|
| 710 | .SS WATCHPROC |
|---|
| 711 | .PP |
|---|
| 712 | The \fIwatchProc\fR field contains the address of a function called |
|---|
| 713 | by the generic layer to initialize the event notification mechanism to |
|---|
| 714 | notice events of interest on this channel. |
|---|
| 715 | \fIWatchProc\fR should match the following prototype: |
|---|
| 716 | .PP |
|---|
| 717 | .CS |
|---|
| 718 | typedef void Tcl_DriverWatchProc( |
|---|
| 719 | ClientData \fIinstanceData\fR, |
|---|
| 720 | int \fImask\fR); |
|---|
| 721 | .CE |
|---|
| 722 | .PP |
|---|
| 723 | The \fIinstanceData\fR is the same as the value passed to |
|---|
| 724 | \fBTcl_CreateChannel\fR when this channel was created. The \fImask\fR |
|---|
| 725 | argument is an OR-ed combination of \fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR |
|---|
| 726 | and \fBTCL_EXCEPTION\fR; it indicates events the caller is interested in |
|---|
| 727 | noticing on this channel. |
|---|
| 728 | .PP |
|---|
| 729 | The function should initialize device type specific mechanisms to |
|---|
| 730 | notice when an event of interest is present on the channel. When one |
|---|
| 731 | or more of the designated events occurs on the channel, the channel |
|---|
| 732 | driver is responsible for calling \fBTcl_NotifyChannel\fR to inform |
|---|
| 733 | the generic channel module. The driver should take care not to starve |
|---|
| 734 | other channel drivers or sources of callbacks by invoking |
|---|
| 735 | Tcl_NotifyChannel too frequently. Fairness can be insured by using |
|---|
| 736 | the Tcl event queue to allow the channel event to be scheduled in sequence |
|---|
| 737 | with other events. See the description of \fBTcl_QueueEvent\fR for |
|---|
| 738 | details on how to queue an event. |
|---|
| 739 | .PP |
|---|
| 740 | This value can be retrieved with \fBTcl_ChannelWatchProc\fR, which returns |
|---|
| 741 | a pointer to the function. |
|---|
| 742 | .SS GETHANDLEPROC |
|---|
| 743 | .PP |
|---|
| 744 | The \fIgetHandleProc\fR field contains the address of a function called by |
|---|
| 745 | the generic layer to retrieve a device-specific handle from the channel. |
|---|
| 746 | \fIGetHandleProc\fR should match the following prototype: |
|---|
| 747 | .PP |
|---|
| 748 | .CS |
|---|
| 749 | typedef int Tcl_DriverGetHandleProc( |
|---|
| 750 | ClientData \fIinstanceData\fR, |
|---|
| 751 | int \fIdirection\fR, |
|---|
| 752 | ClientData *\fIhandlePtr\fR); |
|---|
| 753 | .CE |
|---|
| 754 | .PP |
|---|
| 755 | \fIInstanceData\fR is the same as the value passed to |
|---|
| 756 | \fBTcl_CreateChannel\fR when this channel was created. The \fIdirection\fR |
|---|
| 757 | argument is either \fBTCL_READABLE\fR to retrieve the handle used |
|---|
| 758 | for input, or \fBTCL_WRITABLE\fR to retrieve the handle used for |
|---|
| 759 | output. |
|---|
| 760 | .PP |
|---|
| 761 | If the channel implementation has device-specific handles, the |
|---|
| 762 | function should retrieve the appropriate handle associated with the |
|---|
| 763 | channel, according the \fIdirection\fR argument. The handle should be |
|---|
| 764 | stored in the location referred to by \fIhandlePtr\fR, and |
|---|
| 765 | \fBTCL_OK\fR should be returned. If the channel is not open for the |
|---|
| 766 | specified direction, or if the channel implementation does not use |
|---|
| 767 | device handles, the function should return \fBTCL_ERROR\fR. |
|---|
| 768 | .PP |
|---|
| 769 | This value can be retrieved with \fBTcl_ChannelGetHandleProc\fR, which returns |
|---|
| 770 | a pointer to the function. |
|---|
| 771 | .SS FLUSHPROC |
|---|
| 772 | .PP |
|---|
| 773 | The \fIflushProc\fR field is currently reserved for future use. |
|---|
| 774 | It should be set to NULL. |
|---|
| 775 | \fIFlushProc\fR should match the following prototype: |
|---|
| 776 | .PP |
|---|
| 777 | .CS |
|---|
| 778 | typedef int Tcl_DriverFlushProc( |
|---|
| 779 | ClientData \fIinstanceData\fR); |
|---|
| 780 | .CE |
|---|
| 781 | .PP |
|---|
| 782 | This value can be retrieved with \fBTcl_ChannelFlushProc\fR, which returns |
|---|
| 783 | a pointer to the function. |
|---|
| 784 | .SS HANDLERPROC |
|---|
| 785 | .PP |
|---|
| 786 | The \fIhandlerProc\fR field contains the address of a function called by |
|---|
| 787 | the generic layer to notify the channel that an event occurred. It should |
|---|
| 788 | be defined for stacked channel drivers that wish to be notified of events |
|---|
| 789 | that occur on the underlying (stacked) channel. |
|---|
| 790 | \fIHandlerProc\fR should match the following prototype: |
|---|
| 791 | .PP |
|---|
| 792 | .CS |
|---|
| 793 | typedef int Tcl_DriverHandlerProc( |
|---|
| 794 | ClientData \fIinstanceData\fR, |
|---|
| 795 | int \fIinterestMask\fR); |
|---|
| 796 | .CE |
|---|
| 797 | .PP |
|---|
| 798 | \fIInstanceData\fR is the same as the value passed to \fBTcl_CreateChannel\fR |
|---|
| 799 | when this channel was created. The \fIinterestMask\fR is an OR-ed |
|---|
| 800 | combination of \fBTCL_READABLE\fR or \fBTCL_WRITABLE\fR; it indicates what |
|---|
| 801 | type of event occurred on this channel. |
|---|
| 802 | .PP |
|---|
| 803 | This value can be retrieved with \fBTcl_ChannelHandlerProc\fR, which returns |
|---|
| 804 | a pointer to the function. |
|---|
| 805 | |
|---|
| 806 | .SS "THREADACTIONPROC" |
|---|
| 807 | .PP |
|---|
| 808 | The \fIthreadActionProc\fR field contains the address of the function |
|---|
| 809 | called by the generic layer when a channel is created, closed, or |
|---|
| 810 | going to move to a different thread, i.e. whenever thread-specific |
|---|
| 811 | driver state might have to initialized or updated. It can be NULL. |
|---|
| 812 | The action \fITCL_CHANNEL_THREAD_REMOVE\fR is used to notify the |
|---|
| 813 | driver that it should update or remove any thread-specific data it |
|---|
| 814 | might be maintaining for the channel. |
|---|
| 815 | .PP |
|---|
| 816 | The action \fITCL_CHANNEL_THREAD_INSERT\fR is used to notify the |
|---|
| 817 | driver that it should update or initialize any thread-specific data it |
|---|
| 818 | might be maintaining using the calling thread as the associate. See |
|---|
| 819 | \fBTcl_CutChannel\fR and \fBTcl_SpliceChannel\fR for more detail. |
|---|
| 820 | .PP |
|---|
| 821 | .CS |
|---|
| 822 | typedef void Tcl_DriverThreadActionProc( |
|---|
| 823 | ClientData \fIinstanceData\fR, |
|---|
| 824 | int \fIaction\fR); |
|---|
| 825 | .CE |
|---|
| 826 | .PP |
|---|
| 827 | \fIInstanceData\fR is the same as the value passed to |
|---|
| 828 | \fBTcl_CreateChannel\fR when this channel was created. |
|---|
| 829 | .PP |
|---|
| 830 | These values can be retrieved with \fBTcl_ChannelThreadActionProc\fR, |
|---|
| 831 | which returns a pointer to the function. |
|---|
| 832 | .SS "TRUNCATEPROC" |
|---|
| 833 | .PP |
|---|
| 834 | The \fItruncateProc\fR field contains the address of the function |
|---|
| 835 | called by the generic layer when a channel is truncated to some |
|---|
| 836 | length. It can be NULL. |
|---|
| 837 | .PP |
|---|
| 838 | .CS |
|---|
| 839 | typedef int Tcl_DriverTruncateProc( |
|---|
| 840 | ClientData \fIinstanceData\fR, |
|---|
| 841 | Tcl_WideInt \fIlength\fR); |
|---|
| 842 | .CE |
|---|
| 843 | .PP |
|---|
| 844 | \fIInstanceData\fR is the same as the value passed to |
|---|
| 845 | \fBTcl_CreateChannel\fR when this channel was created, and |
|---|
| 846 | \fIlength\fR is the new length of the underlying file, which should |
|---|
| 847 | not be negative. The result should be 0 on success or an errno code |
|---|
| 848 | (suitable for use with \fBTcl_SetErrno\fR) on failure. |
|---|
| 849 | .PP |
|---|
| 850 | These values can be retrieved with \fBTcl_ChannelTruncateProc\fR, |
|---|
| 851 | which returns a pointer to the function. |
|---|
| 852 | .SH TCL_BADCHANNELOPTION |
|---|
| 853 | .PP |
|---|
| 854 | This procedure generates a |
|---|
| 855 | .QW "bad option" |
|---|
| 856 | error message in an |
|---|
| 857 | (optional) interpreter. It is used by channel drivers when |
|---|
| 858 | an invalid Set/Get option is requested. Its purpose is to concatenate |
|---|
| 859 | the generic options list to the specific ones and factorize |
|---|
| 860 | the generic options error message string. |
|---|
| 861 | .PP |
|---|
| 862 | It always returns \fBTCL_ERROR\fR |
|---|
| 863 | .PP |
|---|
| 864 | An error message is generated in \fIinterp\fR's result object to |
|---|
| 865 | indicate that a command was invoked with a bad option. |
|---|
| 866 | The message has the form |
|---|
| 867 | .CS |
|---|
| 868 | bad option "blah": should be one of |
|---|
| 869 | <...generic options...>+<...specific options...> |
|---|
| 870 | .CE |
|---|
| 871 | so you get for instance: |
|---|
| 872 | .CS |
|---|
| 873 | bad option "-blah": should be one of -blocking, |
|---|
| 874 | -buffering, -buffersize, -eofchar, -translation, |
|---|
| 875 | -peername, or -sockname |
|---|
| 876 | .CE |
|---|
| 877 | when called with \fIoptionList\fR equal to |
|---|
| 878 | .QW "peername sockname" |
|---|
| 879 | .PP |
|---|
| 880 | .QW blah |
|---|
| 881 | is the \fIoptionName\fR argument and |
|---|
| 882 | .QW "<specific options>" |
|---|
| 883 | is a space separated list of specific option words. |
|---|
| 884 | The function takes good care of inserting minus signs before |
|---|
| 885 | each option, commas after, and an |
|---|
| 886 | .QW or |
|---|
| 887 | before the last option. |
|---|
| 888 | .SH "OLD CHANNEL TYPES" |
|---|
| 889 | The original (8.3.1 and below) \fBTcl_ChannelType\fR structure contains |
|---|
| 890 | the following fields: |
|---|
| 891 | .PP |
|---|
| 892 | .CS |
|---|
| 893 | typedef struct Tcl_ChannelType { |
|---|
| 894 | char *\fItypeName\fR; |
|---|
| 895 | Tcl_DriverBlockModeProc *\fIblockModeProc\fR; |
|---|
| 896 | Tcl_DriverCloseProc *\fIcloseProc\fR; |
|---|
| 897 | Tcl_DriverInputProc *\fIinputProc\fR; |
|---|
| 898 | Tcl_DriverOutputProc *\fIoutputProc\fR; |
|---|
| 899 | Tcl_DriverSeekProc *\fIseekProc\fR; |
|---|
| 900 | Tcl_DriverSetOptionProc *\fIsetOptionProc\fR; |
|---|
| 901 | Tcl_DriverGetOptionProc *\fIgetOptionProc\fR; |
|---|
| 902 | Tcl_DriverWatchProc *\fIwatchProc\fR; |
|---|
| 903 | Tcl_DriverGetHandleProc *\fIgetHandleProc\fR; |
|---|
| 904 | Tcl_DriverClose2Proc *\fIclose2Proc\fR; |
|---|
| 905 | } Tcl_ChannelType; |
|---|
| 906 | .CE |
|---|
| 907 | .PP |
|---|
| 908 | It is still possible to create channel with the above structure. The |
|---|
| 909 | internal channel code will determine the version. It is imperative to use |
|---|
| 910 | the new \fBTcl_ChannelType\fR structure if you are creating a stacked |
|---|
| 911 | channel driver, due to problems with the earlier stacked channel |
|---|
| 912 | implementation (in 8.2.0 to 8.3.1). |
|---|
| 913 | .PP |
|---|
| 914 | Prior to 8.4.0 (i.e. during the later releases of 8.3 and early part |
|---|
| 915 | of the 8.4 development cycle) the \fBTcl_ChannelType\fR structure |
|---|
| 916 | contained the following fields: |
|---|
| 917 | .PP |
|---|
| 918 | .CS |
|---|
| 919 | typedef struct Tcl_ChannelType { |
|---|
| 920 | char *\fItypeName\fR; |
|---|
| 921 | Tcl_ChannelTypeVersion \fIversion\fR; |
|---|
| 922 | Tcl_DriverCloseProc *\fIcloseProc\fR; |
|---|
| 923 | Tcl_DriverInputProc *\fIinputProc\fR; |
|---|
| 924 | Tcl_DriverOutputProc *\fIoutputProc\fR; |
|---|
| 925 | Tcl_DriverSeekProc *\fIseekProc\fR; |
|---|
| 926 | Tcl_DriverSetOptionProc *\fIsetOptionProc\fR; |
|---|
| 927 | Tcl_DriverGetOptionProc *\fIgetOptionProc\fR; |
|---|
| 928 | Tcl_DriverWatchProc *\fIwatchProc\fR; |
|---|
| 929 | Tcl_DriverGetHandleProc *\fIgetHandleProc\fR; |
|---|
| 930 | Tcl_DriverClose2Proc *\fIclose2Proc\fR; |
|---|
| 931 | Tcl_DriverBlockModeProc *\fIblockModeProc\fR; |
|---|
| 932 | Tcl_DriverFlushProc *\fIflushProc\fR; |
|---|
| 933 | Tcl_DriverHandlerProc *\fIhandlerProc\fR; |
|---|
| 934 | Tcl_DriverTruncateProc *\fItruncateProc\fR; |
|---|
| 935 | } Tcl_ChannelType; |
|---|
| 936 | .CE |
|---|
| 937 | .PP |
|---|
| 938 | When the above structure is registered as a channel type, the |
|---|
| 939 | \fIversion\fR field should always be \fBTCL_CHANNEL_VERSION_2\fR. |
|---|
| 940 | |
|---|
| 941 | .SH "SEE ALSO" |
|---|
| 942 | Tcl_Close(3), Tcl_OpenFileChannel(3), Tcl_SetErrno(3), Tcl_QueueEvent(3), Tcl_StackChannel(3), Tcl_GetStdChannel(3) |
|---|
| 943 | |
|---|
| 944 | .SH KEYWORDS |
|---|
| 945 | blocking, channel driver, channel registration, channel type, nonblocking |
|---|