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