NAME

UniEvent::Pipe - file streaming abstraction on local machine

SYNOPSIS

    my $loop = UniEvent::Loop->new);
    # just a client
	my $client = UniEvent::Pipe->new($loop);
	$client->connect('/path/to/pipe', sub {
		my ($client, $err) = @_;
        die $err if $err;
        $client->write("hello");

        $client->read_callback(sub {
            my ($handle, $data, $err) = @_;
            die $err if $err;
            say "got $data";
        	$client->shutdown(sub {
        		say "post-shutdown callback";
            });
        });
	});

    # pair of connected sockets
    my ($reader, $writer) = UniEvent::Pipe::pair($loop);

DESCRIPTION

Pipe handles provide an abstraction over streaming files on Unix (including local domain sockets, pipes, and FIFOs) and named pipes on Windows. It is inherited from UniEvent::Stream.

FUNCTIONS

pair($reader, $writer)

pair($loop)

Opens a pair of connected pipes like the corresponding system call. If only $loop argument is specified, then $reader and $writer pipes are created and connected.

If $writer is missing, it will be created.

It returns pair of UniEvent::Pipe handles.

See perlipc and pipe how to work with pair of connected pipes.

METHODS

new([$loop = UniEvent::Loop->default_loop, [$ipc = false]])

Constructs new Pipe handle and binds it to the specified event loop. The $ipc argument is a boolean to indicate if this pipe will be used for handle passing between processes (which may change the bytes on the wire). Only a connected pipe that will be passing the handles should have this flag set, not the listening pipe.

The Pipe hanlde is inherited from UniEvent::Handle.

open($fd, [$connected = false])

Open an existing file descriptor $fd as a pipe. The $connected flag marks the connected state of the stream (see UniEvent::Stream).

bind($name)

Bind the pipe to a file path (Unix) or a name (Windows). On windows it should be something like "\\\\.\\pipe\\$name".

connect($name [, $callback = undef]).

Connect to the Unix domain socket or the named pipe. Optionally the $callback can be specified, which will be called upon connect. The C++ signature is:

void(const StreamSP& handle, const ErrorCode& err, const ConnectRequestSP& req)

i.e. it will be invoked as:

$callback->($pipe_handle, $error_code, $connect_request)

The method returns connect_request, using which the connection request can be tracked.

sockname()

Get the name of the Unix domain socket or the named pipe.

peername()

Get the name of the Unix domain socket or the named pipe which the handle is connected to.

pending_instances($count)

Set the number of pending pipe instance handles when the pipe server is waiting for connections. Applicable for Windows only.

CONSTANTS

TYPE

Pipe type constant

REFERENCES

UniEvent::Handle

UniEvent::Stream

UniEvent::Request::Connect

XS::Framework::CallbackDispatcher