1Tcl_CreateFileHandler(3)    Tcl Library Procedures    Tcl_CreateFileHandler(3)
2
3
4
5______________________________________________________________________________
6

NAME

8       Tcl_CreateFileHandler,   Tcl_DeleteFileHandler  -  associate  procedure
9       callbacks with files or devices (Unix only)
10

SYNOPSIS

12       #include <tcl.h>
13
14       Tcl_CreateFileHandler(fd, mask, proc, clientData)                       │
15
16       Tcl_DeleteFileHandler(fd)                                               │
17

ARGUMENTS

19       int            fd           (in)                                        │
20                                             Unix file descriptor for an  open │
21                                             file or device.
22
23       int            mask         (in)      Conditions   under   which   proc
24                                             should be called: OR-ed  combina‐
25                                             tion       of       TCL_READABLE,
26                                             TCL_WRITABLE, and  TCL_EXCEPTION.
27                                             May  be  set  to 0 to temporarily
28                                             disable a handler.
29
30       Tcl_FileProc   *proc        (in)      Procedure to invoke whenever  the
31                                             file  or device indicated by file
32                                             meets the conditions specified by
33                                             mask.
34
35       ClientData     clientData   (in)      Arbitrary  one-word value to pass
36                                             to proc.
37_________________________________________________________________
38
39

DESCRIPTION

41       Tcl_CreateFileHandler arranges for proc to be  invoked  in  the  future │
42       whenever  I/O  becomes  possible  on a file or an exceptional condition │
43       exists for the file.  The file is indicated by fd, and  the  conditions │
44       of  interest  are indicated by mask.  For example, if mask is TCL_READ‐
45       ABLE, proc will be called when the file is readable.  The  callback  to
46       proc is made by Tcl_DoOneEvent, so Tcl_CreateFileHandler is only useful
47       in programs that dispatch events through Tcl_DoOneEvent or through  Tcl
48       commands such as vwait.
49
50       Proc should have arguments and result that match the type Tcl_FileProc:
51              typedef void Tcl_FileProc(
52                ClientData clientData,
53                int mask);
54       The  clientData  parameter to proc is a copy of the clientData argument
55       given to Tcl_CreateFileHandler when the callback  was  created.   Typi‐
56       cally,  clientData  points  to a data structure containing application-
57       specific information about the file.  Mask is an integer mask  indicat‐
58       ing which of the requested conditions actually exists for the file;  it
59       will contain a subset of the bits in the mask argument  to  Tcl_Create‐
60       FileHandler.
61
62       There  may exist only one handler for a given file at a given time.  If
63       Tcl_CreateFileHandler is called when a handler already exists  for  fd,
64       then  the  new  callback  replaces  the information that was previously
65       recorded.
66
67       Tcl_DeleteFileHandler may be called to delete the file handler for  fd;
68       if no handler exists for the file given by fd then the procedure has no
69       effect.
70
71       The purpose of file handlers is to enable an application to respond  to
72       events  while  waiting  for files to become ready for I/O.  For this to
73       work correctly, the application may need to use non-blocking I/O opera‐
74       tions  on  the  files  for  which handlers are declared.  Otherwise the
75       application may block if it reads or writes too much data; while  wait‐
76       ing  for  the  I/O to complete the application won't be able to service
77       other events. Use Tcl_SetChannelOption with -blocking to set the  chan‐
78       nel into blocking or nonblocking mode as required.
79
80       Note  that  these interfaces are only supported by the Unix implementa‐ │
81       tion of the Tcl notifier.
82
83

KEYWORDS

85       callback, file, handler
86
87
88
89Tcl                                   8.0             Tcl_CreateFileHandler(3)
Impressum