The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

POE::Driver::SysRW - an abstract sysread/syswrite file driver

SYNOPSIS

  $driver = POE::Driver::SysRW->new();
  $arrayref_of_data_chunks = $driver->get($filehandle);
  $queue_octets = $driver->put($arrayref_of_data_chunks);
  $queue_octets = $driver->flush($filehandle);
  $queue_messages = $driver->get_out_messages_buffered();

DESCRIPTION

This driver implements an abstract interface to sysread and syswrite.

PUBLIC METHODS

new BlockSize => $block_size
new

new() creates a new SysRW driver. It accepts one optional named parameter, BlockSize, which indicates the maximum number of octets it will read at a time. For speed, syswrite() tries to send as much information as it can.

BlockSize defaults to 65536 if it is omitted. Higher values improve performance in high-throughput applications at the expense of consuming more resident memory. Lower values reduce memory consumption with corresponding throughput penalties.

  my $driver = POE::Driver::SysRW->new( BlockSize => $block_size );

  my $driver = POE::Driver::SysRW->new;
get FILEHANDLE

get() immediately tries to read information from a filehandle. It returns a reference to an array containing whatever it managed to read, or an empty array if nothing could be read. It returns undef on error, and $! will be set.

The arrayref get() returns is suitable for passing to any POE::Filter's get() method. This is exactly what the ReadWrite wheel does with it.

put ARRAYREF

put() places raw data chunks into the driver's output queue. it accepts a reference to a list of raw data chunks, and it returns the number of octets remaining in its output queue.

Some drivers may flush data immediately from their put() methods.

flush FILEHANDLE

flush() attempts to flush some data from the driver's output queue to the FILEHANDLE. It returns the number of octets remaining in the output queue after the flush attempt.

flush() does the physical write, counterpoint to get's read. If flush() fails for any reason, $! will be set with the reason for its failure. Otherwise $! will be zero.

get_out_messages_buffered

This data accessor returns the number of messages in the driver's output queue. Partial messages are counted as whole ones.

DESIGN NOTES

Driver::SysRW uses a queue of output messages. This means that BLOCK_SIZE is not used for writing. Rather, each message put() through the driver is written in its entirety (or not, if it fails). This often means more syswrite() calls than necessary, however it makes memory management much easier.

If the driver used a scalar buffer for output, it would be necessary to use substr() to remove the beginning of it after it was written. Each substr() call requires the end of the string be moved down to its beginning. That is a lot of memory copying.

The buffer could be allowed to grow until it has flushed entirely. This would be eliminate extra memory copies entirely, but it would then be possible to create programs where the buffer was not allowed to shrink at all. That would quickly become bad.

Better ideas are welcome.

SEE ALSO

POE::Driver.

The SEE ALSO section in POE contains a table of contents covering the entire POE distribution.

AUTHORS & COPYRIGHTS

Please see POE for more information about authors and contributors.