Manual Pages for UNIX Darwin command on man Tcl_ChannelInputProc
MyWebUniversity

Manual Pages for UNIX Darwin command on man Tcl_ChannelInputProc

TclCreateChannel(3) Tcl Library Procedures TclCreateChannel(3)

NAME

TclCreateChannel, TclGetChannelInstanceData, TclGetChannelType, TclGetChannelName, TclGetChannelHandle, TclGetChannelMode, TclGetChannelBufferSize, TclSetChannelBufferSize, TclNotifyChannel,

TclBadChannelOption, TclChannelName, TclChannelVersion, TclChannel-

BlockModeProc, TclChannelCloseProc, TclChannelClose2Proc, TclChan-

nelInputProc, TclChannelOutputProc, TclChannelSeekProc, TclChannel-

WideSeekProc, TclChannelSetOptionProc, TclChannelGetOptionProc, TclChannelWatchProc, TclChannelGetHandleProc, TclChannelFlushProc, TclChannelHandlerProc, TclIsChannelShared, TclIsChannelRegistered, TclCutChannel, TclSpliceChannel, TclIsChannelExisting,

TclClearChannelHandlers, TclGetChannelThread, TclChannelBuffered -

procedures for creating and manipulating channels

SYNOPSIS

##iinncclluuddee <>

TclChannel TTccllCCrreeaatteeCChhaannnneell(typePtr, channelName, instanceData, mask) ClientData TTccllGGeettCChhaannnneellIInnssttaanncceeDDaattaa(channel) TclChannelType * TTccllGGeettCChhaannnneellTTyyppee(channel) CONST char * TTccllGGeettCChhaannnneellNNaammee(channel) int TTccllGGeettCChhaannnneellHHaannddllee(channel, direction, handlePtr) TclThreadId | TTccllGGeettCChhaannnneellTThhrreeaadd(channel) | int TTccllGGeettCChhaannnneellBBuuffffeerrSSiizzee(channel) TTccllSSeettCChhaannnneellBBuuffffeerrSSiizzee(channel, size) TTccllNNoottiiffyyCChhaannnneell(channel, mask) int TclBadChannelOptionitr, pinae otoLs) int | TTccllIIssCChhaannnneellSShhaarreedd(channel) | int | TTccllIIssCChhaannnneellRReeggiisstteerreedd(interp, channel) | int | TTccllIIssCChhaannnneellEExxiissttiinngg(channelName) | void | TTccllCCuuttCChhaannnneell(channel) | void | TTccllSSpplliicceeCChhaannnneell(channel) | void | TTccllCClleeaarrCChhaannnneellHHaannddlleerrss(channel) | int TTccllCChhaannnneellBBuuffffeerreedd(channel) CONST char * TTccllCChhaannnneellNNaammee(typePtr) TclChannelTypeVersion TTccllCChhaannnneellVVeerrssiioonn(typePtr) TclDriverBlockModeProc * TTccllCChhaannnneellBBlloocckkMMooddeePPrroocc(typePtr) TclDriverCloseProc * TTccllCChhaannnneellCClloosseePPrroocc(typePtr) TclDriverClose2Proc * TTccllCChhaannnneellCClloossee22PPrroocc(typePtr) TclDriverInputProc * TTccllCChhaannnneellIInnppuuttPPrroocc(typePtr) TclDriverOutputProc * TTccllCChhaannnneellOOuuttppuuttPPrroocc(typePtr) TclDriverSeekProc * TTccllCChhaannnneellSSeeeekkPPrroocc(typePtr) TclDriverWideSeekProc * | TTccllCChhaannnneellWWiiddeeSSeeeekkPPrroocc(typePtr) | TclDriverSetOptionProc * TclChannelSetOptionProctpPr TclDriverGetOptionProc * TclChannelGetOptionProctpPr TclDriverWatchProc * TTccllCChhaannnneellWWaattcchhPPrroocc(typePtr) TclDriverGetHandleProc * TTccllCChhaannnneellGGeettHHaannddlleePPrroocc(typePtr) TclDriverFlushProc * TTccllCChhaannnneellFFlluusshhPPrroocc(typePtr) TclDriverHandlerProc * TTccllCChhaannnneellHHaannddlleerrPPrroocc(typePtr) AARRGGUUMMEENNTTSS

TclChannelType *typePtr (in) Points to a structure con-

taining the addresses of procedures that can be called to perform I/O and

other functions on the chan-

nel. CONST char *channelName (in) The name of this channel, such as ffiillee33; must not be in use by any other channel. Can be NULL, in which case

the channel is created with-

out a name.

ClientData instanceData (in) Arbitrary one-word value to

be associated with this channel. This value is passed to procedures in typePtr when they are invoked.

int mask (in) OR-ed combination of

TTCCLLRREEAADDAABBLLEE and TTCCLLWWRRIITTAABBLLEE to indicate

whether a channel is read-

able and writable. TclChannel channel (in) The channel to operate on. int direction (in) TTCCLLRREEAADDAABBLLEE means the input handle is wanted;

TTCCLLWWRRIITTAABBLLEE means the out-

put handle is wanted. ClientData *handlePtr (out) Points to the location where

the desired OS-specific han-

dle should be stored. int size (in) The size, in bytes, of buffers to allocate in this channel.

int mask (in) An OR-ed combination of

TTCCLLRREEAADDAABBLLEE, TTCCLLWWRRIITTAABBLLEE

and TTCCLLEEXXCCEEPPTTIIOONN that indi-

cates events that have occurred on this channel. TclInterp *interp (in) Current interpreter. (can be NULL) CONST char *optionName (in) Name of the invalid option. CONST char *optionList (in) Specific options list (space separated words, without

"-") to append to the stan-

dard generic options list. Can be NULL for generic options error message only.

DESCRIPTION

Tcl uses a two-layered channel architecture. It provides a generic

upper layer to enable C and Tcl programs to perform input and output using the same APIs for a variety of files, devices, sockets etc. The

generic C APIs are described in the manual entry for TTccllOOppeennFFiilleeCChhaann-

nneell.

The lower layer provides type-specific channel drivers for each type of

device supported on each platform. This manual entry describes the C

APIs used to communicate between the generic layer and the type-spe-

cific channel drivers. It also explains how new types of channels can be added by providing new channel drivers. Channel drivers consist of a number of components: First, each channel driver provides a TTccllCChhaannnneellTTyyppee structure containing pointers to functions implementing the various operations used by the generic layer to communicate with the channel driver. The TTccllCChhaannnneellTTyyppee structure and the functions referenced by it are described in the section TCLCHANNELTYPE, below. Second, channel drivers usually provide a Tcl command to create instances of that type of channel. For example, the Tcl ooppeenn command creates channels that use the file and command channel drivers, and the Tcl ssoocckkeett command creates channels that use TCP sockets for network communication.

Third, a channel driver optionally provides a C function to open chan-

nel instances of that type. For example, TTccllOOppeennFFiilleeCChhaannnneell opens a channel that uses the file channel driver, and TTccllOOppeennTTccppCClliieenntt opens a channel that uses the TCP network protocol. These creation functions typically use TTccllCCrreeaatteeCChhaannnneell internally to open the channel.

To add a new type of channel you must implement a C API or a Tcl com-

mand that opens a channel by invoking TTccllCCrreeaatteeCChhaannnneell. When your driver calls TTccllCCrreeaatteeCChhaannnneell it passes in a TTccllCChhaannnneellTTyyppee structure describing the driver's I/O procedures. The generic layer will then invoke the functions referenced in that structure to perform operations on the channel.

TTccllCCrreeaatteeCChhaannnneell opens a new channel and associates the supplied type-

Ptr and instanceData with it. The channel is opened in the mode indi-

cated by mask. For a discussion of channel drivers, their operations and the TTccllCChhaannnneellTTyyppee structure, see the section TCLCHANNELTYPE, below.

TTccllCCrreeaatteeCChhaannnneell interacts with the code managing the standard chan-

nels. Once a standard channel was initialized either through a call to TTccllGGeettSSttddCChhaannnneell or a call to TTccllSSeettSSttddCChhaannnneell closing this standard channel will cause the next call to TTccllCCrreeaatteeCChhaannnneell to make the new channel the new standard channel too. See TTccllSSttaannddaarrddCChhaannnneellss for a general treatise about standard channels and the behaviour of the Tcl library with regard to them. TTccllGGeettCChhaannnneellIInnssttaanncceeDDaattaa returns the instance data associated with the channel in channel. This is the same as the instanceData argument in the call to TTccllCCrreeaatteeCChhaannnneell that created this channel. TTccllGGeettCChhaannnneellTTyyppee returns a pointer to the TTccllCChhaannnneellTTyyppee structure used by the channel in the channel argument. This is the same as the typePtr argument in the call to TTccllCCrreeaatteeCChhaannnneell that created this channel. TTccllGGeettCChhaannnneellNNaammee returns a string containing the name associated with the channel, or NULL if the channelName argument to TTccllCCrreeaatteeCChhaannnneell was NULL.

TTccllGGeettCChhaannnneellHHaannddllee places the OS-specific device handle associated

with channel for the given direction in the location specified by han-

dlePtr and returns TTCCLLOOKK. If the channel does not have a device han-

dle for the specified direction, then TTCCLLEERRRROORR is returned instead. Different channel drivers will return different types of handle. Refer to the manual entries for each driver to determine what type of handle is returned. | TTccllGGeettCChhaannnneellTThhrreeaadd returns the id of the thread currently managing | the specified channel. This allows channel drivers to send their file |

events to the correct event queue even for a multi-threaded core.

TTccllGGeettCChhaannnneellMMooddee returns an OR-ed combination of TTCCLLRREEAADDAABBLLEE and

TTCCLLWWRRIITTAABBLLEE, indicating whether the channel is open for input and out-

put.

TTccllGGeettCChhaannnneellBBuuffffeerrSSiizzee returns the size, in bytes, of buffers allo-

cated to store input or output in channel. If the value was not set by a previous call to TTccllSSeettCChhaannnneellBBuuffffeerrSSiizzee, described below, then the default value of 4096 is returned. TTccllSSeettCChhaannnneellBBuuffffeerrSSiizzee sets the size, in bytes, of buffers that will be allocated in subsequent operations on the channel to store input or

output. The size argument should be between ten and one million, allow-

ing buffers of ten bytes to one million bytes. If size is outside this range, TTccllSSeettCChhaannnneellBBuuffffeerrSSiizzee sets the buffer size to 4096. TTccllNNoottiiffyyCChhaannnneell is called by a channel driver to indicate to the generic layer that the events specified by mask have occurred on the channel. Channel drivers are responsible for invoking this function whenever the channel handlers need to be called for the channel. See WWAATTCCHHPPRROOCC below for more details. TclBadChannelOption s ald rm rvr pcfc e o gt pin procs to generate a complete error message. TTccllCChhaannnneellBBuuffffeerreedd returns the number of bytes of input currently buffered in the internal buffer (push back area) of the channel itself. It does not report about the data in the overall buffers for the stack of channels the supplied channel is part of. TTccllIIssCChhaannnneellSShhaarreedd checks the refcount of the specified channel and | returns whether the channel was shared among multiple interpreters | (result == 1) or not (result == 0). |

TTccllIIssCChhaannnneellRReeggiisstteerreedd checks whether the specified channel is regis- |

tered in the given interpreter (result == 1) or not (result == 0). | TTccllIIssCChhaannnneellEExxiissttiinngg checks whether a channel with the specified name |

is registered in the (thread)-global list of all channels (result == 1) |

or not (result == 0). | TTccllCCuuttCChhaannnneell removes the specified channel from the (thread)global | list of all channels (of the current thread). Application to a channel | still registered in some interpreter is not allowed. | TTccllSSpplliicceeCChhaannnneell adds the specified channel to the (thread)global list |

of all channels (of the current thread). Application to a channel reg- |

istered in some interpreter is not allowed. | TTccllCClleeaarrCChhaannnneellHHaannddlleerrss removes all channelhandlers and event scripts | associated with the specified channel, thus shutting down all event | processing for this channel. TTCCLLCCHHAANNNNEELLTTYYPPEE A channel driver provides a TTccllCChhaannnneellTTyyppee structure that contains

pointers to functions that implement the various operations on a chan-

nel; these operations are invoked as needed by the generic layer. The structure was versioned starting in Tcl 8.3.2/8.4 to correct a problem with stacked channel drivers. See the OOLLDD CCHHAANNNNEELL TTYYPPEESS section below for details about the old structure. The TTccllCChhaannnneellTTyyppee structure contains the following fields: typedef struct TclChannelType { char *typeName; TclChannelTypeVersion version; TclDriverCloseProc *closeProc; TclDriverInputProc *inputProc; TclDriverOutputProc *outputProc; TclDriverSeekProc *seekProc; TclDriverSetOptionProc *setOptionProc; TclDriverGetOptionProc *getOptionProc; TclDriverWatchProc *watchProc; TclDriverGetHandleProc *getHandleProc; TclDriverClose2Proc *close2Proc; TclDriverBlockModeProc *blockModeProc; TclDriverFlushProc *flushProc; TclDriverHandlerProc *handlerProc; TclDriverWideSeekProc *wideSeekProc; } TclChannelType;

The driver must provide implementations for all functions except block-

ModeProc, seekProc, setOptionProc, getOptionProc, and close2Proc, which may be specified as NULL. Other functions that can not be implemented for this type of device should return EEIINNVVAALL when invoked to indicate

that they are not implemented, except in the case of flushProc and han-

dlerProc, which should specified as NULL if not otherwise defined. The user should only use the above structure for TTccllCChhaannnneellTTyyppee instantiation. When referencing fields in a TTccllCChhaannnneellTTyyppee structure,

the following functions should be used to obtain the values: TTccllCChhaann-

nneellNNaammee, TTccllCChhaannnneellVVeerrssiioonn, TTccllCChhaannnneellBBlloocckkMMooddeePPrroocc, TTccllCChhaannnneell-

CClloosseePPrroocc, TTccllCChhaannnneellCClloossee22PPrroocc, TTccllCChhaannnneellIInnppuuttPPrroocc, TTccllCChhaannnneellOOuutt-

ppuuttPPrroocc, TTccllCChhaannnneellSSeeeekkPPrroocc, TTccllCChhaannnneellWWiiddeeSSeeeekkPPrroocc, TTccllCChhaannnneellSSee- |

tOptionProc TclChannelGetOptionProc, TclChannelWatchProc TclChan-

nneellGGeettHHaannddlleePPrroocc, TTccllCChhaannnneellFFlluusshhPPrroocc, or TTccllCChhaannnneellHHaannddlleerrPPrroocc.

The change to the structures was made in such a way that standard chan-

nel types are binary compatible. However, channel types that use stacked channels (ie: TLS, Trf) have new versions to correspond to the above change since the previous code for stacked channels had problems.

TYPENAME

The typeName field contains a null-terminated string that identifies

the type of the device implemented by this driver, e.g. ffiillee or ssoocckkeett. This value can be retrieved with TTccllCChhaannnneellNNaammee, which returns a pointer to the string. VVEERRSSIIOONN The version field should be set to TTCCLLCCHHAANNNNEELLVVEERRSSIIOONN22. If it is not set to this value TTCCLLCCHHAANNNNEELLVVEERRSSIIOONN33, then this TTccllCChhaannnneellTTyyppee is assumed to have the older structure. See OOLLDD CCHHAANNNNEELL TTYYPPEESS for more details. While Tcl will recognize and function with either structure, stacked channels must be of at least TTCCLLCCHHAANNNNEELLVVEERRSSIIOONN22 to function correctly. This value can be retrieved with TTccllCChhaannnneellVVeerrssiioonn, which returns one |

of TTCCLLCCHHAANNNNEELLVVEERRSSIIOONN33, TTCCLLCCHHAANNNNEELLVVEERRSSIIOONN22 or TTCCLLCCHHAANNNNEELLVVEERR-

SSIIOONN11. BBLLOOCCKKMMOODDEEPPRROOCC The blockModeProc field contains the address of a function called by the generic layer to set blocking and nonblocking mode on the device. BlockModeProc should match the following prototype: typedef int TclDriverBlockModeProc( ClientData instanceData, int mode); The instanceData is the same as the value passed to TTccllCCrreeaatteeCChhaannnneell when this channel was created. The mode argument is either

TTCCLLMMOODDEEBBLLOOCCKKIINNGG or TTCCLLMMOODDEENNOONNBBLLOOCCKKIINNGG to set the device into block-

ing or nonblocking mode. The function should return zero if the opera-

tion was successful, or a nonzero POSIX error code if the operation failed. If the operation is successful, the function can modify the supplied instanceData to record that the channel entered blocking or nonblocking mode and to implement the blocking or nonblocking behavior. For some device types, the blocking and nonblocking behavior can be implemented

by the underlying operating system; for other device types, the behav-

ior must be emulated in the channel driver. This value can be retrieved with TTccllCChhaannnneellBBlloocckkMMooddeePPrroocc, which returns a pointer to the function. A channel driver nnoott supplying a blockModeProc has to be very, very careful. It has to tell the generic layer exactly which blocking mode is acceptable to it, and should this also document for the user so that the blocking mode of the channel is not changed to an inacceptable value. Any confusion here may lead the interpreter into a (spurious and difficult to find) deadlock. CCLLOOSSEEPPRROOCC AANNDD CCLLOOSSEE22PPRROOCC The closeProc field contains the address of a function called by the

generic layer to clean up driver-related information when the channel

is closed. CloseProc must match the following prototype: typedef int TclDriverCloseProc( ClientData instanceData, TclInterp *interp);

The instanceData argument is the same as the value provided to TTccllCCrree-

aatteeCChhaannnneell when the channel was created. The function should release any storage maintained by the channel driver for this channel, and close the input and output devices encapsulated by this channel. All queued output will have been flushed to the device before this function is called, and no further driver operations will be invoked on this

instance after calling the closeProc. If the close operation is suc-

cessful, the procedure should return zero; otherwise it should return a nonzero POSIX error code. In addition, if an error occurs and interp is

not NULL, the procedure should store an error message in the inter-

preter's result. Alternatively, channels that support closing the read and write sides independently may set closeProc to TTCCLLCCLLOOSSEE22PPRROOCC and set close2Proc to the address of a function that matches the following prototype: typedef int TclDriverClose2Proc( ClientData instanceData, TclInterp *interp, int flags); The close2Proc will be called with flags set to an OR'ed combination of TTCCLLCCLLOOSSEERREEAADD or TTCCLLCCLLOOSSEEWWRRIITTEE to indicate that the driver should close the read and/or write side of the channel. The channel driver may be invoked to perform additional operations on the channel after close2Proc is called to close one or both sides of the channel. If flags is 00 (zero), the driver should close the channel in the manner described above for closeProc. No further operations will be invoked on this instance after close2Proc is called with all flags cleared. In all cases, the close2Proc function should return zero if the close operation was successful; otherwise it should return a nonzero POSIX error code. In addition, if an error occurs and interp is not NULL, the procedure should store an error message in the interpreter's result.

These value can be retrieved with TTccllCChhaannnneellCClloosseePPrroocc or TTccllCChhaannnneell-

CClloossee22PPrroocc, which returns a pointer to the respective function. IINNPPUUTTPPRROOCC The inputProc field contains the address of a function called by the generic layer to read data from the file or device and store it in an internal buffer. InputProc must match the following prototype: typedef int TclDriverInputProc( ClientData instanceData, char *buf, int bufSize, int *errorCodePtr); InstanceData is the same as the value passed to TTccllCCrreeaatteeCChhaannnneell when the channel was created. The buf argument points to an array of bytes

in which to store input from the device, and the bufSize argument indi-

cates how many bytes are available at buf. The errorCodePtr argument points to an integer variable provided by the generic layer. If an error occurs, the function should set the variable to a POSIX error code that identifies the error that occurred. The function should read data from the input device encapsulated by the channel and store it at buf. On success, the function should return a nonnegative integer indicating how many bytes were read from the input

device and stored at buf. On error, the function should return -1. If

an error occurs after some data has been read from the device, that data is lost.

If inputProc can determine that the input device has some data avail-

able but less than requested by the bufSize argument, the function should only attempt to read as much data as is available and return without blocking. If the input device has no data available whatsoever and the channel is in nonblocking mode, the function should return an EEAAGGAAIINN error. If the input device has no data available whatsoever and the channel is in blocking mode, the function should block for the shortest possible time until at least one byte of data can be read from the device; then, it should return as much data as it can read without blocking. This value can be retrieved with TTccllCChhaannnneellIInnppuuttPPrroocc, which returns a pointer to the function. OOUUTTPPUUTTPPRROOCC The outputProc field contains the address of a function called by the generic layer to transfer data from an internal buffer to the output device. OutputProc must match the following prototype: typedef int TclDriverOutputProc( ClientData instanceData, CONST char *buf, int toWrite, int *errorCodePtr); InstanceData is the same as the value passed to TTccllCCrreeaatteeCChhaannnneell when the channel was created. The buf argument contains an array of bytes to be written to the device, and the toWrite argument indicates how many bytes are to be written from the buf argument. The errorCodePtr argument points to an integer variable provided by the

generic layer. If an error occurs, the function should set this vari-

able to a POSIX error code that identifies the error.

The function should write the data at buf to the output device encapsu-

lated by the channel. On success, the function should return a nonnega-

tive integer indicating how many bytes were written to the output device. The return value is normally the same as toWrite, but may be less in some cases such as if the output operation is interrupted by a

signal. If an error occurs the function should return -1. In case of

error, some data may have been written to the device. If the channel is nonblocking and the output device is unable to absorb

any data whatsoever, the function should return -1 with an EEAAGGAAIINN error

without writing any data. This value can be retrieved with TTccllCChhaannnneellOOuuttppuuttPPrroocc, which returns a pointer to the function. SSEEEEKKPPRROOCC AANNDD WWIIDDEESSEEEEKKPPRROOCC The seekProc field contains the address of a function called by the generic layer to move the access point at which subsequent input or output operations will be applied. SeekProc must match the following prototype: typedef int TclDriverSeekProc( ClientData instanceData, long offset, int seekMode, int *errorCodePtr);

The instanceData argument is the same as the value given to TTccllCCrreeaattee-

CChhaannnneell when this channel was created. Offset and seekMode have the same meaning as for the TTccllSSeeeekk procedure (described in the manual entry for TTccllOOppeennFFiilleeCChhaannnneell). The errorCodePtr argument points to an integer variable provided by the

generic layer for returning eerrrrnnoo values from the function. The func-

tion should set this variable to a POSIX error code if an error occurs. The function should store an EEIINNVVAALL error code if the channel type does not implement seeking.

The return value is the new access point or -1 in case of error. If an

error occurred, the function should not move the access point.

If there is a non-NULL seekProc field, the wideSeekProc field may con- |

tain the address of an alternative function to use which handles wide |

(i.e. larger than 32-bit) offsets, so allowing seeks within files |

larger than 2GB. The wideSeekProc will be called in preference to the | seekProc, but both must be defined if the wideSeekProc is defined. | WideSeekProc must match the following prototype: | typedef TclWideInt TclDriverWideSeekProc( | ClientData instanceData, | TclWideInt offset, | int seekMode, | int *errorCodePtr); | The arguments and return values mean the same thing as with seekProc |

above, except that the type of offsets and the return type are differ- |

ent. | The seekProc value can be retrieved with TTccllCChhaannnneellSSeeeekkPPrroocc, which | returns a pointer to the function, and similarly the wideSeekProc can | be retrieved with TTccllCChhaannnneellWWiiddeeSSeeeekkPPrroocc. SSEETTOOPPTTIIOONNPPRROOCC The setOptionProc field contains the address of a function called by the generic layer to set a channel type specific option on a channel. setOptionProc must match the following prototype: typedef int TclDriverSetOptionProc( ClientData instanceData, TclInterp *interp, CONST char *optionName, CONST char *newValue); optionName is the name of an option to set, and newValue is the new value for that option, as a string. The instanceData is the same as the value given to TTccllCCrreeaatteeCChhaannnneell when this channel was created. The function should do whatever channel type specific action is required to implement the new value of the option. Some options are handled by the generic code and this function is never

called to set them, e.g. -bblloocckkmmooddee. Other options are specific to each

channel type and the setOptionProc procedure of the channel driver will get called to implement them. The setOptionProc field can be NULL, which indicates that this channel type supports no type specific options. If the option value is successfully modified to the new value, the ucin eun TCLOK. t hud al TclBadChannelOption hc

itself returns TTCCLLEERRRROORR if the optionName is unrecognized. If new-

Value specifies a value for the option that is not supported or if a system call error occurs, the function should leave an error message in the result field of interp if interp is not NULL. The function should also call TTccllSSeettEErrrrnnoo to store an appropriate POSIX error code. hs au cn e eree wt TclChannelSetOptionProc, hc returns a pointer to the function. GGEETTOOPPTTIIOONNPPRROOCC The getOptionProc field contains the address of a function called by the generic layer to get the value of a channel type specific option on a channel. getOptionProc must match the following prototype: typedef int TclDriverGetOptionProc( ClientData instanceData, TclInterp *interp, CONST char *optionName, TclDString *optionValue); OptionName is the name of an option supported by this type of channel. If the option name is not NULL, the function stores its current value, as a string, in the Tcl dynamic string optionValue. If optionName is NULL, the function stores in optionValue an alternating list of all supported options and their current values. On success, the function eun TCLOK. t hud al TclBadChannelOption hc isl returns TTCCLLEERRRROORR if the optionName is unrecognized. If a system call error occurs, the function should leave an error message in the result of interp if interp is not NULL. The function should also call TTccllSSeettEErrrrnnoo to store an appropriate POSIX error code. Some options are handled by the generic code and this function is never

called to retrieve their value, e.g. -bblloocckkmmooddee. Other options are spe-

cific to each channel type and the getOptionProc procedure of the chan-

nel driver will get called to implement them. The getOptionProc field can be NULL, which indicates that this channel type supports no type specific options. hs au cn e eree wt TclChannelGetOptionProc, hc returns a pointer to the function. WWAATTCCHHPPRROOCC The watchProc field contains the address of a function called by the generic layer to initialize the event notification mechanism to notice

events of interest on this channel. WatchProc should match the follow-

ing prototype: typedef void TclDriverWatchProc( ClientData instanceData, int mask); The instanceData is the same as the value passed to TTccllCCrreeaatteeCChhaannnneell

when this channel was created. The mask argument is an OR-ed combina-

tion of TTCCLLRREEAADDAABBLLEE, TTCCLLWWRRIITTAABBLLEE and TTCCLLEEXXCCEEPPTTIIOONN; it indicates events the caller is interested in noticing on this channel. The function should initialize device type specific mechanisms to notice when an event of interest is present on the channel. When one or more of the designated events occurs on the channel, the channel driver is responsible for calling TTccllNNoottiiffyyCChhaannnneell to inform the generic channel module. The driver should take care not to starve

other channel drivers or sources of callbacks by invoking TclNotify-

Channel too frequently. Fairness can be insured by using the Tcl event queue to allow the channel event to be scheduled in sequence with other events. See the description of TTccllQQuueeuueeEEvveenntt for details on how to queue an event. This value can be retrieved with TTccllCChhaannnneellWWaattcchhPPrroocc, which returns a pointer to the function. GGEETTHHAANNDDLLEEPPRROOCC The getHandleProc field contains the address of a function called by

the generic layer to retrieve a device-specific handle from the chan-

nel. GetHandleProc should match the following prototype: typedef int TclDriverGetHandleProc( ClientData instanceData, int direction, ClientData *handlePtr); InstanceData is the same as the value passed to TTccllCCrreeaatteeCChhaannnneell when this channel was created. The direction argument is either TTCCLLRREEAADDAABBLLEE to retrieve the handle used for input, or TTCCLLWWRRIITTAABBLLEE to retrieve the handle used for output.

If the channel implementation has device-specific handles, the function

should retrieve the appropriate handle associated with the channel, according the direction argument. The handle should be stored in the location referred to by handlePtr, and TTCCLLOOKK should be returned. If the channel is not open for the specified direction, or if the channel implementation does not use device handles, the function should return TTCCLLEERRRROORR. This value can be retrieved with TTccllCChhaannnneellGGeettHHaannddlleePPrroocc, which returns a pointer to the function. FFLLUUSSHHPPRROOCC The flushProc field is currently reserved for future use. It should be set to NULL. FlushProc should match the following prototype: typedef int TclDriverFlushProc( ClientData instanceData); This value can be retrieved with TTccllCChhaannnneellFFlluusshhPPrroocc, which returns a pointer to the function. HHAANNDDLLEERRPPRROOCC The handlerProc field contains the address of a function called by the generic layer to notify the channel that an event occurred. It should be defined for stacked channel drivers that wish to be notified of events that occur on the underlying (stacked) channel. HandlerProc should match the following prototype: typedef int TclDriverHandlerProc( ClientData instanceData, int interestMask); InstanceData is the same as the value passed to TTccllCCrreeaatteeCChhaannnneell when

this channel was created. The interestMask is an OR-ed combination of

TTCCLLRREEAADDAABBLLEE or TTCCLLWWRRIITTAABBLLEE; it indicates what type of event occurred on this channel. This value can be retrieved with TTccllCChhaannnneellHHaannddlleerrPPrroocc, which returns a pointer to the function. TTCCLLBBAADDCCHHAANNNNEELLOOPPTTIIOONN This procedure generates a "bad option" error message in an (optional) interpreter. It is used by channel drivers when a invalid Set/Get option is requested. Its purpose is to concatenate the generic options

list to the specific ones and factorize the generic options error mes-

sage string. It always return TTCCLLEERRRROORR An error message is generated in interp's result object to indicate that a command was invoked with the a bad option The message has the form bad option "blah": should be one of <...generic options...>+<...specific options...> so you get for instance:

bad option "-blah": should be one of -blocking,

-buffering, -buffersize, -eofchar, -translation,

-peername, or -sockname

when called with optionList="peername sockname" ``blah'' is the optionName argument and ``'' is a space separated list of specific option words. The function takes good care of inserting minus signs before each option, commas after, and an ``or'' before the last option. OOLLDD CCHHAANNNNEELL TTYYPPEESS The original (8.3.1 and below) TTccllCChhaannnneellTTyyppee structure contains the following fields: typedef struct TclChannelType { char *typeName; TclDriverBlockModeProc *blockModeProc; TclDriverCloseProc *closeProc; TclDriverInputProc *inputProc; TclDriverOutputProc *outputProc; TclDriverSeekProc *seekProc; TclDriverSetOptionProc *setOptionProc; TclDriverGetOptionProc *getOptionProc; TclDriverWatchProc *watchProc; TclDriverGetHandleProc *getHandleProc; TclDriverClose2Proc *close2Proc; } TclChannelType; It is still possible to create channel with the above structure. The internal channel code will determine the version. It is imperative to use the new TTccllCChhaannnneellTTyyppee structure if you are creating a stacked

channel driver, due to problems with the earlier stacked channel imple-

mentation (in 8.2.0 to 8.3.1). Prior to 8.4.0 (i.e. during the later releases of 8.3 and early part of | the 8.4 development cycle) the TTccllCChhaannnneellTTyyppee structure contained the | following fields: | typedef struct TclChannelType { | char *typeName; | TclChannelTypeVersion version; | TclDriverCloseProc *closeProc; | TclDriverInputProc *inputProc; | TclDriverOutputProc *outputProc; | TclDriverSeekProc *seekProc; | TclDriverSetOptionProc *setOptionProc; | TclDriverGetOptionProc *getOptionProc; | TclDriverWatchProc *watchProc; | TclDriverGetHandleProc *getHandleProc; | TclDriverClose2Proc *close2Proc; | TclDriverBlockModeProc *blockModeProc; | TclDriverFlushProc *flushProc; | TclDriverHandlerProc *handlerProc; | } TclChannelType; | When the above structure is registered as a channel type, the version | field should always be TTCCLLCCHHAANNNNEELLVVEERRSSIIOONN22.

SEE ALSO

TclClose(3), TclOpenFileChannel(3), TclSetErrno(3), TclQueueEvent(3), TclStackChannel(3), TclGetStdChannel(3) KKEEYYWWOORRDDSS

blocking, channel driver, channel registration, channel type, nonblock-

ing Tcl 8.3 TclCreateChannel(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™