📄 crtchannel.3
字号:
'\"'\" Copyright (c) 1996-1997 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\"'\" SCCS: @(#) CrtChannel.3 1.29 97/06/20 13:37:45.so man.macros.TH Tcl_CreateChannel 3 8.0 Tcl "Tcl Library Procedures".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMETcl_CreateChannel, Tcl_GetChannelInstanceData, Tcl_GetChannelType, Tcl_GetChannelName, Tcl_GetChannelHandle, Tcl_GetChannelMode, Tcl_GetChannelBufferSize, Tcl_SetDefaultTranslation, Tcl_SetChannelBufferSize, Tcl_NotifyChannel, Tcl_BadChannelOption \- procedures for creating and manipulating channels.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.spTcl_Channel\fBTcl_CreateChannel\fR(\fItypePtr, channelName, instanceData, mask\fR).spClientData\fBTcl_GetChannelInstanceData\fR(\fIchannel\fR).spTcl_ChannelType *\fBTcl_GetChannelType\fR(\fIchannel\fR).spchar *\fBTcl_GetChannelName\fR(\fIchannel\fR).VS.spint\fBTcl_GetChannelHandle\fR(\fIchannel, direction, handlePtr\fR).VE.spint\fBTcl_GetChannelFlags\fR(\fIchannel\fR).sp\fBTcl_SetDefaultTranslation\fR(\fIchannel, transMode\fR).spint\fBTcl_GetChannelBufferSize\fR(\fIchannel\fR).sp\fBTcl_SetChannelBufferSize\fR(\fIchannel, size\fR).sp.VS\fBTcl_NotifyChannel\fR(\fIchannel, mask\fR).spint\fBTcl_BadChannelOption\fR(\fIinterp, optionName, optionList\fR).VE.sp.SH ARGUMENTS.AS Tcl_EolTranslation *channelName in.AP Tcl_ChannelType *typePtr inPoints to a structure containing the addresses of procedures thatcan be called to perform I/O and other functions on the channel..AP char *channelName inThe name of this channel, such as \fBfile3\fR; must not be in useby any other channel. Can be NULL, in which case the channel iscreated without a name..AP ClientData instanceData inArbitrary one-word value to be associated with this channel. Thisvalue is passed to procedures in \fItypePtr\fR when they are invoked..AP int mask inOR-ed combination of \fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR to indicatewhether a channel is readable and writable..AP Tcl_Channel channel inThe channel to operate on..VS.AP int direction in\fBTCL_READABLE\fR means the input handle is wanted; \fBTCL_WRITABLE\fRmeans the output handle is wanted..AP ClientData *handlePtr outPoints to the location where the desired OS-specific handle should bestored..VE.AP Tcl_EolTranslation transMode inThe translation mode; one of the constants \fBTCL_TRANSLATE_AUTO\fR,\fBTCL_TRANSLATE_CR\fR, \fBTCL_TRANSLATE_LF\fR and \fBTCL_TRANSLATE_CRLF\fR..AP int size inThe size, in bytes, of buffers to allocate in this channel..VS.AP int mask inAn OR-ed combination of \fBTCL_READABLE\fR, \fBTCL_WRITABLE\fRand \fBTCL_EXCEPTION\fR that indicates events that have occurred onthis channel..AP Tcl_Interp *interp inCurrent interpreter. (can be NULL).AP char *optionName inName of the invalid option..AP char *optionList inSpecific options list (space separated words, without "-") to append to the standard generic options list.Can be NULL for generic options error message only..VE.BE.SH DESCRIPTION.PPTcl uses a two-layered channel architecture. It provides a generic upperlayer to enable C and Tcl programs to perform input and output using thesame APIs for a variety of files, devices, sockets etc. The generic C APIsare described in the manual entry for \fBTcl_OpenFileChannel\fR..PPThe lower layer provides type-specific channel drivers for each typeof device supported on each platform. This manual entry describes theC APIs used to communicate between the generic layer and thetype-specific channel drivers. It also explains how new types ofchannels can be added by providing new channel drivers..PPChannel drivers consist of a number of components: First, each channeldriver provides a \fBTcl_ChannelType\fR structure containing pointers tofunctions implementing the various operations used by the generic layer tocommunicate with the channel driver. The \fBTcl_ChannelType\fR structureand the functions referenced by it are described in the sectionTCL_CHANNELTYPE, below..PPSecond, channel drivers usually provide a Tcl command to createinstances of that type of channel. For example, the Tcl \fBopen\fRcommand creates channels that use the file and command channeldrivers, and the Tcl \fBsocket\fR command creates channels that useTCP sockets for network communication..PPThird, a channel driver optionally provides a C function to openchannel instances of that type. For example, \fBTcl_OpenFileChannel\fRopens a channel that uses the file channel driver, and\fBTcl_OpenTcpClient\fR opens a channel that uses the TCP networkprotocol. These creation functions typically use\fBTcl_CreateChannel\fR internally to open the channel..PPTo add a new type of channel you must implement a C API or a Tcl commandthat opens a channel by invoking \fBTcl_CreateChannel\fR.When your driver calls \fBTcl_CreateChannel\fR it passes ina \fBTcl_ChannelType\fR structure describing the driver's I/Oprocedures.The generic layer will then invoke the functions referenced in thatstructure to perform operations on the channel..PP\fBTcl_CreateChannel\fR opens a new channel and associates the supplied\fItypePtr\fR and \fIinstanceData\fR with it. The channel is opened in themode indicated by \fImask\fR.For a discussion of channel drivers, their operations and the\fBTcl_ChannelType\fR structure, see the section TCL_CHANNELTYPE, below..PP\fBTcl_GetChannelInstanceData\fR returns the instance data associated withthe channel in \fIchannel\fR. This is the same as the \fIinstanceData\fRargument in the call to \fBTcl_CreateChannel\fR that created this channel..PP\fBTcl_GetChannelType\fR returns a pointer to the \fBTcl_ChannelType\fRstructure used by the channel in the \fIchannel\fR argument. This isthe same as the \fItypePtr\fR argument in the call to\fBTcl_CreateChannel\fR that created this channel..PP\fBTcl_GetChannelName\fR returns a string containing the name associatedwith the channel, or NULL if the \fIchannelName\fR argument to\fBTcl_CreateChannel\fR was NULL..PP.VS\fBTcl_GetChannelHandle\fR places the OS-specific device handleassociated with \fIchannel\fR for the given \fIdirection\fR in thelocation specified by \fIhandlePtr\fR and returns \fBTCL_OK\fR. Ifthe channel does not have a device handle for the specified direction,then \fBTCL_ERROR\fR is returned instead. Different channel driverswill return different types of handle. Refer to the manual entriesfor each driver to determine what type of handle is returned..VE.PP\fBTcl_GetChannelMode\fR returns an OR-ed combination of \fBTCL_READABLE\fRand \fBTCL_WRITABLE\fR, indicating whether the channel is open for inputand output..PP\fBTcl_SetDefaultTranslation\fR sets the default end of line translationmode. This mode will be installed as the translation mode for the channelif an attempt is made to output on the channel while it is still in\fBTCL_TRANSLATE_AUTO\fR mode. For a description of end of line translationmodes, see the manual entry for \fBfconfigure\fR..PP\fBTcl_GetChannelBufferSize\fR returns the size, in bytes, of buffersallocated to store input or output in \fIchan\fR. If the value was not setby a previous call to \fBTcl_SetChannelBufferSize\fR, described below, thenthe default value of 4096 is returned..PP\fBTcl_SetChannelBufferSize\fR sets the size, in bytes, of buffers thatwill be allocated in subsequent operations on the channel to store input oroutput. The \fIsize\fR argument should be between ten and one million,allowing buffers of ten bytes to one million bytes. If \fIsize\fR isoutside this range, \fBTcl_SetChannelBufferSize\fR sets the buffer size to4096..PP.VS\fBTcl_NotifyChannel\fR is called by a channel driver to indicate tothe generic layer that the events specified by \fImask\fR haveoccurred on the channel. Channel drivers are responsible for invokingthis function whenever the channel handlers need to be called for thechannel. See \fBWATCHPROC\fR below for more details..VE.PP.VS\fBTcl_BadChannelOption\fR is called from driver specific set or get optionprocs to generate a complete error message..VE.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\fBTcl_ChannelType\fR structure contains the following fields:.PP.VS.CStypedef struct Tcl_ChannelType { char *\fItypeName\fR; Tcl_DriverBlockModeProc *\fIblockModeProc\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_ChannelType;.CE.VE.PPThe driver must provide implementations for all functions except\fIblockModeProc\fR, \fIseekProc\fR, \fIsetOptionProc\fR, and\fIgetOptionProc\fR, which may be specified as NULL to indicate that thechannel does not support seeking. Other functions that can not beimplemented for this type of device should return \fBEINVAL\fR when invokedto indicate that they are not implemented..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..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..SH CLOSEPROC.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 POSIX
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -