CrtFileHdlr.3
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:4k
- '"
- '" Copyright (c) 1990-1994 The Regents of the University of California.
- '" Copyright (c) 1994-1997 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: CrtFileHdlr.3,v 1.2 1998/09/14 18:39:47 stanton Exp $
- '"
- .so man.macros
- .TH Tcl_CreateFileHandler 3 8.0 Tcl "Tcl Library Procedures"
- .BS
- .SH NAME
- Tcl_CreateFileHandler, Tcl_DeleteFileHandler - associate procedure callbacks with files or devices (Unix only)
- .SH SYNOPSIS
- .nf
- fB#include <tcl.h>fR
- .VS
- .sp
- fBTcl_CreateFileHandlerfR(fIfd, mask, proc, clientDatafR)
- .sp
- fBTcl_DeleteFileHandlerfR(fIfdfR)
- .VE
- .SH ARGUMENTS
- .AS Tcl_FileProc clientData
- .VS
- .AP int fd in
- Unix file descriptor for an open file or device.
- .VE
- .AP int mask in
- Conditions under which fIprocfR should be called:
- OR-ed combination of fBTCL_READABLEfR, fBTCL_WRITABLEfR,
- and fBTCL_EXCEPTIONfR. May be set to 0 to temporarily disable
- a handler.
- .AP Tcl_FileProc *proc in
- Procedure to invoke whenever the file or device indicated
- by fIfilefR meets the conditions specified by fImaskfR.
- .AP ClientData clientData in
- Arbitrary one-word value to pass to fIprocfR.
- .BE
- .SH DESCRIPTION
- .PP
- .VS
- fBTcl_CreateFileHandlerfR arranges for fIprocfR to be
- invoked in the future whenever I/O becomes possible on a file
- or an exceptional condition exists for the file. The file
- is indicated by fIfdfR, and the conditions of interest
- .VE
- are indicated by fImaskfR. For example, if fImaskfR
- is fBTCL_READABLEfR, fIprocfR will be called when
- the file is readable.
- The callback to fIprocfR is made by fBTcl_DoOneEventfR, so
- fBTcl_CreateFileHandlerfR is only useful in programs that dispatch
- events through fBTcl_DoOneEventfR or through Tcl commands such
- as fBvwaitfR.
- .PP
- fIProcfR should have arguments and result that match the
- type fBTcl_FileProcfR:
- .CS
- typedef void Tcl_FileProc(
- ClientData fIclientDatafR,
- int fImaskfR);
- .CE
- The fIclientDatafR parameter to fIprocfR is a copy
- of the fIclientDatafR
- argument given to fBTcl_CreateFileHandlerfR when the callback
- was created. Typically, fIclientDatafR points to a data
- structure containing application-specific information about
- the file. fIMaskfR is an integer mask indicating which
- of the requested conditions actually exists for the file; it
- will contain a subset of the bits in the fImaskfR argument
- to fBTcl_CreateFileHandlerfR.
- .PP
- .PP
- There may exist only one handler for a given file at a given time.
- If fBTcl_CreateFileHandlerfR is called when a handler already
- exists for fIfdfR, then the new callback replaces the information
- that was previously recorded.
- .PP
- fBTcl_DeleteFileHandlerfR may be called to delete the
- file handler for fIfdfR; if no handler exists for the
- file given by fIfdfR then the procedure has no effect.
- .PP
- The purpose of file handlers is to enable an application to respond to
- events while waiting for files to become ready for I/O. For this to work
- correctly, the application may need to use non-blocking I/O operations on
- the files for which handlers are declared. Otherwise the application may
- block if it reads or writes too much data; while waiting for the I/O to
- complete the application won't be able to service other events. Use
- fBTcl_SetChannelOptionfR with fB-blockingfR to set the channel into
- blocking or nonblocking mode as required.
- .PP
- .VS
- Note that these interfaces are only supported by the Unix
- implementation of the Tcl notifier.
- .VE
- .SH KEYWORDS
- callback, file, handler