⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 openfilechnl.3

📁 linux系统下的音频通信
💻 3
📖 第 1 页 / 共 2 页
字号:
\fBTcl_GetChannel\fR returns a channel given the \fIchannelName\fR used tocreate it with \fBTcl_CreateChannel\fR and a pointer to a Tcl interpreter in\fIinterp\fR. If a channel by that name is not registered in that interpreter,the procedure returns NULL. If the \fImode\fR argument is not NULL, itpoints at an integer variable that will receive an OR-ed combination of\fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR describing whether the channel isopen for reading and writing..SH TCL_REGISTERCHANNEL.PP\fBTcl_RegisterChannel\fR adds a channel to the set of channels accessiblein \fIinterp\fR. After this call, Tcl programs executing in thatinterpreter can refer to the channel in input or output operations usingthe name given in the call to \fBTcl_CreateChannel\fR.  After this call,the channel becomes the property of the interpreter, and the caller shouldnot call \fBTcl_Close\fR for the channel; the channel will be closedautomatically when it is unregistered from the interpreter..PPCode executing outside of any Tcl interpreter can call\fBTcl_RegisterChannel\fR with \fIinterp\fR as NULL, to indicate that itwishes to hold a reference to this channel. Subsequently, the channel canbe registered in a Tcl interpreter and it will only be closed when thematching number of calls to \fBTcl_UnregisterChannel\fR have been made.This allows code executing outside of any interpreter to safely hold areference to a channel that is also registered in a Tcl interpreter..SH TCL_UNREGISTERCHANNEL.PP\fBTcl_UnregisterChannel\fR removes a channel from the set of channelsaccessible in \fIinterp\fR. After this call, Tcl programs will no longer beable to use the channel's name to refer to the channel in that interpreter.If this operation removed the last registration of the channel in anyinterpreter, the channel is also closed and destroyed..PPCode not associated with a Tcl interpreter can call\fBTcl_UnregisterChannel\fR with \fIinterp\fR as NULL, to indicate to Tclthat it no longer holds a reference to that channel. If this is the lastreference to the channel, it will now be closed..SH TCL_CLOSE.PP\fBTcl_Close\fR destroys the channel \fIchannel\fR, which must denote acurrently open channel. The channel should not be registered in anyinterpreter when \fBTcl_Close\fR is called. Buffered output is flushed tothe channel's output device prior to destroying the channel, and anybuffered input is discarded.  If this is a blocking channel, the call doesnot return until all buffered data is successfully sent to the channel'soutput device.  If this is a nonblocking channel and there is bufferedoutput that cannot be written without blocking, the call returnsimmediately; output is flushed in the background and the channel will beclosed once all of the buffered data has been output.  In this case errorsduring flushing are not reported..PPIf the channel was closed successfully, \fBTcl_Close\fR returns \fBTCL_OK\fR.If an error occurs, \fBTcl_Close\fR returns \fBTCL_ERROR\fR and records aPOSIX error code that can be retrieved with \fBTcl_GetErrno\fR.If the channel is being closed synchronously and an error occurs duringclosing of the channel and \fIinterp\fR is not NULL, an error message isleft in \fIinterp->result\fR..PPNote: it is not safe to call \fBTcl_Close\fR on a channel that has beenregistered using \fBTcl_RegisterChannel\fR; see the documentation for\fBTcl_RegisterChannel\fR, above, for details. If the channel has ever beengiven as the \fBchan\fR argument in a call to \fBTcl_RegisterChannel\fR,you should instead use \fBTcl_UnregisterChannel\fR, which will internallycall \fBTcl_Close\fR when all calls to \fBTcl_RegisterChannel\fR have beenmatched by corresponding calls to \fBTcl_UnregisterChannel\fR..SH TCL_READ.PP\fBTcl_Read\fR consumes up to \fItoRead\fR bytes of data from\fIchannel\fR and stores it at \fIbuf\fR.The return value of \fBTcl_Read\fR is the number of characters writtenat \fIbuf\fR.The buffer produced by \fBTcl_Read\fR is not NULL terminated. Its contentsare valid from the zeroth position up to and excluding the positionindicated by the return value.If an error occurs, the return value is -1 and \fBTcl_Read\fR recordsa POSIX error code that can be retrieved with \fBTcl_GetErrno\fR..PPThe return value may be smaller than the value of \fItoRead\fR, indicatingthat less data than requested was available, also called a \fIshortread\fR.In blocking mode, this can only happen on an end-of-file.In nonblocking mode, a short read can also occur if there is notenough input currently available:  \fBTcl_Read\fR returns a shortcount rather than waiting for more data..PPIf the channel is in blocking mode, a return value of zero indicates an endof file condition. If the channel is in nonblocking mode, a return value ofzero indicates either that no input is currently available or an end offile condition. Use \fBTcl_Eof\fR and \fBTcl_InputBlocked\fRto tell which of these conditions actually occurred..PP\fBTcl_Read\fR translates platform-specific end-of-line representationsinto the canonical \fB\en\fR internal representation according to thecurrent end-of-line recognition mode. End-of-line recognition and thevarious platform-specific modes are described in the manual entry for theTcl \fBfconfigure\fR command..SH TCL_GETS AND TCL_GETSOBJ.PP\fBTcl_Gets\fR reads a line of input from a channel and appends all ofthe characters of the line except for the terminating end-of-line character(s)to the dynamic string given by \fIdsPtr\fR.The end-of-line character(s) are read and discarded..PPIf a line was successfully read, the return value is greater than orequal to zero, and it indicates the number of characters storedin the dynamic string.If an error occurs, \fBTcl_Gets\fR returns -1 and records a POSIX errorcode that can be retrieved with \fBTcl_GetErrno\fR.\fBTcl_Gets\fR also returns -1 if the end of the file is reached;the \fBTcl_Eof\fR procedure can be used to distinguish an errorfrom an end-of-file condition..PPIf the channel is in nonblocking mode, the return value can alsobe -1 if no data was available or the data that was availabledid not contain an end-of-line character.When -1 is returned, the \fBTcl_InputBlocked\fR procedure may beinvoked to determine if the channel is blocked because of inputunavailability..PP\fBTcl_GetsObj\fR is the same as \fBTcl_Gets\fR except the resultingcharacters are appended to a Tcl object \fBlineObjPtr\fR rather than adynamic string..SH TCL_WRITE.PP\fBTcl_Write\fR accepts \fItoWrite\fR bytes of data at \fIbuf\fR for outputon \fIchannel\fR. This data may not appear on the output deviceimmediately. If the data should appear immediately, call \fBTcl_Flush\fRafter the call to \fBTcl_Write\fR, or set the \fB-buffering\fR option onthe channel to \fBnone\fR. If you wish the data to appear as soon as an endof line is accepted for output, set the \fB\-buffering\fR option on thechannel to \fBline\fR mode..PPThe \fItoWrite\fR argument specifies how many bytes of data are provided inthe \fIbuf\fR argument. If it is negative, \fBTcl_Write\fR expects the datato be NULL terminated and it outputs everything up to the NULL..PPThe return value of \fBTcl_Write\fR is a count of how manycharacters were accepted for output to the channel. This is either equal to\fItoWrite\fR or -1 to indicate that an error occurred.If an error occurs, \fBTcl_Write\fR also records a POSIX error codethat may be retrieved with \fBTcl_GetErrno\fR..PPNewline characters in the output data are translated to platform-specificend-of-line sequences according to the \fB\-translation\fR option forthe channel..SH TCL_FLUSH.PP\fBTcl_Flush\fR causes all of the buffered output data for \fIchannel\fRto be written to its underlying file or device as soon as possible.If the channel is in blocking mode, the call does not return untilall the buffered data has been sent to the channel or some error occurred.The call returns immediately if the channel is nonblocking; it startsa background flush that will write the buffered data to the channeleventually, as fast as the channel is able to absorb it..PPThe return value is normally \fBTCL_OK\fR.If an error occurs, \fBTcl_Flush\fR returns \fBTCL_ERROR\fR andrecords a POSIX error code that can be retrieved with \fBTcl_GetErrno\fR..SH TCL_SEEK.PP\fBTcl_Seek\fR moves the access point in \fIchannel\fR where subsequentdata will be read or written. Buffered output is flushed to the channel andbuffered input is discarded, prior to the seek operation..PP\fBTcl_Seek\fR normally returns the new access point.If an error occurs, \fBTcl_Seek\fR returns -1 and records a POSIX errorcode that can be retrieved with \fBTcl_GetErrno\fR.After an error, the access point may or may not have been moved..SH TCL_TELL.PP\fBTcl_Tell\fR returns the current access point for a channel. The returnedvalue is -1 if the channel does not support seeking..SH TCL_GETCHANNELOPTION.PP\fBTcl_GetChannelOption\fR retrieves, in \fIdsPtr\fR, the value of one ofthe options currently in effect for a channel, or a list of all options andtheir values.  The \fIchannel\fR argument identifies the channel for whichto query an option or retrieve all options and their values.If \fIoptionName\fR is not NULL, it is the name of theoption to query; the option's value is copied to the Tcl dynamic stringdenoted by \fIoptionValue\fR. If\fIoptionName\fR is NULL, the function stores an alternating list of optionnames and their values in \fIoptionValue\fR, using a series of calls to\fBTcl_DStringAppendElement\fR. The various preexisting options andtheir possible values are described in the manual entry for the Tcl\fBfconfigure\fR command. Other options can be added by each channel type.These channel type specific options are described in the manual entry forthe Tcl command that creates a channel of that type; for example, theadditional options for TCP based channels are described in the manual entryfor the Tcl \fBsocket\fR command.The procedure normally returns \fBTCL_OK\fR. If an error occurs, it returns\fBTCL_ERROR\fR and calls \fBTcl_SetErrno\fR to store an appropriate POSIXerror code..SH TCL_SETCHANNELOPTION.PP\fBTcl_SetChannelOption\fR sets a new value for an option on \fIchannel\fR.\fIOptionName\fR is the option to set and \fInewValue\fR is the value toset.The procedure normally returns \fBTCL_OK\fR.  If an error occurs,it returns \fBTCL_ERROR\fR;  in addition, if \fIinterp\fR is non-NULL,\fBTcl_SetChannelOption\fR leaves an error message in \fIinterp->result\fR..SH TCL_EOF.PP\fBTcl_Eof\fR returns a nonzero value if \fIchannel\fR encounteredan end of file during the last input operation..SH TCL_INPUTBLOCKED.PP\fBTcl_InputBlocked\fR returns a nonzero value if \fIchannel\fR is innonblocking mode and the last input operation returned less data thanrequested because there was insufficient data available.The call always returns zero if the channel is in blocking mode..SH TCL_INPUTBUFFERED.PP\fBTcl_InputBuffered\fR returns the number of bytes of input currentlybuffered in the internal buffers for a channel. If the channel is not openfor reading, this function always returns zero..VS.SH "PLATFORM ISSUES".PPThe handles returned from \fBTcl_GetChannelHandle\fR depend on theplatform and the channel type.  On Unix platforms, the handle isalways a Unix file descriptor as returned from the \fBopen\fR systemcall.  On Windows platforms, the handle is a file \fBHANDLE\fR whenthe channel was created with \fBTcl_OpenFileChannel\fR,\fBTcl_OpenCommandChannel\fR, or \fBTcl_MakeFileChannel\fR.  Otherchannel types may return a different type of handle on Windowsplatforms.  On the Macintosh platform, the handle is a file referencenumber as returned from \fBHOpenDF\fR..VE.SH "SEE ALSO"DString(3), fconfigure(n), filename(n), fopen(2), Tcl_CreateChannel(3).SH KEYWORDSaccess point, blocking, buffered I/O, channel, channel driver, end of file,flush, input, nonblocking, output, read, seek, write

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -