1Tcl_CreateFileHandler(3) Tcl Library Procedures Tcl_CreateFileHandler(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_CreateFileHandler, Tcl_DeleteFileHandler - associate procedure
9 callbacks with files or devices (Unix only)
10
12 #include <tcl.h>
13
14 Tcl_CreateFileHandler(fd, mask, proc, clientData)
15
16 Tcl_DeleteFileHandler(fd)
17
19 int fd (in) Unix file descriptor for an open
20 file or device.
21
22 int mask (in) Conditions under which proc
23 should be called: OR-ed combina‐
24 tion of TCL_READABLE,
25 TCL_WRITABLE, and TCL_EXCEPTION.
26 May be set to 0 to temporarily
27 disable a handler.
28
29 Tcl_FileProc *proc (in) Procedure to invoke whenever the
30 file or device indicated by file
31 meets the conditions specified by
32 mask.
33
34 ClientData clientData (in) Arbitrary one-word value to pass
35 to proc.
36_________________________________________________________________
37
38
40 Tcl_CreateFileHandler arranges for proc to be invoked in the future
41 whenever I/O becomes possible on a file or an exceptional condition
42 exists for the file. The file is indicated by fd, and the conditions
43 of interest are indicated by mask. For example, if mask is TCL_READ‐
44 ABLE, proc will be called when the file is readable. The callback to
45 proc is made by Tcl_DoOneEvent, so Tcl_CreateFileHandler is only useful
46 in programs that dispatch events through Tcl_DoOneEvent or through Tcl
47 commands such as vwait.
48
49 Proc should have arguments and result that match the type Tcl_FileProc:
50 typedef void Tcl_FileProc(
51 ClientData clientData,
52 int mask);
53 The clientData parameter to proc is a copy of the clientData argument
54 given to Tcl_CreateFileHandler when the callback was created. Typi‐
55 cally, clientData points to a data structure containing application-
56 specific information about the file. Mask is an integer mask indicat‐
57 ing which of the requested conditions actually exists for the file; it
58 will contain a subset of the bits in the mask argument to Tcl_Create‐
59 FileHandler.
60
61 There may exist only one handler for a given file at a given time. If
62 Tcl_CreateFileHandler is called when a handler already exists for fd,
63 then the new callback replaces the information that was previously
64 recorded.
65
66 Tcl_DeleteFileHandler may be called to delete the file handler for fd;
67 if no handler exists for the file given by fd then the procedure has no
68 effect.
69
70 The purpose of file handlers is to enable an application to respond to
71 events while waiting for files to become ready for I/O. For this to
72 work correctly, the application may need to use non-blocking I/O opera‐
73 tions on the files for which handlers are declared. Otherwise the
74 application may block if it reads or writes too much data; while wait‐
75 ing for the I/O to complete the application will not be able to service
76 other events. Use Tcl_SetChannelOption with -blocking to set the chan‐
77 nel into blocking or nonblocking mode as required.
78
79 Note that these interfaces are only supported by the Unix implementa‐
80 tion of the Tcl notifier.
81
82
84 callback, file, handler
85
86
87
88Tcl 8.0 Tcl_CreateFileHandler(3)