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
39 Tcl_CreateFileHandler arranges for proc to be invoked in the future
40 whenever I/O becomes possible on a file or an exceptional condition
41 exists for the file. The file is indicated by fd, and the conditions
42 of interest are indicated by mask. For example, if mask is TCL_READ‐
43 ABLE, proc will be called when the file is readable. The callback to
44 proc is made by Tcl_DoOneEvent, so Tcl_CreateFileHandler is only useful
45 in programs that dispatch events through Tcl_DoOneEvent or through Tcl
46 commands such as vwait.
47
48 Proc should have arguments and result that match the type Tcl_FileProc:
49
50 typedef void Tcl_FileProc(
51 ClientData clientData,
52 int mask);
53
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 will not 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
84 fileevent(n), Tcl_CreateTimerHandler(3), Tcl_DoWhenIdle(3)
85
87 callback, file, handler
88
89
90
91Tcl 8.0 Tcl_CreateFileHandler(3)