home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_c7aa4e056464fe8d4cbe7bfa0dc149c0
< prev
next >
Wrap
Text File
|
2000-03-23
|
6KB
|
175 lines
<HTML>
<HEAD>
<TITLE>POE::Wheel::ReadWrite - POE Read/Write Logic Abstraction</TITLE>
<LINK REL="stylesheet" HREF="../../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> POE::Wheel::ReadWrite - POE Read/Write Logic Abstraction</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<LI><A HREF="#public methods">PUBLIC METHODS</A></LI>
<LI><A HREF="#events and parameters">EVENTS AND PARAMETERS</A></LI>
<LI><A HREF="#see also">SEE ALSO</A></LI>
<LI><A HREF="#bugs">BUGS</A></LI>
<LI><A HREF="#authors & copyrights">AUTHORS & COPYRIGHTS</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>POE::Wheel::ReadWrite - POE Read/Write Logic Abstraction</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
$wheel = new POE::Wheel::ReadWrite(</PRE>
<PRE>
# To read and write from the same handle, such as a socket, use
# the Handle parameter:
Handle => $file_or_socket_handle, # Handle to read/write</PRE>
<PRE>
# To read and write from different handles, such as a dual pipe to
# a child process, or a console, use InputHandle and OutputHandle:
InputHandle => $readable_filehandle, # Handle to read
OutputHandle => $writable_filehandle, # Handle to write</PRE>
<PRE>
Driver => new POE::Driver::Something(), # How to read/write it
Filter => new POE::Filter::Something(), # How to parse it
InputState => $input_state_name, # Input received state
FlushedState => $flush_state_name, # Output flushed state
ErrorState => $error_state_name, # Error occurred state
);</PRE>
<PRE>
$wheel->put( $something );
$wheel->event( ... );
$wheel->set_filter( new POE::Filter::Something );</PRE>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>The ReadWrite wheel does buffered, select-based I/O on a filehandle.
It generates events for common file conditions, such as when data has
been read or flushed. This wheel includes a <CODE>put()</CODE> method.</P>
<P>
<HR>
<H1><A NAME="public methods">PUBLIC METHODS</A></H1>
<UL>
<LI>
POE::Wheel::ReadWrite::put($logical_data_chunk)
<P>The <CODE>put()</CODE> method uses a POE::Filter to translate the logical data
chunk into a serialized (streamable) representation. It then uses a
POE::Driver to enqueue or write the data to a filehandle. It also
manages the wheel's write select so that any buffered data can be
flushed when the handle is ready.</P>
<P></P>
<LI>
POE::Wheel::ReadWrite::event(...)
<P>Please see POE::Wheel.</P>
<P></P>
<LI>
POE::Wheel::ReadWrite::set_filter( $poe_filter )
<P>The set_filter method changes the filter that the ReadWrite wheel uses
to translate between streams and logical chunks of data. It uses
filters' <CODE>get_pending()</CODE> method to preserve any buffered data between
the previous and new filters.</P>
<P>Please be aware that this method has complex and perhaps non-obvious
side effects. The description of POE::Filter::get_pending() discusses
them further.</P>
<P>POE::Filter::HTTPD does not support the <CODE>get_pending()</CODE> method.
Switching from an HTTPD filter to another one will display a reminder
that it sn't supported.</P>
<P></P></UL>
<P>
<HR>
<H1><A NAME="events and parameters">EVENTS AND PARAMETERS</A></H1>
<UL>
<LI>
InputState
<P>The InputState event contains the name of the state that will be
called for each chunk of logical data returned by the ReadWrite
wheel's filter.</P>
<P>The ARG0 parameter contains the chunk of logical data that was
received.</P>
<P>A sample InputState state:</P>
<PRE>
sub input_state {
my ($heap, $input) = @_[HEAP, ARG0];
print "Echoing input: $input\n";
$heap->{wheel}->put($input); # Echo it back.
}</PRE>
<P></P>
<LI>
FlushedState
<P>The FlushedState event contains the name of the state that will be
called whenever the wheel's driver's output queue becomes empty. This
signals that all pending data has been written. It does not include
parameters.</P>
<P>A sample FlushedState state:</P>
<PRE>
sub flushed_state {
# Stop the wheel after all outgoing data is flushed.
# This frees the wheel's resources, including the
# filehandle, and closes the connection.
delete $_[HEAP]->{wheel};
}</PRE>
<P></P>
<LI>
ErrorState
<P>The ErrorState event contains the name of the state that will be
called when a file error occurs. The ReadWrite wheel knows what to do
with EAGAIN, so it's not considered a true error.</P>
<P>The ARG0 parameter contains the name of the function that failed.
ARG1 and ARG2 contain the numeric and string versions of $! at the
time of the error, respectively.</P>
<P>A sample ErrorState state:</P>
<PRE>
sub error_state {
my ($operation, $errnum, $errstr) = @_[ARG0, ARG1, ARG2];
warn "$operation error $errnum: $errstr\n";
}</PRE>
<P></P></UL>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P>POE::Wheel; POE::Wheel::FollowTail; POE::Wheel::ListenAccept;
POE::Wheel::SocketFactory</P>
<P>
<HR>
<H1><A NAME="bugs">BUGS</A></H1>
<P>Oh, probably some.</P>
<P>
<HR>
<H1><A NAME="authors & copyrights">AUTHORS & COPYRIGHTS</A></H1>
<P>Please see the POE manpage.</P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> POE::Wheel::ReadWrite - POE Read/Write Logic Abstraction</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>