| 1 |
'\" |
| 2 |
'\" Copyright (c) 1990-1994 The Regents of the University of California. |
| 3 |
'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. |
| 4 |
'\" |
| 5 |
'\" See the file "license.terms" for information on usage and redistribution |
| 6 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 7 |
'\" |
| 8 |
.TH Tcl_CreateFileHandler 3 8.0 Tcl "Tcl Library Procedures" |
| 9 |
.so man.macros |
| 10 |
.BS |
| 11 |
.SH NAME |
| 12 |
Tcl_CreateFileHandler, Tcl_DeleteFileHandler \- associate procedure callbacks with files or devices (Unix only) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
\fB#include <tcl.h>\fR |
| 16 |
.sp |
| 17 |
\fBTcl_CreateFileHandler\fR(\fIfd, mask, proc, clientData\fR) |
| 18 |
.sp |
| 19 |
\fBTcl_DeleteFileHandler\fR(\fIfd\fR) |
| 20 |
.SH ARGUMENTS |
| 21 |
.AS Tcl_FileProc clientData |
| 22 |
.AP int fd in |
| 23 |
Unix file descriptor for an open file or device. |
| 24 |
.AP int mask in |
| 25 |
Conditions under which \fIproc\fR should be called: |
| 26 |
OR-ed combination of \fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR, |
| 27 |
and \fBTCL_EXCEPTION\fR. May be set to 0 to temporarily disable |
| 28 |
a handler. |
| 29 |
.AP Tcl_FileProc *proc in |
| 30 |
Procedure to invoke whenever the file or device indicated |
| 31 |
by \fIfile\fR meets the conditions specified by \fImask\fR. |
| 32 |
.AP ClientData clientData in |
| 33 |
Arbitrary one-word value to pass to \fIproc\fR. |
| 34 |
.BE |
| 35 |
.SH DESCRIPTION |
| 36 |
.PP |
| 37 |
\fBTcl_CreateFileHandler\fR arranges for \fIproc\fR to be |
| 38 |
invoked in the future whenever I/O becomes possible on a file |
| 39 |
or an exceptional condition exists for the file. The file |
| 40 |
is indicated by \fIfd\fR, and the conditions of interest |
| 41 |
are indicated by \fImask\fR. For example, if \fImask\fR |
| 42 |
is \fBTCL_READABLE\fR, \fIproc\fR will be called when |
| 43 |
the file is readable. |
| 44 |
The callback to \fIproc\fR is made by \fBTcl_DoOneEvent\fR, so |
| 45 |
\fBTcl_CreateFileHandler\fR is only useful in programs that dispatch |
| 46 |
events through \fBTcl_DoOneEvent\fR or through Tcl commands such |
| 47 |
as \fBvwait\fR. |
| 48 |
.PP |
| 49 |
\fIProc\fR should have arguments and result that match the |
| 50 |
type \fBTcl_FileProc\fR: |
| 51 |
.PP |
| 52 |
.CS |
| 53 |
typedef void \fBTcl_FileProc\fR( |
| 54 |
ClientData \fIclientData\fR, |
| 55 |
int \fImask\fR); |
| 56 |
.CE |
| 57 |
.PP |
| 58 |
The \fIclientData\fR parameter to \fIproc\fR is a copy |
| 59 |
of the \fIclientData\fR |
| 60 |
argument given to \fBTcl_CreateFileHandler\fR when the callback |
| 61 |
was created. Typically, \fIclientData\fR points to a data |
| 62 |
structure containing application-specific information about |
| 63 |
the file. \fIMask\fR is an integer mask indicating which |
| 64 |
of the requested conditions actually exists for the file; it |
| 65 |
will contain a subset of the bits in the \fImask\fR argument |
| 66 |
to \fBTcl_CreateFileHandler\fR. |
| 67 |
.PP |
| 68 |
There may exist only one handler for a given file at a given time. |
| 69 |
If \fBTcl_CreateFileHandler\fR is called when a handler already |
| 70 |
exists for \fIfd\fR, then the new callback replaces the information |
| 71 |
that was previously recorded. |
| 72 |
.PP |
| 73 |
\fBTcl_DeleteFileHandler\fR may be called to delete the |
| 74 |
file handler for \fIfd\fR; if no handler exists for the |
| 75 |
file given by \fIfd\fR then the procedure has no effect. |
| 76 |
.PP |
| 77 |
The purpose of file handlers is to enable an application to respond to |
| 78 |
events while waiting for files to become ready for I/O. For this to work |
| 79 |
correctly, the application may need to use non-blocking I/O operations on |
| 80 |
the files for which handlers are declared. Otherwise the application may |
| 81 |
block if it reads or writes too much data; while waiting for the I/O to |
| 82 |
complete the application will not be able to service other events. Use |
| 83 |
\fBTcl_SetChannelOption\fR with \fB\-blocking\fR to set the channel into |
| 84 |
blocking or nonblocking mode as required. |
| 85 |
.PP |
| 86 |
Note that these interfaces are only supported by the Unix |
| 87 |
implementation of the Tcl notifier. |
| 88 |
.SH "SEE ALSO" |
| 89 |
fileevent(n), Tcl_CreateTimerHandler(3), Tcl_DoWhenIdle(3) |
| 90 |
.SH KEYWORDS |
| 91 |
callback, file, handler |