… | |
… | |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use IO::AIO; |
7 | use IO::AIO; |
8 | |
8 | |
9 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
9 | aio_open "/etc/passwd", IO::AIO::O_RDONLY, 0, sub { |
10 | my $fh = shift |
10 | my $fh = shift |
11 | or die "/etc/passwd: $!"; |
11 | or die "/etc/passwd: $!"; |
12 | ... |
12 | ... |
13 | }; |
13 | }; |
14 | |
14 | |
… | |
… | |
76 | |
76 | |
77 | # register the IO::AIO callback with EV |
77 | # register the IO::AIO callback with EV |
78 | my $aio_w = EV::io IO::AIO::poll_fileno, EV::READ, \&IO::AIO::poll_cb; |
78 | my $aio_w = EV::io IO::AIO::poll_fileno, EV::READ, \&IO::AIO::poll_cb; |
79 | |
79 | |
80 | # queue the request to open /etc/passwd |
80 | # queue the request to open /etc/passwd |
81 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
81 | aio_open "/etc/passwd", IO::AIO::O_RDONLY, 0, sub { |
82 | my $fh = shift |
82 | my $fh = shift |
83 | or die "error while opening: $!"; |
83 | or die "error while opening: $!"; |
84 | |
84 | |
85 | # stat'ing filehandles is generally non-blocking |
85 | # stat'ing filehandles is generally non-blocking |
86 | my $size = -s $fh; |
86 | my $size = -s $fh; |
… | |
… | |
168 | use common::sense; |
168 | use common::sense; |
169 | |
169 | |
170 | use base 'Exporter'; |
170 | use base 'Exporter'; |
171 | |
171 | |
172 | BEGIN { |
172 | BEGIN { |
173 | our $VERSION = '3.5'; |
173 | our $VERSION = '3.65'; |
174 | |
174 | |
175 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close |
175 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close |
176 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx |
176 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx |
177 | aio_scandir aio_symlink aio_readlink aio_sync aio_fsync |
177 | aio_scandir aio_symlink aio_readlink aio_sync aio_fsync |
178 | aio_fdatasync aio_sync_file_range aio_pathsync aio_readahead |
178 | aio_fdatasync aio_sync_file_range aio_pathsync aio_readahead |
… | |
… | |
352 | by the umask in effect then the request is being executed, so better never |
352 | by the umask in effect then the request is being executed, so better never |
353 | change the umask. |
353 | change the umask. |
354 | |
354 | |
355 | Example: |
355 | Example: |
356 | |
356 | |
357 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
357 | aio_open "/etc/passwd", IO::AIO::O_RDONLY, 0, sub { |
358 | if ($_[0]) { |
358 | if ($_[0]) { |
359 | print "open successful, fh is $_[0]\n"; |
359 | print "open successful, fh is $_[0]\n"; |
360 | ... |
360 | ... |
361 | } else { |
361 | } else { |
362 | die "open failed: $!\n"; |
362 | die "open failed: $!\n"; |
… | |
… | |
1580 | C<IO::AIO::MAP_NORESERVE>, C<IO::AIO::MAP_POPULATE> or |
1580 | C<IO::AIO::MAP_NORESERVE>, C<IO::AIO::MAP_POPULATE> or |
1581 | C<IO::AIO::MAP_NONBLOCK> |
1581 | C<IO::AIO::MAP_NONBLOCK> |
1582 | |
1582 | |
1583 | If C<$fh> is C<undef>, then a file descriptor of C<-1> is passed. |
1583 | If C<$fh> is C<undef>, then a file descriptor of C<-1> is passed. |
1584 | |
1584 | |
|
|
1585 | C<$offset> is the offset from the start of the file - it generally must be |
|
|
1586 | a multiple of C<IO::AIO::PAGESIZE> and defaults to C<0>. |
|
|
1587 | |
|
|
1588 | Example: |
|
|
1589 | |
|
|
1590 | use Digest::MD5; |
|
|
1591 | use IO::AIO; |
|
|
1592 | |
|
|
1593 | open my $fh, "<verybigfile" |
|
|
1594 | or die "$!"; |
|
|
1595 | |
|
|
1596 | IO::AIO::mmap my $data, -s $fh, IO::AIO::PROT_READ, IO::AIO::MAP_SHARED, $fh |
|
|
1597 | or die "verybigfile: $!"; |
|
|
1598 | |
|
|
1599 | my $fast_md5 = md5 $data; |
|
|
1600 | |
1585 | =item IO::AIO::munmap $scalar |
1601 | =item IO::AIO::munmap $scalar |
1586 | |
1602 | |
1587 | Removes a previous mmap and undefines the C<$scalar>. |
1603 | Removes a previous mmap and undefines the C<$scalar>. |
1588 | |
1604 | |
1589 | =item IO::AIO::mlockall $flags |
1605 | =item IO::AIO::mlockall $flags |