UV::Pipe - Pipe stream handles in libuv
#!/usr/bin/env perl use strict; use warnings; # A new stream handle will be initialised against the default loop my $pipe = UV::Pipe->new; $pipe->connect("server.sock", sub { say "Connected!"; $pipe->write("Hello, server!\n"); }); # set up the data read callback $pipe->on(read => sub { my ($self, $err, $buf) = @_; say "More data: $buf"; }); $pipe->read_start();
This module provides an interface to libuv's pipe stream handle.
Pipe handles represent a FIFO or UNIX ("local") socket.
UV::Pipe inherits all events from UV::Stream and UV::Handle.
UV::Pipe inherits all methods from UV::Stream and UV::Handle and also makes the following extra methods available.
$pipe->open($fh);
The open method associates the pipe with an existing filehandle already opened by the process.
$pipe->bind($path);
The bind method associates the pipe with a UNIX socket path or named filehandle, which will be created on the filesystem.
$pipe->connect($path, sub { my ($err) = @_; die "Cannot connect pipe - $err\n" if $err; say "The pipe is now connected"; });
The connect method requests that the pipe be connected a server found on the given path.
On completion the callback is invoked. It is passed undef on success, or an error value on failure. This error value can be compared numerically to one of the UV_E* constants, or printed as a string to give a message.
undef
UV_E*
my $path = $pipe->getpeername;
The getpeername method returns the filesystem path to which this pipe handle is connected.
my $path = $pipe->getsockname;
The getsockname method returns the filesystem path on which this pipe server handle is listening for incoming connections.
$pipe->chmod($flags);
The chmod method sets the filesystem permissions on the named pipe or socket to allow access by other users. $flags should be a bitmask of UV_READABLE or UV_WRITABLE.
$flags
UV_READABLE
UV_WRITABLE
Paul Evans <leonerd@leonerd.org.uk>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install UV, copy and paste the appropriate command in to your terminal.
cpanm
cpanm UV
CPAN shell
perl -MCPAN -e shell install UV
For more information on module installation, please visit the detailed CPAN module installation guide.