| 1 |
'\" |
| 2 |
'\" Copyright (c) 1996 Sun Microsystems, Inc. |
| 3 |
'\" |
| 4 |
'\" See the file "license.terms" for information on usage and redistribution |
| 5 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 6 |
'\" |
| 7 |
.TH Tcl_CreateChannelHandler 3 7.5 Tcl "Tcl Library Procedures" |
| 8 |
.so man.macros |
| 9 |
.BS |
| 10 |
'\" Note: do not modify the .SH NAME line immediately below! |
| 11 |
.SH NAME |
| 12 |
Tcl_CreateChannelHandler, Tcl_DeleteChannelHandler \- call a procedure when a channel becomes readable or writable |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.nf |
| 16 |
\fB#include <tcl.h>\fR |
| 17 |
.sp |
| 18 |
void |
| 19 |
\fBTcl_CreateChannelHandler\fR(\fIchannel, mask, proc, clientData\fR) |
| 20 |
.sp |
| 21 |
void |
| 22 |
\fBTcl_DeleteChannelHandler\fR(\fIchannel, proc, clientData\fR) |
| 23 |
.sp |
| 24 |
.SH ARGUMENTS |
| 25 |
.AS Tcl_ChannelProc clientData |
| 26 |
.AP Tcl_Channel channel in |
| 27 |
Tcl channel such as returned by \fBTcl_CreateChannel\fR. |
| 28 |
.AP int mask in |
| 29 |
Conditions under which \fIproc\fR should be called: OR-ed combination of |
| 30 |
\fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR and \fBTCL_EXCEPTION\fR. Specify |
| 31 |
a zero value to temporarily disable an existing handler. |
| 32 |
.AP Tcl_FileProc *proc in |
| 33 |
Procedure to invoke whenever the channel indicated by \fIchannel\fR meets |
| 34 |
the conditions specified by \fImask\fR. |
| 35 |
.AP ClientData clientData in |
| 36 |
Arbitrary one-word value to pass to \fIproc\fR. |
| 37 |
.BE |
| 38 |
.SH DESCRIPTION |
| 39 |
.PP |
| 40 |
\fBTcl_CreateChannelHandler\fR arranges for \fIproc\fR to be called in the |
| 41 |
future whenever input or output becomes possible on the channel identified |
| 42 |
by \fIchannel\fR, or whenever an exceptional condition exists for |
| 43 |
\fIchannel\fR. The conditions of interest under which \fIproc\fR will be |
| 44 |
invoked are specified by the \fImask\fR argument. |
| 45 |
See the manual entry for \fBfileevent\fR for a precise description of |
| 46 |
what it means for a channel to be readable or writable. |
| 47 |
\fIProc\fR must conform to the following prototype: |
| 48 |
.PP |
| 49 |
.CS |
| 50 |
typedef void \fBTcl_ChannelProc\fR( |
| 51 |
ClientData \fIclientData\fR, |
| 52 |
int \fImask\fR); |
| 53 |
.CE |
| 54 |
.PP |
| 55 |
The \fIclientData\fR argument is the same as the value passed to |
| 56 |
\fBTcl_CreateChannelHandler\fR when the handler was created. Typically, |
| 57 |
\fIclientData\fR points to a data structure containing application-specific |
| 58 |
information about the channel. \fIMask\fR is an integer mask indicating |
| 59 |
which of the requested conditions actually exists for the channel; it will |
| 60 |
contain a subset of the bits from the \fImask\fR argument to |
| 61 |
\fBTcl_CreateChannelHandler\fR when the handler was created. |
| 62 |
.PP |
| 63 |
Each channel handler is identified by a unique combination of \fIchannel\fR, |
| 64 |
\fIproc\fR and \fIclientData\fR. |
| 65 |
There may be many handlers for a given channel as long as they do not |
| 66 |
have the same \fIchannel\fR, \fIproc\fR, and \fIclientData\fR. |
| 67 |
If \fBTcl_CreateChannelHandler\fR is invoked when there is already a handler |
| 68 |
for \fIchannel\fR, \fIproc\fR, and \fIclientData\fR, then no new |
| 69 |
handler is created; instead, the \fImask\fR is changed for the |
| 70 |
existing handler. |
| 71 |
.PP |
| 72 |
\fBTcl_DeleteChannelHandler\fR deletes a channel handler identified by |
| 73 |
\fIchannel\fR, \fIproc\fR and \fIclientData\fR; if no such handler exists, |
| 74 |
the call has no effect. |
| 75 |
.PP |
| 76 |
Channel handlers are invoked via the Tcl event mechanism, so they |
| 77 |
are only useful in applications that are event-driven. |
| 78 |
Note also that the conditions specified in the \fImask\fR argument |
| 79 |
to \fIproc\fR may no longer exist when \fIproc\fR is invoked: for |
| 80 |
example, if there are two handlers for \fBTCL_READABLE\fR on the same |
| 81 |
channel, the first handler could consume all of the available input |
| 82 |
so that the channel is no longer readable when the second handler |
| 83 |
is invoked. |
| 84 |
For this reason it may be useful to use nonblocking I/O on channels |
| 85 |
for which there are event handlers. |
| 86 |
.SH "SEE ALSO" |
| 87 |
Notifier(3), Tcl_CreateChannel(3), Tcl_OpenFileChannel(3), vwait(n) |
| 88 |
.SH KEYWORDS |
| 89 |
blocking, callback, channel, events, handler, nonblocking |