Philip Gwyn > POE-Wheel-Sendfile > POE::Wheel::Sendfile

Download:
POE-Wheel-Sendfile-0.0200.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.0200   Source  

NAME ^

POE::Wheel::Sendfile - Extend POE::Wheel::ReadWrite with sendfile

SYNOPSIS ^

    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};
    }

DESCRIPTION ^

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.

METHODS ^

POE::Wheel::Sendfile only adds one public method to the interface:

sendfile

    $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 => $FILE

An open filehandle or the name of a file.

offset => $OFFSET

Byte offset from which the sending will start. Optional, defaults to 0.

size => $SIZE

Number of bytes to send. Defaults to the entire file.

blocksize => $BLKSIZE

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).

SEE ALSO ^

POE, POE::Wheel::ReadWrite.

AUTHOR ^

Philip Gwyn, <gwyn -at- cpan.org>

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: