Linux:Perl::aio - asynchronous I/O
#Platform-specific invocation uses e.g.: # Linux::Perl::aio::x86_64->new(...) # Linux::Perl::aio::Control::x86_64->new(...) my $aio = Linux::Perl::aio->new(16); my $ctrl = Linux::Perl::aio::Control->new( $filehandle, \$buffer, lio_opcode => 'PREAD', ); #Multiple $ctrl objects can be submitted in a list. $aio->submit($ctrl); my @events = $aio->getevents( $min, $max, $timeout );
This module provides support for the kernel-level AIO interface.
DESTROY handlers are provided for automatic reaping of unused instances/contexts.
This module is EXPERIMENTAL. For now only the x86_64 architecture is supported; others may follow, though 32-bit architectures would take a bit more work.
x86_64
Calls io_setup with the referred number of events to create an AIO context. An object of CLASS is returned.
io_setup
Returns an instance of the relevant Linux::Perl::aio::Control subclass for your architecture.
FILEHANDLE is a Perl filehandle object, and BUFFER_SR is a reference to the buffer string. This buffer must be pre-initialized to at least the needed/desired length.
%OPTS is:
lio_opcode: Required, one of: PREAD, PWRITE, FSYNC, FDSYNC, NOOP, PREADV, PWRITEV.
lio_opcode
PREAD
PWRITE
FSYNC
FDSYNC
NOOP
PREADV
PWRITEV
buffer_offset: The byte offset in BUFFER_SR at which to start the I/O operation. Defaults to 0.
buffer_offset
nbytes: The number of bytes on which to operate. This value plus buffer_offset must be less than the length of BUFFER_SR. Defaults to length(BUFFER_SR) minus buffer_offset.
nbytes
rw_flags: Optional, an array reference of any or all of: HIPRI, DSYNC, SYNC, NOWAIT, APPEND. Not supported in all kernel versions; in fact, support seems more the exception than the rule! See the kernel documentation (e.g., RWF_HIPRI) for details on what these flags mean and whether your system supports them.
rw_flags
HIPRI
DSYNC
SYNC
NOWAIT
APPEND
RWF_HIPRI
reqprio: Optional. See the kernel’s documentation.
reqprio
eventfd: Optional, an eventfd file descriptor (i.e., unsigned integer) to receive updates when aio events are finished. (See Linux::Perl::eventfd for one way of making this work.)
eventfd
For more information, consult the definition and documentation for struct iocb. (cf. include/linux/aio_abi.h)
iocb
Calls io_submit. Each CTRL* is an instance of Linux::Perl::aio::Control and represets an I/O request.
io_submit
The return value is the number of control objects submitted.
Calls io_getevents with the relevant minimum, maximum, and timeout values. (TIMEOUT can be a float.)
io_getevents
If more than one event is requested (i.e., MAX > 1), then list context is required.
The return is a list of hash references; each hash reference has the following values as in the kernel io_event struct:
io_event
data
obj (corresponds to the Control instance id())
obj
id()
res
res2
Linux::Perl::aio::Control
my $ctrl = Linux::Perl::aio::Control->new( $filehandle, \$buffer, lio_opcode => 'PREAD', buffer_offset => 4, nbytes => 2, );
This class encapsulates a kernel iocb struct, i.e., an I/O request.
You should not instantiate it directly; instead, use Linux::Perl::aio’s create_control() method.
create_control()
Returns the string buffer reference given originally to new().
new()
Returns the internal iocb’s memory address as an octet string.
Returns the internal iocb’s ID.
To install Linux::Perl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Linux::Perl
CPAN shell
perl -MCPAN -e shell install Linux::Perl
For more information on module installation, please visit the detailed CPAN module installation guide.