POE::Wheel::Sendfile - Extend POE::Wheel::ReadWrite with sendfile
use POE::Wheel::Sendfile; my $wheel = POE::Wheel::Sendfile->new( Handle => $socket, InputEvent => 'input', FlushedEvent => 'flushed', ); $heap->{wheel} = $wheel; sub input { $heap->{wheel}->sendfile( $file ); } sub flushed { delete $heap->{wheel}; }
POE::Wheel::Sendfile extends POE::Wheel::ReadWrite and adds the possibility of using the sendfile system call to transfer data as efficiently.
It is created just like a POE::Wheel::ReadWrite would be. When you want to send a file, you call "sendfile". When sendfile is done, your FlushedEvent will be invoked.
POE::Wheel::Sendfile uses Sys::Sendfile for portable sendfile. If it is not available, it falls back to using sysread and syswrite.
POE::Wheel::Sendfile only adds one public method to the interface:
$wheel->sendfile( $FILE ); $wheel->sendfile( { file => $FILE, [ offset => $OFFSET, ] [ size => $SIZE, ] [ blocksize => $BLKSIZE ] } );
Sends $FILE over the wheel's socket. Optionnaly starting at $OFFSET. If Sys::Sendfile is not available, will fall back to sending the file in $BLKSIZE chunks with sysread.
$FILE
$OFFSET
$BLKSIZE
An open filehandle or the name of a file.
Byte offset from which the sending will start. Optional, defaults to 0.
Number of bytes to send. Defaults to the entire file.
If Sys::Sendfile is not available, POE::Wheel::Sendfile will fall back to using sysread and syswrite. It will read and write $BLKSIZE bytes at once. If omited, the socket's SO_SNDBUF size is used. If that is unavailable, the block size is 7500 bytes (5 ethernet frames).
SO_SNDBUF
POE, POE::Wheel::ReadWrite.
Philip Gwyn, <gwyn -at- cpan.org>
Copyright (C) 2010, 2011 by Philip Gwyn
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install POE::Wheel::Sendfile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Wheel::Sendfile
CPAN shell
perl -MCPAN -e shell install POE::Wheel::Sendfile
For more information on module installation, please visit the detailed CPAN module installation guide.