# Copyright (c) 1990-1994 The Regents of the University of California. # Copyright (c) 1994 Sun Microsystems, Inc. # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # # @(#) FileHndlr.3 1.12 95/05/06 15:29:24 # =head1 NAME Tk_CreateFileHandler, Tk_CreateFileHandler2, Tk_DeleteFileHandler - associate procedure callbacks with files or devices =for category C Programming =head1 SYNOPSIS B<#include Etk.hE> B(I) B(I) B(I) =head1 ARGUMENTS =over 4 =item int id (in) Integer identifier for an open file or device (such as returned by B system call). =item int mask (in) Conditions under which I should be called: OR-ed combination of B, B, and B. =item Tk_FileProc *proc (in) Procedure to invoke whenever the file or device indicated by I meets the conditions specified by I. =item Tk_FileProc2 *proc2 (in) Procedure to invoke from event loop to check whether I is ready and, if so, handle it. =item ClientData clientData (in) Arbitrary one-word value to pass to I. =back =head1 DESCRIPTION B arranges for I 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 I, and the conditions of interest are indicated by I. For example, if I is B, I will be called when the file is readable. The callback to I is made by B, so B is only useful in programs that dispatch events through B or through other Tk procedures that call B, such as B. I should have arguments and result that match the type B: =over 4 typedef void Tk_FileProc( =over 4 ClientData I, int I); =back =back The I parameter to I is a copy of the I argument given to B when the callback was created. Typically, I points to a data structure containing application-specific information about the file. I 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 I argument to B. B also creates a file handler, but it provides a lower-level and more flexible interface. The callback procedure I must have arguments and result that match the following prototype: =over 4 typedef int Tk_FileProc2( =over 4 ClientData I, int I, int I); =back =back Whereas a file handler created by B is only invoked when the file is known to be ``ready'', a file handler created by B is invoked on every pass through the the event loop (B); it gets to determine whether the file is ``ready'' or not. The I argument contains an OR'ed combination of the bits B, B, and B, which indicate whether the file is known to be readable, writable, or to have an exceptional condition present (this is the case if B. Typically the return value reflects all of the conditions that I cares about. A zero return value means that the file should be ignored if B calls B call from the current invocation of B; the next invocation of B will call I afresh to get new information. There may exist only one handler for a given file at a given time. If B or B is called when a handler already exists for I, then the new callback replaces the information that was previously recorded. B may be called to delete the file handler for I; if no handler exists for the file given by I then the procedure has no effect. The purpose of file handlers is to enable an application to respond to X events and other 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 be put to sleep 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. In BSD-based UNIX systems, non-blocking I/O can be specified for a file using the B kernel call with the B flag. =head1 KEYWORDS callback, file, handler