NAME
UV - Perl interface to libuv
SYNOPSIS
#!/usr/bin/env perl
use strict;
use warnings;
use UV;
# hi-resolution time
my $hi_res_time = UV::hrtime();
# A new loop
my $loop = UV::Loop->new();
# default loop
my $loop = UV::Loop->default_loop(); # convenience constructor
my $loop = UV::Loop->new(1); # Tell the constructor you want the default loop
# run a loop with one of three options:
# UV_RUN_DEFAULT, UV_RUN_ONCE, UV_RUN_NOWAIT
$loop->run(); # runs with UV_RUN_DEFAULT
$loop->run(UV::Loop::UV_RUN_DEFAULT); # explicitly state UV_RUN_DEFAULT
$loop->run(UV::Loop::UV_RUN_ONCE);
$loop->run(UV::Loop::UV_RUN_NOWAIT);
DESCRIPTION
This module provides an interface to libuv. We will try to document things here as best as we can, but we also suggest you look at the libuv docs directly for more details on how things work.
Event loops that work properly on all platforms. YAY!
HELP NEEDED
If you are a C/XS developer, I'm pleading for help. While the test cases so far function as expected, some design decisions I've made up to this point have become somewhat untenable.
Please submit PRs, yell at me on IRC, email me, call me, contact me by any means available to you to help me fix this and get the entirety of the libuv project ready for Perl use.
Thanks!!
CONSTANTS
VERSION CONSTANTS
UV_VERSION_MAJOR
UV_VERSION_MINOR
UV_VERSION_PATCH
UV_VERSION_IS_RELEASE
UV_VERSION_SUFFIX
UV_VERSION_HEX
ERROR CONSTANTS
UV_E2BIG
Argument list too long
UV_EACCES
Permission denied
UV_EADDRINUSE
Address already in use
UV_EADDRNOTAVAIL
Address not available
UV_EAFNOSUPPORT
Address family not supported
UV_EAGAIN
Resource temporarily unavailable
UV_EAI_ADDRFAMILY
Address family not supported
UV_EAI_AGAIN
Temporary failure
UV_EAI_BADFLAGS
Bad ai_flags value
UV_EAI_BADHINTS
Invalid value for hints
UV_EAI_CANCELED
Request canceled
UV_EAI_FAIL
Permanent failure
UV_EAI_FAMILY
ai_family not supported
UV_EAI_MEMORY
Out of memory
UV_EAI_NODATA
No address
UV_EAI_NONAME
Unknown node or service
UV_EAI_OVERFLOW
Argument buffer overflow
UV_EAI_PROTOCOL
Resolved protocol is unknown
UV_EAI_SERVICE
Service not available for socket type
UV_EAI_SOCKTYPE
Socket type not supported
UV_EALREADY
Connection already in progress
UV_EBADF
Bad file descriptor
UV_EBUSY
Resource busy or locked
UV_ECANCELED
Operation canceled
UV_ECHARSET
Invalid Unicode character
UV_ECONNABORTED
Software caused connection abort
UV_ECONNREFUSED
Connection refused
UV_ECONNRESET
Connection reset by peer
UV_EDESTADDRREQ
Destination address required
UV_EEXIST
File already exists
UV_EFAULT
Bad address in system call argument
UV_EFBIG
File too large
UV_EHOSTUNREACH
Host is unreachable
UV_EINTR
Interrupted system call
UV_EINVAL
Invalid argument
UV_EIO
i/o error
UV_EISCONN
Socket is already connected
UV_EISDIR
Illegal operation on a directory
UV_ELOOP
Too many symbolic links encountered
UV_EMFILE
Too many open files
UV_EMLINK
Too many links
UV_EMSGSIZE
Message too long
UV_ENAMETOOLONG
Name too long
UV_ENETDOWN
Network is down
UV_ENETUNREACH
Network is unreachable
UV_ENFILE
File table overflow
UV_ENOBUFS
No buffer space available
UV_ENODEV
No such device
UV_ENOENT
No such file or directory
UV_ENOMEM
Not enough memory
UV_ENONET
Machine is not on the network
UV_ENOPROTOOPT
Protocol not available
UV_ENOSPC
No space left on device
UV_ENOSYS
Function not implemented
UV_ENOTCONN
Socket is not connected
UV_ENOTDIR
Not a directory
UV_ENOTEMPTY
Directory not empty
UV_ENOTSOCK
Socket operation on non-socket
UV_ENOTSUP
Operation not supported on socket
UV_ENXIO
No such device or address
UV_EOF
End of file
UV_EPERM
Operation not permitted
UV_EPIPE
Broken pipe
UV_EPROTO
Protocol error
UV_EPROTONOSUPPORT
Protocol not supported
UV_EPROTOTYPE
Protocol wrong type for socket
UV_ERANGE
Result too large
UV_EROFS
Read-only file system
UV_ESHUTDOWN
Cannot send after transport endpoint shutdown
UV_ESPIPE
Invalid seek
UV_ESRCH
No such process
UV_ETIMEDOUT
Connection timed out
UV_ETXTBSY
Text file is busy
UV_EXDEV
Cross-device link not permitted
UV_UNKNOWN
Unknown error
FUNCTIONS
The following functions are available:
default_loop
my $loop = UV::default_loop();
# You can also get it with the UV::Loop methods below:
my $loop = UV::Loop->default_loop();
my $loop = UV::Loop->default();
# Passing a true value as the first arg to the UV::Loop constructor
# will also return the default loop
my $loop = UV::Loop->new(1);
Returns the default loop (which is a singleton object). This module already creates the default loop and you get access to it with this method.
err_name
my $error_name = UV::err_name(UV::UV_EAI_BADFLAGS);
say $error_name; # EAI_BADFLAGS
The err_name function returns the error name for the given error code. Leaks a few bytes of memory when you call it with an unknown error code.
In libuv errors are negative numbered constants. As a rule of thumb, whenever there is a status parameter, or an API functions returns an integer, a negative number will imply an error.
When a function which takes a callback returns an error, the callback will never be called.
hrtime
my $uint64_t = UV::hrtime();
Get the current Hi-Res time (uint64_t
).
strerror
my $error = UV::strerror(UV::UV_EAI_BADFLAGS);
say $error; # bad ai_flags value
The strerror function returns the error message for the given error code. Leaks a few bytes of memory when you call it with an unknown error code.
In libuv errors are negative numbered constants. As a rule of thumb, whenever there is a status parameter, or an API functions returns an integer, a negative number will imply an error.
When a function which takes a callback returns an error, the callback will never be called.
version
my $int = UV::version();
The version function returns UV::UV_VERSION_HEX
, the libuv version packed into a single integer. 8 bits are used for each component, with the patch number stored in the 8 least significant bits. E.g. for libuv 1.2.3 this would be 0x010203
.
version_string
say UV::version_string();
# 1.13.1
The version_string function returns the libuv version number as a string. For non-release versions the version suffix is included.
AUTHOR
Chase Whitener <capoeirab@cpan.org>
AUTHOR EMERITUS
Daisuke Murase <typester@cpan.org>
COPYRIGHT AND LICENSE
Copyright 2012, Daisuke Murase.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.