Seth Woolley's Man Viewer

Tcl_GetChannelHandle(3) - Tcl_BadChannelOption, Tcl_ChannelBlockModeProc, Tcl_ChannelBuffered, Tcl_ChannelClose2Proc, Tcl_ChannelCloseProc, Tcl_ChannelFlushProc, Tcl_ChannelGetHandleProc, Tcl_ChannelGetOptionProc, Tcl_ChannelHandlerProc, Tcl_ChannelInputProc, Tcl_ChannelName, Tcl_ChannelOutputProc, Tcl_ChannelSeekProc, Tcl_ChannelSetOptionProc, Tcl_ChannelVersion, Tcl_ChannelWatchProc, Tcl_ChannelWideSeekProc, Tcl_ClearChannelHandlers, Tcl_CreateChannel, Tcl_CutChannel, Tcl_GetChannelBufferSize, Tcl_GetChannelHandle, Tcl_GetChannelInstanceData, Tcl_GetChannelMode, Tcl_GetChannelName, Tcl_GetChannelThread, Tcl_GetChannelType, Tcl_IsChannelExisting, Tcl_IsChannelRegistered, Tcl_IsChannelShared, Tcl_NotifyChannel, Tcl_SetChannelBufferSize, Tcl_SpliceChannel - procedures for creating and manipulating channels - man 3 Tcl_GetChannelHandle

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

Tcl_CreateChannel(3)        Tcl Library Procedures        Tcl_CreateChannel(3)



______________________________________________________________________________

NAME
       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_Channel-
       BlockModeProc,  Tcl_ChannelCloseProc,  Tcl_ChannelClose2Proc, Tcl_Chan-
       nelInputProc, Tcl_ChannelOutputProc, Tcl_ChannelSeekProc,  Tcl_Channel-
       WideSeekProc,    Tcl_ChannelSetOptionProc,    Tcl_ChannelGetOptionProc,
       Tcl_ChannelWatchProc,  Tcl_ChannelGetHandleProc,  Tcl_ChannelFlushProc,
       Tcl_ChannelHandlerProc,  Tcl_IsChannelShared,  Tcl_IsChannelRegistered,
       Tcl_CutChannel,        Tcl_SpliceChannel,        Tcl_IsChannelExisting,
       Tcl_ClearChannelHandlers,  Tcl_GetChannelThread,  Tcl_ChannelBuffered -
       procedures for creating and manipulating channels

SYNOPSIS
       #include <tcl.h>

       Tcl_Channel
       Tcl_CreateChannel(typePtr, channelName, instanceData, mask)

       ClientData
       Tcl_GetChannelInstanceData(channel)

       Tcl_ChannelType *
       Tcl_GetChannelType(channel)

       CONST char *
       Tcl_GetChannelName(channel)

       int
       Tcl_GetChannelHandle(channel, direction, handlePtr)

       Tcl_ThreadId                                                            |
       Tcl_GetChannelThread(channel)                                           |

       int
       Tcl_GetChannelBufferSize(channel)

       Tcl_SetChannelBufferSize(channel, size)

       Tcl_NotifyChannel(channel, mask)

       int
       Tcl_BadChannelOption(interp, optionName, optionList)

       int                                                                     |
       Tcl_IsChannelShared(channel)                                            |

       int                                                                     |
       Tcl_IsChannelRegistered(interp, channel)                                |

       int                                                                     |
       Tcl_IsChannelExisting(channelName)                                      |

       void                                                                    |
       Tcl_CutChannel(channel)                                                 |

       void                                                                    |
       Tcl_SpliceChannel(channel)                                              |

       void                                                                    |
       Tcl_ClearChannelHandlers(channel)                                       |

       int
       Tcl_ChannelBuffered(channel)

       CONST char *
       Tcl_ChannelName(typePtr)

       Tcl_ChannelTypeVersion
       Tcl_ChannelVersion(typePtr)

       Tcl_DriverBlockModeProc *
       Tcl_ChannelBlockModeProc(typePtr)

       Tcl_DriverCloseProc *
       Tcl_ChannelCloseProc(typePtr)

       Tcl_DriverClose2Proc *
       Tcl_ChannelClose2Proc(typePtr)

       Tcl_DriverInputProc *
       Tcl_ChannelInputProc(typePtr)

       Tcl_DriverOutputProc *
       Tcl_ChannelOutputProc(typePtr)

       Tcl_DriverSeekProc *
       Tcl_ChannelSeekProc(typePtr)

       Tcl_DriverWideSeekProc *                                                |
       Tcl_ChannelWideSeekProc(typePtr)                                        |

       Tcl_DriverSetOptionProc *
       Tcl_ChannelSetOptionProc(typePtr)

       Tcl_DriverGetOptionProc *
       Tcl_ChannelGetOptionProc(typePtr)

       Tcl_DriverWatchProc *
       Tcl_ChannelWatchProc(typePtr)

       Tcl_DriverGetHandleProc *
       Tcl_ChannelGetHandleProc(typePtr)

       Tcl_DriverFlushProc *
       Tcl_ChannelFlushProc(typePtr)

       Tcl_DriverHandlerProc *
       Tcl_ChannelHandlerProc(typePtr)


ARGUMENTS
       Tcl_ChannelType   *typePtr       (in(1,8))      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(1,8))      The  name  of  this channel,
                                                  such as file3; must  not  be
                                                  in(1,8) use by any other channel.
                                                  Can be NULL, in(1,8)  which  case
                                                  the channel is created with-
                                                  out a name.

       ClientData        instanceData   (in(1,8))      Arbitrary one-word value  to
                                                  be   associated   with  this
                                                  channel.   This   value   is
                                                  passed   to   procedures  in(1,8)
                                                  typePtr   when   they    are
                                                  invoked.

       int               mask           (in(1,8))      OR-ed     combination     of
                                                  TCL_READABLE             and
                                                  TCL_WRITABLE   to   indicate
                                                  whether a channel  is  read-
                                                  able and writable.

       Tcl_Channel       channel        (in(1,8))      The channel to operate on.

       int               direction      (in(1,8))      TCL_READABLE means the input
                                                  handle      is       wanted;
                                                  TCL_WRITABLE  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(1,8))      The  size,  in(1,8)   bytes,   of
                                                  buffers  to allocate in(1,8) this
                                                  channel.

       int               mask           (in(1,8))      An  OR-ed   combination   of
                                                  TCL_READABLE,   TCL_WRITABLE
                                                  and TCL_EXCEPTION that indi-
                                                  cates   events   that   have
                                                  occurred on this channel.

       Tcl_Interp        *interp        (in(1,8))      Current interpreter. (can be
                                                  NULL)

       CONST char        *optionName    (in(1,8))      Name  of the invalid option.

       CONST char        *optionList    (in(1,8))      Specific options list (space
                                                  separated   words,   without
                                                  "-") to append to the  stan-
                                                  dard  generic  options list.
                                                  Can  be  NULL  for   generic
                                                  options  error(8,n) 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(1,8) the manual entry for Tcl_OpenFileChan-
       nel.

       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  Tcl_ChannelType  structure  containing pointers to
       functions implementing the various operations used by the generic layer
       to  communicate  with the channel driver. The Tcl_ChannelType structure
       and the functions  referenced  by  it  are  described  in(1,8)  the  section
       TCL_CHANNELTYPE, below.

       Second,  channel  drivers  usually  provide  a  Tcl  command  to create
       instances of that type of channel. For example, the  Tcl  open(2,3,n)  command
       creates channels that use the file(1,n) and command channel drivers, and the
       Tcl socket(2,7,n) command creates channels that use TCP  sockets  for  network
       communication.

       Third,  a channel driver optionally provides a C function to open(2,3,n) chan-
       nel instances of that type. For example,  Tcl_OpenFileChannel  opens  a
       channel  that uses the file(1,n) channel driver, and Tcl_OpenTcpClient opens
       a channel that uses the TCP network protocol.  These creation functions
       typically use Tcl_CreateChannel internally to open(2,3,n) 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  Tcl_CreateChannel.   When  your
       driver calls Tcl_CreateChannel it passes in(1,8) a Tcl_ChannelType structure
       describing the driver's I/O procedures.  The generic  layer  will  then
       invoke the functions referenced in(1,8) that structure to perform operations
       on the channel.

       Tcl_CreateChannel opens a new channel and associates the supplied type-
       Ptr  and  instanceData with it. The channel is opened in(1,8) the mode indi-
       cated by mask.  For a discussion of channel drivers,  their  operations
       and  the  Tcl_ChannelType  structure,  see the section TCL_CHANNELTYPE,
       below.

       Tcl_CreateChannel interacts with the code managing the  standard  chan-
       nels.  Once a standard channel was initialized either through a call to
       Tcl_GetStdChannel or a call to Tcl_SetStdChannel closing this  standard
       channel  will  cause the next call to Tcl_CreateChannel to make the new
       channel the new standard channel too. See  Tcl_StandardChannels  for  a
       general  treatise  about standard channels and the behaviour of the Tcl
       library with regard to them.

       Tcl_GetChannelInstanceData returns the instance  data  associated  with
       the  channel  in(1,8) channel. This is the same as the instanceData argument
       in(1,8) the call to Tcl_CreateChannel that created this channel.

       Tcl_GetChannelType returns a pointer to the  Tcl_ChannelType  structure
       used  by  the  channel in(1,8) the channel argument. This is the same as the
       typePtr argument in(1,8) the call to  Tcl_CreateChannel  that  created  this
       channel.

       Tcl_GetChannelName returns a string(3,n) containing the name associated with
       the channel, or NULL if(3,n) the channelName argument  to  Tcl_CreateChannel
       was NULL.

       Tcl_GetChannelHandle  places  the  OS-specific device handle associated
       with channel for the given direction in(1,8) the location specified by  han-
       dlePtr  and returns TCL_OK.  If the channel does not have a device han-
       dle for the specified direction, then TCL_ERROR  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.                                                            |

       Tcl_GetChannelThread  returns  the  id of the thread currently managing |
       the specified channel. This allows channel drivers to send(2,n)  their  file(1,n) |
       events to the correct event queue(1,3) even for a multi-threaded core.

       Tcl_GetChannelMode  returns  an  OR-ed  combination of TCL_READABLE and
       TCL_WRITABLE, indicating whether the channel is open(2,3,n) for input and out-
       put.

       Tcl_GetChannelBufferSize  returns  the size, in(1,8) bytes, of buffers allo-
       cated to store input or output in(1,8) channel. If the value was not set(7,n,1 builtins)  by
       a  previous call to Tcl_SetChannelBufferSize, described below, then the
       default value of 4096 is returned.

       Tcl_SetChannelBufferSize sets the size, in(1,8) bytes, of buffers that  will
       be  allocated in(1,8) 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, Tcl_SetChannelBufferSize sets the buffer size to 4096.

       Tcl_NotifyChannel 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
       WATCHPROC below for more details.

       Tcl_BadChannelOption is called from driver specific set(7,n,1 builtins) or  get  option
       procs to generate a complete error(8,n) message.

       Tcl_ChannelBuffered  returns  the  number  of  bytes of input currently
       buffered in(1,8) the internal buffer (push back area) of the channel itself.
       It  does not report about the data in(1,8) the overall buffers for the stack
       of channels the supplied channel is part of.

       Tcl_IsChannelShared checks the refcount of the  specified  channel  and |
       returns  whether  the  channel  was  shared among multiple interpreters |
       (result == 1) or not (result == 0).                                     |

       Tcl_IsChannelRegistered checks whether the specified channel is  regis- |
       tered in(1,8) the given interpreter (result == 1) or not (result == 0).      |

       Tcl_IsChannelExisting  checks whether a channel with the specified name |
       is registered in(1,8) the (thread)-global list of all channels (result == 1) |
       or not (result == 0).                                                   |

       Tcl_CutChannel  removes  the  specified channel from the (thread)global |
       list of all channels (of the current thread).  Application to a channel |
       still registered in(1,8) some interpreter is not allowed.                    |

       Tcl_SpliceChannel adds the specified channel to the (thread)global list |
       of all channels (of the current thread).  Application to a channel reg- |
       istered in(1,8) some interpreter is not allowed.                             |

       Tcl_ClearChannelHandlers  removes all channelhandlers and event scripts |
       associated with the specified channel, thus  shutting  down  all  event |
       processing for this channel.


TCL_CHANNELTYPE
       A  channel  driver  provides  a Tcl_ChannelType 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(1,8) Tcl 8.3.2/8.4 to correct a  problem
       with  stacked channel drivers.  See the OLD CHANNEL TYPES section below
       for details about the old structure.

       The Tcl_ChannelType structure contains the following fields:
              typedef struct Tcl_ChannelType {
                char *typeName;
                Tcl_ChannelTypeVersion version(1,3,5);
                Tcl_DriverCloseProc *closeProc;
                Tcl_DriverInputProc *inputProc;
                Tcl_DriverOutputProc *outputProc;
                Tcl_DriverSeekProc *seekProc;
                Tcl_DriverSetOptionProc *setOptionProc;
                Tcl_DriverGetOptionProc *getOptionProc;
                Tcl_DriverWatchProc *watchProc;
                Tcl_DriverGetHandleProc *getHandleProc;
                Tcl_DriverClose2Proc *close2Proc;
                Tcl_DriverBlockModeProc *blockModeProc;
                Tcl_DriverFlushProc *flushProc;
                Tcl_DriverHandlerProc *handlerProc;
                Tcl_DriverWideSeekProc *wideSeekProc;
              } Tcl_ChannelType;

       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 EINVAL when invoked to indicate
       that they are not implemented, except in(1,8) the case of flushProc and han-
       dlerProc, which should specified as NULL if(3,n) not otherwise defined.

       The  user  should  only  use  the  above  structure for Tcl_ChannelType
       instantiation.  When referencing fields in(1,8) a Tcl_ChannelType structure,
       the  following functions should be used to obtain the values: Tcl_Chan-
       nelName,  Tcl_ChannelVersion,  Tcl_ChannelBlockModeProc,   Tcl_Channel-
       CloseProc, Tcl_ChannelClose2Proc, Tcl_ChannelInputProc, Tcl_ChannelOut-
       putProc, Tcl_ChannelSeekProc,  Tcl_ChannelWideSeekProc,  Tcl_ChannelSe- |
       tOptionProc,  Tcl_ChannelGetOptionProc, Tcl_ChannelWatchProc, Tcl_Chan-
       nelGetHandleProc, Tcl_ChannelFlushProc, or Tcl_ChannelHandlerProc.

       The change to the structures was made in(1,8) 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(3,n)  that  identifies
       the  type  of  the  device  implemented  by  this driver, e.g.  file(1,n) or
       socket(2,7,n).

       This value can be  retrieved  with  Tcl_ChannelName,  which  returns  a
       pointer to the string.


VERSION
       The version(1,3,5) field should be set(7,n,1 builtins) to TCL_CHANNEL_VERSION_2.  If it is not
       set(7,n,1 builtins) to this value TCL_CHANNEL_VERSION_3, then this  Tcl_ChannelType  is
       assumed  to  have  the older structure.  See OLD CHANNEL TYPES for more
       details.  While Tcl will recognize and function with either  structure,
       stacked  channels must be of at least TCL_CHANNEL_VERSION_2 to function
       correctly.

       This value can be retrieved with Tcl_ChannelVersion, which returns  one |
       of  TCL_CHANNEL_VERSION_3,  TCL_CHANNEL_VERSION_2  or  TCL_CHANNEL_VER-
       SION_1.


BLOCKMODEPROC
       The blockModeProc field contains the address of a  function  called  by
       the  generic  layer to set(7,n,1 builtins) blocking and nonblocking mode on the device.
       BlockModeProc should match the following prototype:

              typedef int Tcl_DriverBlockModeProc(
                ClientData instanceData,
                int mode);

       The instanceData is the same as the value passed  to  Tcl_CreateChannel
       when   this   channel   was  created.   The  mode  argument  is  either
       TCL_MODE_BLOCKING or TCL_MODE_NONBLOCKING to set(7,n,1 builtins) the device into block-
       ing  or nonblocking mode. The function should return zero if(3,n) the opera-
       tion was successful, or a nonzero POSIX error(8,n)  code  if(3,n)  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(1,8) the channel driver.

       This  value  can  be  retrieved  with  Tcl_ChannelBlockModeProc,  which
       returns a pointer to the function.

       A  channel  driver  not  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.



CLOSEPROC AND CLOSE2PROC
       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 Tcl_DriverCloseProc(
                ClientData instanceData,
                Tcl_Interp *interp);

       The instanceData argument is the same as the value provided to Tcl_Cre-
       ateChannel  when  the  channel was created. The function should release
       any storage maintained by the channel  driver  for  this  channel,  and
       close(2,7,n)  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(2,7,n)  operation  is  suc-
       cessful, the procedure should return zero; otherwise it should return a
       nonzero POSIX error(8,n) code. In addition, if(3,n) an error(8,n) occurs and interp is
       not  NULL,  the  procedure  should store an error(8,n) message in(1,8) the inter-
       preter's result.

       Alternatively, channels that support closing the read(2,n,1 builtins) and  write(1,2)  sides
       independently may set(7,n,1 builtins) closeProc to TCL_CLOSE2PROC and set(7,n,1 builtins) close2Proc to
       the address of a function that matches the following prototype:

              typedef int Tcl_DriverClose2Proc(
                ClientData instanceData,
                Tcl_Interp *interp,
                int flags);

       The close2Proc will be called with flags set(7,n,1 builtins) to an OR'ed combination of
       TCL_CLOSE_READ  or  TCL_CLOSE_WRITE  to indicate that the driver should
       close(2,7,n) the read(2,n,1 builtins) and/or write(1,2) side of the channel.   The  channel  driver
       may  be  invoked  to perform additional operations on the channel after
       close2Proc is called to close(2,7,n) one or both sides  of  the  channel.   If
       flags  is  0  (zero), the driver should close(2,7,n) the channel in(1,8) 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(3,n)  the  close(2,7,n)
       operation  was  successful;  otherwise it should return a nonzero POSIX
       error(8,n) code. In addition, if(3,n) an error(8,n) occurs and interp is not NULL, the
       procedure should store an error(8,n) message in(1,8) the interpreter's result.

       These  value can be retrieved with Tcl_ChannelCloseProc or Tcl_Channel-
       Close2Proc, which returns a pointer to the respective function.


INPUTPROC
       The inputProc field contains the address of a function  called  by  the
       generic  layer  to read(2,n,1 builtins) data from the file(1,n) or device and store it in(1,8) an
       internal buffer. InputProc must match the following prototype:

              typedef int Tcl_DriverInputProc(
                ClientData instanceData,
                char *buf,
                int bufSize,
                int *errorCodePtr);

       InstanceData is the same as the value passed to Tcl_CreateChannel  when
       the  channel was created.  The buf argument points to an array of bytes
       in(1,8) 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(8,n) occurs, the function should set(7,n,1 builtins) the variable
       to a POSIX error(8,n) code that identifies the error(8,n) that occurred.

       The function should read(2,n,1 builtins) 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(2,n,1 builtins) from the input
       device and stored at buf. On error(8,n), the function should return  -1.  If
       an  error(8,n)  occurs  after  some data has been read(2,n,1 builtins) from the device, that
       data is lost.

       If inputProc can determine that the input device has some  data  avail-
       able  but  less(1,3)  than  requested  by the bufSize argument, the function
       should only attempt to read(2,n,1 builtins) as much data as  is  available  and  return
       without  blocking. If the input device has no data available whatsoever
       and the channel is in(1,8) nonblocking mode, the function should  return  an
       EAGAIN  error. If the input device has no data available whatsoever and
       the channel is in(1,8) blocking mode, the  function  should  block  for  the
       shortest possible time(1,2,n) until at least one byte of data can be read(2,n,1 builtins) from
       the device; then, it should return as much data as it can read(2,n,1 builtins)  without
       blocking.

       This  value can be retrieved with Tcl_ChannelInputProc, which returns a
       pointer to the function.


OUTPUTPROC
       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 Tcl_DriverOutputProc(
                ClientData instanceData,
                CONST char *buf,
                int toWrite,
                int *errorCodePtr);

       InstanceData is the same as the value passed to Tcl_CreateChannel  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(8,n) occurs, the function should set(7,n,1 builtins)  this  vari-
       able to a POSIX error(8,n) code that identifies the error.

       The function should write(1,2) 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(1,3)  in(1,8) some cases such as if(3,n) the output operation is interrupted by a
       signal. If an error(8,n) occurs the function should return -1.  In  case  of
       error(8,n), 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 EAGAIN error(8,n)
       without writing any data.

       This value can be retrieved with Tcl_ChannelOutputProc, which returns a
       pointer to the function.


SEEKPROC AND WIDESEEKPROC
       The seekProc field contains the address of a  function  called  by  the
       generic  layer  to  move(3x,7,3x curs_move)  the access(2,5) point at which subsequent input or
       output operations will be applied. SeekProc must  match  the  following
       prototype:

              typedef int Tcl_DriverSeekProc(
                ClientData instanceData,
                long offset,
                int seekMode,
                int *errorCodePtr);

       The instanceData argument is the same as the value given to Tcl_Create-
       Channel when this channel was created.  Offset and  seekMode  have  the
       same  meaning  as  for  the Tcl_Seek procedure (described in(1,8) the manual
       entry for Tcl_OpenFileChannel).

       The errorCodePtr argument points to an integer variable provided by the
       generic  layer for returning errno values from the function.  The func-
       tion should set(7,n,1 builtins) this variable to a POSIX error(8,n) code if(3,n) an error(8,n) occurs.
       The function should store an EINVAL error(8,n) code if(3,n) the channel type does
       not implement seeking.

       The return value is the new access(2,5) point or -1 in(1,8) case of error. If  an
       error(8,n) occurred, the function should not move(3x,7,3x curs_move) the access(2,5) 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(1,8) preference to  the |
       seekProc,  but  both  must  be  defined if(3,n) the wideSeekProc is defined. |
       WideSeekProc must match the following prototype:                        |

              typedef Tcl_WideInt Tcl_DriverWideSeekProc(                      |
                ClientData instanceData,                                       |
                Tcl_WideInt 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  Tcl_ChannelSeekProc,  which |
       returns  a  pointer to the function, and similarly the wideSeekProc can |
       be retrieved with Tcl_ChannelWideSeekProc.


SETOPTIONPROC
       The setOptionProc field contains the address of a  function  called  by
       the  generic  layer to set(7,n,1 builtins) a channel type specific option on a channel.
       setOptionProc must match the following prototype:

              typedef int Tcl_DriverSetOptionProc(
                ClientData instanceData,
                Tcl_Interp *interp,
                CONST char *optionName,
                CONST char *newValue);

       optionName is the name of an option to set(7,n,1 builtins), and  newValue  is  the  new
       value for that option, as a string. The instanceData is the same as the
       value given to Tcl_CreateChannel 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(7,n,1 builtins) them, e.g. -blockmode. 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
       function returns TCL_OK.  It  should  call  Tcl_BadChannelOption  which
       itself  returns  TCL_ERROR  if(3,n) the optionName is unrecognized.  If new-
       Value specifies a value for the option that is not supported  or  if(3,n)  a
       system call error(8,n) occurs, the function should leave an error(8,n) message in(1,8)
       the result field of interp if(3,n) interp is not NULL. The  function  should
       also call Tcl_SetErrno to store an appropriate POSIX error(8,n) code.

       This  value  can  be  retrieved  with  Tcl_ChannelSetOptionProc,  which
       returns a pointer to the function.


GETOPTIONPROC
       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 Tcl_DriverGetOptionProc(
                ClientData instanceData,
                Tcl_Interp *interp,
                CONST char *optionName,
                Tcl_DString *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(3,n), in(1,8) the Tcl dynamic string(3,n) optionValue.  If  optionName  is
       NULL,  the  function  stores  in(1,8) optionValue an alternating list of all
       supported options and their current values.  On success,  the  function
       returns  TCL_OK.   It  should  call  Tcl_BadChannelOption  which itself
       returns TCL_ERROR if(3,n) the optionName is unrecognized. If a  system  call
       error(8,n)  occurs, the function should leave an error(8,n) message in(1,8) the result
       of interp if(3,n)  interp  is  not  NULL.  The  function  should  also  call
       Tcl_SetErrno to store an appropriate POSIX error(8,n) code.

       Some options are handled by the generic code and this function is never
       called to retrieve their value, e.g. -blockmode. 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.

       This  value  can  be  retrieved  with  Tcl_ChannelGetOptionProc,  which
       returns a pointer to the function.


WATCHPROC
       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 Tcl_DriverWatchProc(
                ClientData instanceData,
                int mask);

       The instanceData is the same as the value passed  to  Tcl_CreateChannel
       when  this  channel was created. The mask argument is an OR-ed combina-
       tion of TCL_READABLE,  TCL_WRITABLE  and  TCL_EXCEPTION;  it  indicates
       events the caller is interested in(1,8) 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  Tcl_NotifyChannel  to  inform  the
       generic  channel  module.   The  driver  should take care not to starve
       other channel drivers or sources of callbacks by  invoking  Tcl_Notify-
       Channel too frequently.  Fairness can be insured by using the Tcl event
       queue(1,3) to allow the channel event to be scheduled in(1,8) sequence with other
       events.   See  the  description of Tcl_QueueEvent for details on how to
       queue(1,3) an event.

       This value can be retrieved with Tcl_ChannelWatchProc, which returns  a
       pointer to the function.


GETHANDLEPROC
       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 Tcl_DriverGetHandleProc(
                ClientData instanceData,
                int direction,
                ClientData *handlePtr);

       InstanceData  is the same as the value passed to Tcl_CreateChannel when
       this channel was created. The direction argument is either TCL_READABLE
       to  retrieve the handle used for input, or TCL_WRITABLE 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(1,8)  the
       location  referred  to by handlePtr, and TCL_OK should be returned.  If
       the channel is not open(2,3,n) for the specified direction, or if(3,n) the  channel
       implementation  does not use device handles, the function should return
       TCL_ERROR.

       This  value  can  be  retrieved  with  Tcl_ChannelGetHandleProc,  which
       returns a pointer to the function.


FLUSHPROC
       The flushProc field is currently reserved for future use.  It should be
       set(7,n,1 builtins) to NULL.  FlushProc should match the following prototype:

              typedef int Tcl_DriverFlushProc(
                ClientData instanceData);

       This value can be retrieved with Tcl_ChannelFlushProc, which returns  a
       pointer to the function.


HANDLERPROC
       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 Tcl_DriverHandlerProc(
                ClientData instanceData,
                int interestMask);

       InstanceData  is the same as the value passed to Tcl_CreateChannel when
       this channel was created.  The interestMask is an OR-ed combination  of
       TCL_READABLE  or TCL_WRITABLE; it indicates what type of event occurred
       on this channel.

       This value can be retrieved with Tcl_ChannelHandlerProc, which  returns
       a pointer to the function.


TCL_BADCHANNELOPTION
       This  procedure generates a "bad option" error(8,n) message in(1,8) 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(8,n)  mes-
       sage string.

       It always return TCL_ERROR

       An  error(8,n)  message  is  generated in(1,8) 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 ``<specific options>'' 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.


OLD CHANNEL TYPES
       The original (8.3.1 and below) Tcl_ChannelType structure  contains  the
       following fields:

              typedef struct Tcl_ChannelType {
                char *typeName;
                Tcl_DriverBlockModeProc *blockModeProc;
                Tcl_DriverCloseProc *closeProc;
                Tcl_DriverInputProc *inputProc;
                Tcl_DriverOutputProc *outputProc;
                Tcl_DriverSeekProc *seekProc;
                Tcl_DriverSetOptionProc *setOptionProc;
                Tcl_DriverGetOptionProc *getOptionProc;
                Tcl_DriverWatchProc *watchProc;
                Tcl_DriverGetHandleProc *getHandleProc;
                Tcl_DriverClose2Proc *close2Proc;
              } Tcl_ChannelType;

       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  Tcl_ChannelType  structure if(3,n) you are creating a stacked
       channel driver, due to problems with the earlier stacked channel imple-
       mentation (in(1,8) 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 Tcl_ChannelType structure contained  the |
       following fields:                                                       |

              typedef struct Tcl_ChannelType {                                 |
                char *typeName;                                                |
                Tcl_ChannelTypeVersion version(1,3,5);                                |
                Tcl_DriverCloseProc *closeProc;                                |
                Tcl_DriverInputProc *inputProc;                                |
                Tcl_DriverOutputProc *outputProc;                              |
                Tcl_DriverSeekProc *seekProc;                                  |
                Tcl_DriverSetOptionProc *setOptionProc;                        |
                Tcl_DriverGetOptionProc *getOptionProc;                        |
                Tcl_DriverWatchProc *watchProc;                                |
                Tcl_DriverGetHandleProc *getHandleProc;                        |
                Tcl_DriverClose2Proc *close2Proc;                              |
                Tcl_DriverBlockModeProc *blockModeProc;                        |
                Tcl_DriverFlushProc *flushProc;                                |
                Tcl_DriverHandlerProc *handlerProc;                            |
              } Tcl_ChannelType;                                               |

       When  the  above structure is registered as a channel type, the version(1,3,5) |
       field should always be TCL_CHANNEL_VERSION_2.


SEE ALSO
       Tcl_Close(3),         Tcl_OpenFileChannel(3),          Tcl_SetErrno(3),
       Tcl_QueueEvent(3), Tcl_StackChannel(3), Tcl_GetStdChannel(3)


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



Tcl                                   8.3                 Tcl_CreateChannel(3)

References for this manual (incoming links)