home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _3d05d0a5dede387f9150de6763cafd82 < prev    next >
Text File  |  2000-03-23  |  7KB  |  142 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Tk::fileevent - Execute a callback when a filehandle becomes readable or writable</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> Tk::fileevent - Execute a callback when a filehandle becomes readable or writable</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#bugs">BUGS</A></LI>
  26.     <LI><A HREF="#credits">CREDITS</A></LI>
  27.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  28.     <LI><A HREF="#keywords">KEYWORDS</A></LI>
  29. </UL>
  30. <!-- INDEX END -->
  31.  
  32. <HR>
  33. <P>
  34. <H1><A NAME="name">NAME</A></H1>
  35. <P>Tk::fileevent - Execute a callback when a filehandle becomes readable or writable</P>
  36. <P>
  37. <HR>
  38. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  39. <UL>
  40. <LI>Linux</LI>
  41. <LI>Solaris</LI>
  42. <LI>Windows</LI>
  43. </UL>
  44. <HR>
  45. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  46. <P><EM>$widget</EM>-><STRONG>fileevent</STRONG>(<EM>fileHandle</EM>,<STRONG>readable</STRONG>?,<EM>callback</EM>?)</P>
  47. <P><EM>$widget</EM>-><STRONG>fileevent</STRONG>(<EM>fileHandle</EM>,<STRONG>writable</STRONG>?,<EM>callback</EM>?)</P>
  48. <P>
  49. <HR>
  50. <H1><A NAME="description">DESCRIPTION</A></H1>
  51. <P>This command is used to create <EM>file event handlers</EM>.  A file event
  52. handler is a binding between a filehandle and a callback, such that the callback
  53. is evaluated whenever the filehandle becomes readable or writable.  File event
  54. handlers are most commonly used to allow data to be received from another
  55. process on an event-driven basis, so that the receiver can continue to
  56. interact with the user while waiting for the data to arrive.  If an
  57. application invokes <CODE><></CODE>, <A HREF="../../../lib/Pod/perlfunc.html#item_sysread"><CODE>sysread</CODE></A> or <A HREF="../../../lib/Pod/perlfunc.html#item_read"><CODE>read</CODE></A> on a blocking filehandle when
  58. there is no input data available, the process will block; until the input
  59. data arrives, it will not be able to service other events, so it will
  60. appear to the user to ``freeze up''.  With <STRONG>fileevent</STRONG>, the process can
  61. tell when data is present and only invoke <STRONG>gets</STRONG> or <STRONG>read</STRONG> when
  62. they won't block.</P>
  63. <P>The <EM>fileHandle</EM> argument to <STRONG>fileevent</STRONG> refers to an open filehandle,
  64. such as the return value from a previous <STRONG>open</STRONG> or <STRONG>socket</STRONG>
  65. command.
  66. If the <EM>callback</EM> argument is specified, then <STRONG>fileevent</STRONG>
  67. creates a new event handler:  <EM>callback</EM> will be evaluated
  68. whenever the filehandle becomes readable or writable (depending on the
  69. argument to <STRONG>fileevent</STRONG>).
  70. In this case <STRONG>fileevent</STRONG> returns an empty string.
  71. The <STRONG>readable</STRONG> and <STRONG>writable</STRONG> event handlers for a file
  72. are independent, and may be created and deleted separately.
  73. However, there may be at most one <STRONG>readable</STRONG> and one <STRONG>writable</STRONG>
  74. handler for a file at a given time in a given interpreter.
  75. If <STRONG>fileevent</STRONG> is called when the specified handler already
  76. exists in the invoking interpreter, the new callback replaces the old one.</P>
  77. <P>If the <EM>callback</EM> argument is not specified, <STRONG>fileevent</STRONG>
  78. returns the current callback for <EM>fileHandle</EM>, or an empty string
  79. if there is none.
  80. If the <EM>callback</EM> argument is specified as an empty string
  81. then the event handler is deleted, so that no callback will be invoked.
  82. A file event handler is also deleted automatically whenever
  83. its filehandle is closed or its interpreter is deleted.</P>
  84. <P>A filehandle is considered to be readable if there is unread data
  85. available on the underlying device.
  86. A filehandle is also considered to be readable if an end of file or
  87. error condition is present on the underlying file or device.
  88. It is important for <EM>callback</EM> to check for these conditions
  89. and handle them appropriately;  for example, if there is no special
  90. check for end of file, an infinite loop may occur where <EM>callback</EM>
  91. reads no data, returns, and is immediately invoked again.</P>
  92. <P>A filehandle is considered to be writable if at least one byte of data
  93. can be written to the underlying file or device without blocking,
  94. or if an error condition is present on the underlying file or device.</P>
  95. <P>Event-driven I/O works best for filehandles that have been
  96. placed into nonblocking mode.
  97. In blocking mode, a <A HREF="../../../lib/Pod/perlfunc.html#item_print"><CODE>print</CODE></A> command may block if you give it
  98. more data than the underlying file or device can accept, and a
  99. <CODE><></CODE>, <A HREF="../../../lib/Pod/perlfunc.html#item_sysread"><CODE>sysread</CODE></A> or <A HREF="../../../lib/Pod/perlfunc.html#item_read"><CODE>read</CODE></A> command will block if you attempt to read
  100. more data than is ready;  no events will be processed while the
  101. commands block.
  102. In nonblocking mode <A HREF="../../../lib/Pod/perlfunc.html#item_print"><CODE>print</CODE></A>, <CODE><></CODE>, <A HREF="../../../lib/Pod/perlfunc.html#item_sysread"><CODE>sysread</CODE></A> and <A HREF="../../../lib/Pod/perlfunc.html#item_read"><CODE>read</CODE></A> never block.
  103. See the documentation for the individual commands for information
  104. on how they handle blocking and nonblocking filehandles.</P>
  105. <P>The callback for a file event is executed in the context of <EM>$widget</EM>
  106. with which <STRONG>fileevent</STRONG> was invoked.
  107. If an error occurs while executing the callback then the
  108. <A HREF="../../../site/lib/Tk/Error.html">the Tk::Error manpage</A> mechanism is used to report the error.
  109. In addition, the file event handler is deleted if it ever returns
  110. an error;  this is done in order to prevent infinite loops due to
  111. buggy handlers.</P>
  112. <P>
  113. <HR>
  114. <H1><A NAME="bugs">BUGS</A></H1>
  115. <P>On windows platforms <STRONG>fileevent</STRONG> is limited in the types of filehandles
  116. that behave correctly. Making filefhandles non-blocking is only implemented
  117. on a subset of UNIX platforms (see <A HREF="../../../site/lib/Tk/IO.html">the Tk::IO manpage</A>).</P>
  118. <P>
  119. <HR>
  120. <H1><A NAME="credits">CREDITS</A></H1>
  121. <P><STRONG>fileevent</STRONG> is based on the <STRONG>addinput</STRONG> command created
  122. by Mark Diekhans.</P>
  123. <P>
  124. <HR>
  125. <H1><A NAME="see also">SEE ALSO</A></H1>
  126. <P><A HREF="../../../site/lib/Tk/IO.html">Tk::IO</A>
  127. <A HREF="../../../site/lib/Tk/callbacks.html">Tk::callbacks</A></P>
  128. <P>
  129. <HR>
  130. <H1><A NAME="keywords">KEYWORDS</A></H1>
  131. <P>asynchronous I/O, blocking, filehandle, event handler, nonblocking, readable,
  132. callback, writable.</P>
  133. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  134. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  135. <STRONG><P CLASS=block> Tk::fileevent - Execute a callback when a filehandle becomes readable or writable</P></STRONG>
  136. </TD></TR>
  137. </TABLE>
  138.  
  139. </BODY>
  140.  
  141. </HTML>
  142.