Skip Menu |

This queue is for tickets about the POE CPAN distribution.

Report information
The Basics
Id: 20328
Status: resolved
Priority: 0/
Queue: POE

People
Owner: Nobody in particular
Requestors: gbjk [...] thermeon.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: POE::Wheel::ReadWrite flush and autoflush functionality
Adds manual flush method and AutoFlush functionality to POE::Wheel::ReadWrite. Respects water events, hopefully. Feedback welcome. Gareth
Subject: ReadWrite.patch
--- /var/install/cpan/build/POE-0.3502/lib/POE/Wheel/ReadWrite.pm 2006-07-06 15:46:22.000000000 +0100 +++ /usr/local/lib/perl5/site_perl/5.8.4/POE/Wheel/ReadWrite.pm 2006-07-06 16:43:20.000000000 +0100 @@ -28,6 +28,7 @@ sub STATE_WRITE () { 14 } sub STATE_READ () { 15 } sub UNIQUE_ID () { 16 } +sub AUTOFLUSH () { 17 } sub CRIMSON_SCOPE_HACK ($) { 0 } @@ -130,6 +131,7 @@ undef, # STATE_READ # Unique ID. &POE::Wheel::allocate_wheel_id(), # UNIQUE_ID + delete $params{AutoFlush}, # AUTOFLUSH ], $type; if (scalar keys %params) { @@ -421,6 +423,13 @@ $self->[DRIVER_BUFFERED_OUT_OCTETS] = $self->[DRIVER_BOTH]->put($self->[FILTER_OUTPUT]->put(\@chunks)); + if ($self->[AUTOFLUSH] && + $new_buffered_out_octets and !$old_buffered_out_octets) { + $old_buffered_out_octets = $new_buffered_out_octets; + $self->flush(); + $new_buffered_out_octets = $self->[DRIVER_BUFFERED_OUT_OCTETS]; + } + # Resume write-ok if the output buffer gets data. This avoids # redundant calls to select_resume_write(), which is probably a good # thing. @@ -619,6 +628,14 @@ $poe_kernel->select_write($self->[HANDLE_OUTPUT], undef); } +# Flush the output handle +sub flush { + my $self = shift; + return unless defined $self->[HANDLE_OUTPUT]; + $poe_kernel->call($poe_kernel->get_active_session(), + $self->[STATE_WRITE], $self->[HANDLE_OUTPUT]); +} + ############################################################################### 1; @@ -662,6 +679,9 @@ HighEvent => $high_mark_event, # Event to emit when high-water reached LowMark => $low_mark_octets, # Outgoing low-water mark LowEvent => $low_mark_event, # Event to emit when low-water reached + + AutoFlush => $boolean, # Turn on autoflushing of output handle on put() with 1 + # Defaults to 0, no autoflush ); $wheel->put( $something ); @@ -693,6 +713,9 @@ $wheel->shutdown_input(); $wheel->shutdown_output(); + # To flush a wheel's output + $wheel->flush(); + =head1 DESCRIPTION ReadWrite performs buffered, select-based I/O on filehandles. It @@ -793,6 +816,12 @@ they will continue. These methods map directly to shutdown() for the wheel's input and output sockets. +=item flush + +Though the watermarks affect how often a wheel is flushed, in some +cases you might want to manually flush a smaller output, such as +before shutdown_output. + =back =head1 EVENTS AND PARAMETERS
On Thu Jul 06 17:41:30 2006, guest wrote: Show quoted text
> Adds manual flush method and AutoFlush functionality to > POE::Wheel::ReadWrite. > Respects water events, hopefully. > > Feedback welcome. > > Gareth
Hi, Gareth. I finally tested your patch. It passes "make test", which is great, but at least one test (tests/30_loops/10_select/comp_tcp.t) hangs when I hardcode AUTOFLUSH on. As far as I know, Wheel::ReadWrite should work identically with autoflush on or off. If there are unavoidable issues, however, we should try to document them as best as possible.
Hmm. This patch caused lockups in th past, but these days it passes all tests just fine. I've gone ahead and applied it as revision 2199, but I've flagged it "experimental" in the documentation. Thanks for the feature!
Hmm. This patch caused lockups in th past, but these days it passes all tests just fine. I've gone ahead and applied it as revision 2199, but I've flagged it "experimental" in the documentation. Thanks for the feature!
Thanks for the feature. It's applied as revision 2199, but I've flagged it as "experimental" in the docs.