📄 crtchannel.3
字号:
(thread)global list of all channels (of the current thread).Application to a channel registered in some interpreter is not allowed..PP\fBTcl_ClearChannelHandlers\fR removes all channelhandlers and eventscripts associated with the specified \fIchannel\fR, thus shuttingdown all event processing for this channel..VE 8.4.SH TCL_CHANNELTYPE.PPA channel driver provides a \fBTcl_ChannelType\fR structure that containspointers to functions that implement the various operations on a channel;these operations are invoked as needed by the generic layer. The structurewas versioned starting in Tcl 8.3.2/8.4 to correct a problem with stackedchannel drivers. See the \fBOLD CHANNEL TYPES\fR section below fordetails about the old structure..PPThe \fBTcl_ChannelType\fR structure contains the following fields:.CStypedef struct Tcl_ChannelType { char *\fItypeName\fR; Tcl_ChannelTypeVersion \fIversion\fR; Tcl_DriverCloseProc *\fIcloseProc\fR; Tcl_DriverInputProc *\fIinputProc\fR; Tcl_DriverOutputProc *\fIoutputProc\fR; Tcl_DriverSeekProc *\fIseekProc\fR; Tcl_DriverSetOptionProc *\fIsetOptionProc\fR; Tcl_DriverGetOptionProc *\fIgetOptionProc\fR; Tcl_DriverWatchProc *\fIwatchProc\fR; Tcl_DriverGetHandleProc *\fIgetHandleProc\fR; Tcl_DriverClose2Proc *\fIclose2Proc\fR; Tcl_DriverBlockModeProc *\fIblockModeProc\fR; Tcl_DriverFlushProc *\fIflushProc\fR; Tcl_DriverHandlerProc *\fIhandlerProc\fR; Tcl_DriverWideSeekProc *\fIwideSeekProc\fR;} Tcl_ChannelType;.CE.PPThe driver must provide implementations for all functions except\fIblockModeProc\fR, \fIseekProc\fR, \fIsetOptionProc\fR,\fIgetOptionProc\fR, and \fIclose2Proc\fR, which may be specified asNULL. Other functions that can not be implemented for this type ofdevice should return \fBEINVAL\fR when invoked to indicate that theyare not implemented, except in the case of \fIflushProc\fR and\fIhandlerProc\fR, which should specified as NULL if not otherwise defined..PPThe user should only use the above structure for \fBTcl_ChannelType\fRinstantiation. When referencing fields in a \fBTcl_ChannelType\fRstructure, the following functions should be used to obtain the values:\fBTcl_ChannelName\fR, \fBTcl_ChannelVersion\fR,\fBTcl_ChannelBlockModeProc\fR, \fBTcl_ChannelCloseProc\fR,\fBTcl_ChannelClose2Proc\fR, \fBTcl_ChannelInputProc\fR,\fBTcl_ChannelOutputProc\fR, \fBTcl_ChannelSeekProc\fR,.VS 8.4\fBTcl_ChannelWideSeekProc\fR,.VE 8.4\fBTcl_ChannelSetOptionProc\fR, \fBTcl_ChannelGetOptionProc\fR,\fBTcl_ChannelWatchProc\fR, \fBTcl_ChannelGetHandleProc\fR,\fBTcl_ChannelFlushProc\fR, or \fBTcl_ChannelHandlerProc\fR..PPThe change to the structures was made in such a way that standard channeltypes are binary compatible. However, channel types that use stackedchannels (ie: TLS, Trf) have new versions to correspond to the above changesince the previous code for stacked channels had problems..SH TYPENAME.PPThe \fItypeName\fR field contains a null-terminated string thatidentifies the type of the device implemented by this driver, e.g.\fBfile\fR or \fBsocket\fR..PPThis value can be retrieved with \fBTcl_ChannelName\fR, which returnsa pointer to the string..SH VERSION.PPThe \fIversion\fR field should be set to \fBTCL_CHANNEL_VERSION_2\fR.If it is not set to this value \fBTCL_CHANNEL_VERSION_3\fR, then this\fBTcl_ChannelType\fR is assumed to have the older structure. See\fBOLD CHANNEL TYPES\fR for more details. While Tcl will recognizeand function with either structure, stacked channels must be of atleast \fBTCL_CHANNEL_VERSION_2\fR to function correctly..PPThis value can be retrieved with \fBTcl_ChannelVersion\fR, which returns.VS 8.4one of \fBTCL_CHANNEL_VERSION_3\fR,.VE 8.4\fBTCL_CHANNEL_VERSION_2\fR or \fBTCL_CHANNEL_VERSION_1\fR..SH BLOCKMODEPROC.PPThe \fIblockModeProc\fR field contains the address of a function called bythe generic layer to set blocking and nonblocking mode on the device.\fIBlockModeProc\fR should match the following prototype:.PP.CStypedef int Tcl_DriverBlockModeProc( ClientData \fIinstanceData\fR, int \fImode\fR);.CE.PPThe \fIinstanceData\fR is the same as the value passed to\fBTcl_CreateChannel\fR when this channel was created. The \fImode\fRargument is either \fBTCL_MODE_BLOCKING\fR or \fBTCL_MODE_NONBLOCKING\fR toset the device into blocking or nonblocking mode. The function shouldreturn zero if the operation was successful, or a nonzero POSIX error codeif the operation failed..PPIf the operation is successful, the function can modify the supplied\fIinstanceData\fR to record that the channel entered blocking ornonblocking mode and to implement the blocking or nonblocking behavior.For some device types, the blocking and nonblocking behavior can beimplemented by the underlying operating system; for other device types, thebehavior must be emulated in the channel driver..PPThis value can be retrieved with \fBTcl_ChannelBlockModeProc\fR, which returnsa pointer to the function..SH "CLOSEPROC AND CLOSE2PROC".PPThe \fIcloseProc\fR field contains the address of a function called by thegeneric layer to clean up driver-related information when the channel isclosed. \fICloseProc\fR must match the following prototype:.PP.CStypedef int Tcl_DriverCloseProc( ClientData \fIinstanceData\fR, Tcl_Interp *\fIinterp\fR);.CE.PPThe \fIinstanceData\fR argument is the same as the value provided to\fBTcl_CreateChannel\fR when the channel was created. The function shouldrelease any storage maintained by the channel driver for this channel, andclose the input and output devices encapsulated by this channel. All queuedoutput will have been flushed to the device before this function is called,and no further driver operations will be invoked on this instance aftercalling the \fIcloseProc\fR. If the close operation is successful, theprocedure should return zero; otherwise it should return a nonzero POSIXerror code. In addition, if an error occurs and \fIinterp\fR is not NULL,the procedure should store an error message in the interpreter's result..PPAlternatively, channels that support closing the read and write sidesindependently may set \fIcloseProc\fR to \fBTCL_CLOSE2PROC\fR and set\fIclose2Proc\fR to the address of a function that matches thefollowing prototype:.PP.CStypedef int Tcl_DriverClose2Proc( ClientData \fIinstanceData\fR, Tcl_Interp *\fIinterp\fR, int \fIflags\fR);.CE.PPThe \fIclose2Proc\fR will be called with \fIflags\fR set to an OR'edcombination of \fBTCL_CLOSE_READ\fR or \fBTCL_CLOSE_WRITE\fR toindicate that the driver should close the read and/or write side ofthe channel. The channel driver may be invoked to performadditional operations on the channel after \fIclose2Proc\fR iscalled to close one or both sides of the channel. If \fIflags\fR is\fB0\fR (zero), the driver should close the channel in the mannerdescribed above for \fIcloseProc\fR. No further operations will beinvoked on this instance after \fIclose2Proc\fR is called with allflags cleared. In all cases, the \fIclose2Proc\fR function shouldreturn zero if the close operation was successful; otherwise it shouldreturn a nonzero POSIX error code. In addition, if an error occurs and\fIinterp\fR is not NULL, the procedure should store an error messagein the interpreter's result..PPThese value can be retrieved with \fBTcl_ChannelCloseProc\fR or\fBTcl_ChannelClose2Proc\fR, which returns a pointer to the respectivefunction..SH INPUTPROC.PPThe \fIinputProc\fR field contains the address of a function called by thegeneric layer to read data from the file or device and store it in aninternal buffer. \fIInputProc\fR must match the following prototype:.PP.CStypedef int Tcl_DriverInputProc( ClientData \fIinstanceData\fR, char *\fIbuf\fR, int \fIbufSize\fR, int *\fIerrorCodePtr\fR);.CE.PP\fIInstanceData\fR is the same as the value passed to\fBTcl_CreateChannel\fR when the channel was created. The \fIbuf\fRargument points to an array of bytes in which to store input from thedevice, and the \fIbufSize\fR argument indicates how many bytes areavailable at \fIbuf\fR..PPThe \fIerrorCodePtr\fR argument points to an integer variable provided bythe generic layer. If an error occurs, the function should set the variableto a POSIX error code that identifies the error that occurred..PPThe function should read data from the input device encapsulated by thechannel and store it at \fIbuf\fR. On success, the function should returna nonnegative integer indicating how many bytes were read from the inputdevice and stored at \fIbuf\fR. On error, the function should return -1. Ifan error occurs after some data has been read from the device, that data islost..PPIf \fIinputProc\fR can determine that the input device has some dataavailable but less than requested by the \fIbufSize\fR argument, thefunction should only attempt to read as much data as is available andreturn without blocking. If the input device has no data availablewhatsoever and the channel is in nonblocking mode, the function shouldreturn an \fBEAGAIN\fR error. If the input device has no data availablewhatsoever and the channel is in blocking mode, the function should blockfor the shortest possible time until at least one byte of data can be readfrom the device; then, it should return as much data as it can read withoutblocking..PPThis value can be retrieved with \fBTcl_ChannelInputProc\fR, which returnsa pointer to the function..SH OUTPUTPROC.PPThe \fIoutputProc\fR field contains the address of a function called by thegeneric layer to transfer data from an internal buffer to the output device.\fIOutputProc\fR must match the following prototype:.PP.CStypedef int Tcl_DriverOutputProc( ClientData \fIinstanceData\fR, CONST char *\fIbuf\fR, int \fItoWrite\fR, int *\fIerrorCodePtr\fR);.CE.PP\fIInstanceData\fR is the same as the value passed to\fBTcl_CreateChannel\fR when the channel was created. The \fIbuf\fRargument contains an array of bytes to be written to the device, and the\fItoWrite\fR argument indicates how many bytes are to be written from the\fIbuf\fR argument..PPThe \fIerrorCodePtr\fR argument points to an integer variable provided bythe generic layer. If an error occurs, the function should set thisvariable to a POSIX error code that identifies the error..PPThe function should write the data at \fIbuf\fR to the output deviceencapsulated by the channel. On success, the function should return anonnegative integer indicating how many bytes were written to the outputdevice. The return value is normally the same as \fItoWrite\fR, but may beless in some cases such as if the output operation is interrupted by asignal. If an error occurs the function should return -1. In case oferror, some data may have been written to the device..PPIf the channel is nonblocking and the output device is unable to absorb anydata whatsoever, the function should return -1 with an \fBEAGAIN\fR errorwithout writing any data..PPThis value can be retrieved with \fBTcl_ChannelOutputProc\fR, which returnsa pointer to the function..SH "SEEKPROC AND WIDESEEKPROC".PPThe \fIseekProc\fR field contains the address of a function called by thegeneric layer to move the access point at which subsequent input or outputoperations will be applied. \fISeekProc\fR must match the followingprototype:.PP.CStypedef int Tcl_DriverSeekProc( ClientData \fIinstanceData\fR, long \fIoffset\fR, int \fIseekMode\fR, int *\fIerrorCodePtr\fR);.CE.PPThe \fIinstanceData\fR argument is the same as the value given to\fBTcl_CreateChannel\fR when this channel was created. \fIOffset\fR and\fIseekMode\fR have the same meaning as for the \fBTcl_Seek\fRprocedure (described in the manual entry for \fBTcl_OpenFileChannel\fR)..PPThe \fIerrorCodePtr\fR argument points to an integer variable provided bythe generic layer for returning \fBerrno\fR values from the function. Thefunction should set this variable to a POSIX error code if an error occurs.The function should store an \fBEINVAL\fR error code if the channel typedoes not implement seeking..PPThe return value is the new access point or -1 in case of error. If anerror occurred, the function should not move the access point..PP.VS 8.4If there is a non-NULL \fIseekProc\fR field, the \fIwideSeekProc\fRfield may contain the address of an alternative function to use whichhandles wide (i.e. larger than 32-bit) offsets, so allowing seekswithin files larger than 2GB. The \fIwideSeekProc\fR will be called
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -