Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / sun4-solaris / Tk / fileevent.pod
CommitLineData
86530b38
AT
1# Copyright (c) 1994 The Regents of the University of California.
2# Copyright (c) 1994-1996 Sun Microsystems, Inc.
3# See the file "license.terms" for information on usage and redistribution
4# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
5#
6#
7
8=head1 NAME
9
10Tk::fileevent - Execute a callback when a filehandle becomes readable or writable
11
12=for category Binding Events and Callbacks
13
14=head1 SYNOPSIS
15
16I<$widget>-E<gt>B<fileevent>(I<fileHandle>,B<readable>?,I<callback>?)
17
18I<$widget>-E<gt>B<fileevent>(I<fileHandle>,B<writable>?,I<callback>?)
19
20=head1 DESCRIPTION
21
22This command is used to create I<file event handlers>. A file event
23handler is a binding between a filehandle and a callback, such that the callback
24is evaluated whenever the filehandle becomes readable or writable. File event
25handlers are most commonly used to allow data to be received from another
26process on an event-driven basis, so that the receiver can continue to
27interact with the user while waiting for the data to arrive. If an
28application invokes C<E<lt>E<gt>>, C<sysread> or C<read> on a blocking filehandle when
29there is no input data available, the process will block; until the input
30data arrives, it will not be able to service other events, so it will
31appear to the user to ``freeze up''. With B<fileevent>, the process can
32tell when data is present and only invoke B<gets> or B<read> when
33they won't block.
34
35The I<fileHandle> argument to B<fileevent> refers to an open filehandle,
36such as the return value from a previous B<open> or B<socket>
37command.
38If the I<callback> argument is specified, then B<fileevent>
39creates a new event handler: I<callback> will be evaluated
40whenever the filehandle becomes readable or writable (depending on the
41argument to B<fileevent>).
42In this case B<fileevent> returns an empty string.
43The B<readable> and B<writable> event handlers for a file
44are independent, and may be created and deleted separately.
45However, there may be at most one B<readable> and one B<writable>
46handler for a file at a given time in a given interpreter.
47If B<fileevent> is called when the specified handler already
48exists in the invoking interpreter, the new callback replaces the old one.
49
50If the I<callback> argument is not specified, B<fileevent>
51returns the current callback for I<fileHandle>, or an empty string
52if there is none.
53If the I<callback> argument is specified as an empty string
54then the event handler is deleted, so that no callback will be invoked.
55A file event handler is also deleted automatically whenever
56its filehandle is closed or its interpreter is deleted.
57
58A filehandle is considered to be readable if there is unread data
59available on the underlying device.
60A filehandle is also considered to be readable if an end of file or
61error condition is present on the underlying file or device.
62It is important for I<callback> to check for these conditions
63and handle them appropriately; for example, if there is no special
64check for end of file, an infinite loop may occur where I<callback>
65reads no data, returns, and is immediately invoked again.
66
67A filehandle is considered to be writable if at least one byte of data
68can be written to the underlying file or device without blocking,
69or if an error condition is present on the underlying file or device.
70
71Event-driven I/O works best for filehandles that have been
72placed into nonblocking mode.
73In blocking mode, a C<print> command may block if you give it
74more data than the underlying file or device can accept, and a
75C<E<lt>E<gt>>, C<sysread> or C<read> command will block if you attempt to read
76more data than is ready; no events will be processed while the
77commands block.
78In nonblocking mode C<print>, C<E<lt>E<gt>>, C<sysread> and C<read> never block.
79See the documentation for the individual commands for information
80on how they handle blocking and nonblocking filehandles.
81
82The callback for a file event is executed in the context of I<$widget>
83with which B<fileevent> was invoked.
84If an error occurs while executing the callback then the
85L<Tk::Error> mechanism is used to report the error.
86In addition, the file event handler is deleted if it ever returns
87an error; this is done in order to prevent infinite loops due to
88buggy handlers.
89
90=head1 BUGS
91
92On windows platforms B<fileevent> is limited in the types of filehandles
93that behave correctly. Making filefhandles non-blocking is only implemented
94on a subset of UNIX platforms (see L<Tk::IO>).
95
96=head1 CREDITS
97
98B<fileevent> is based on the B<addinput> command created
99by Mark Diekhans.
100
101=head1 SEE ALSO
102
103L<Tk::IO|Tk::IO>
104L<Tk::callbacks|Tk::callbacks>
105
106=head1 KEYWORDS
107
108asynchronous I/O, blocking, filehandle, event handler, nonblocking, readable,
109callback, writable.
110
111=cut
112