NAME

UniEvent::Streamer - generic connector for read and write streams

SYNOPSIS

use UniEvent;

# let's stream self for target connection
my $loop   = UE::Loop->default_loop;
my $client = UE::Tcp->new;
... # connect

my $input    = UE::Streamer::FileInput->new(__FILE__);
my $output   = UE::Streamer::StreamOutput->new($client);
my $streamer = UE::Streamer->new($input, $output);
$streamer->start();
$streamer->finish_callback(sub { $loop->stop; });
$loop->run;

DESCRIPTION

Streamer redirects byte stream from input stream (aka producer) into output stream (aka consumer). It automatically adjusts input stream speed if the consumer it too slow; to implement that the internal temporally buffer is used.

Any input and output combination is possible, i.e. read data from file and stream it into network over TCP connection, or read data from TTY and stream it into Pipe. Pure perl input / output is also possible to allow custom processing.

METHODS

new($input, $output [, $max_buf = 10_000_000] [$loop = UniEvent::Loop->default_loop])

Constructs new Streamer object, connecting $intput sink to $output using intermediate buffer of $max_buf size bytes.

start()

Starts the streamer, i.e. makes it active for the next even loop iteration.

stop()

Stops the streamer, i.e. makes it inactive for the next event loop iteration.

finish_callback($code)

Sets the callback, which will be invoked upon streaming completion. All previously set event listeners or callbacks are discarded.

finish_event()

Returns XS::Framework::CallbackDispatcher instance, where callback(s) can be assigned with. The callbacks will be invoked upon streaming completion.

The C++ interface is:

void(const ErrorCode& err)

On perl side it the callbacks will be called :

$callback->($error_code);

Multiple callbacks can be added via the XS::Framework::CallbackDispatcher interface.

REFERENCES

UniEvent::Streamer::IInput

UniEvent::Streamer::Input

UniEvent::Streamer::Output

UniEvent::Streamer::IOutput

UniEvent::Streamer::FileInput

UniEvent::Streamer::FileOutput

UniEvent::Streamer::StreamInput

UniEvent::Streamer::StreamOutput

XS::Framework::CallbackDispatcher