ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.pm
(Generate patch)

Comparing IO-AIO/AIO.pm (file contents):
Revision 1.267 by root, Tue Aug 9 11:39:17 2016 UTC vs.
Revision 1.269 by root, Tue Jun 6 04:29:35 2017 UTC

171use common::sense; 171use common::sense;
172 172
173use base 'Exporter'; 173use base 'Exporter';
174 174
175BEGIN { 175BEGIN {
176 our $VERSION = 4.34; 176 our $VERSION = 4.35;
177 177
178 our @AIO_REQ = qw(aio_sendfile aio_seek aio_read aio_write aio_open aio_close 178 our @AIO_REQ = qw(aio_sendfile aio_seek aio_read aio_write aio_open aio_close
179 aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx 179 aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx
180 aio_scandir aio_symlink aio_readlink aio_realpath aio_fcntl aio_ioctl 180 aio_scandir aio_symlink aio_readlink aio_realpath aio_fcntl aio_ioctl
181 aio_sync aio_fsync aio_syncfs aio_fdatasync aio_sync_file_range 181 aio_sync aio_fsync aio_syncfs aio_fdatasync aio_sync_file_range
252 aio_syncfs $fh, $callback->($status) 252 aio_syncfs $fh, $callback->($status)
253 aio_fsync $fh, $callback->($status) 253 aio_fsync $fh, $callback->($status)
254 aio_fdatasync $fh, $callback->($status) 254 aio_fdatasync $fh, $callback->($status)
255 aio_sync_file_range $fh, $offset, $nbytes, $flags, $callback->($status) 255 aio_sync_file_range $fh, $offset, $nbytes, $flags, $callback->($status)
256 aio_pathsync $pathname, $callback->($status) 256 aio_pathsync $pathname, $callback->($status)
257 aio_msync $scalar, $offset = 0, $length = undef, flags = 0, $callback->($status) 257 aio_msync $scalar, $offset = 0, $length = undef, flags = MS_SYNC, $callback->($status)
258 aio_mtouch $scalar, $offset = 0, $length = undef, flags = 0, $callback->($status) 258 aio_mtouch $scalar, $offset = 0, $length = undef, flags = 0, $callback->($status)
259 aio_mlock $scalar, $offset = 0, $length = undef, $callback->($status) 259 aio_mlock $scalar, $offset = 0, $length = undef, $callback->($status)
260 aio_mlockall $flags, $callback->($status) 260 aio_mlockall $flags, $callback->($status)
261 aio_group $callback->(...) 261 aio_group $callback->(...)
262 aio_nop $callback->() 262 aio_nop $callback->()
1350 }; 1350 };
1351 1351
1352 $grp 1352 $grp
1353} 1353}
1354 1354
1355=item aio_msync $scalar, $offset = 0, $length = undef, flags = 0, $callback->($status) 1355=item aio_msync $scalar, $offset = 0, $length = undef, flags = MS_SYNC, $callback->($status)
1356 1356
1357This is a rather advanced IO::AIO call, which only works on mmap(2)ed 1357This is a rather advanced IO::AIO call, which only works on mmap(2)ed
1358scalars (see the C<IO::AIO::mmap> function, although it also works on data 1358scalars (see the C<IO::AIO::mmap> function, although it also works on data
1359scalars managed by the L<Sys::Mmap> or L<Mmap> modules, note that the 1359scalars managed by the L<Sys::Mmap> or L<Mmap> modules, note that the
1360scalar must only be modified in-place while an aio operation is pending on 1360scalar must only be modified in-place while an aio operation is pending on
1362 1362
1363It calls the C<msync> function of your OS, if available, with the memory 1363It calls the C<msync> function of your OS, if available, with the memory
1364area starting at C<$offset> in the string and ending C<$length> bytes 1364area starting at C<$offset> in the string and ending C<$length> bytes
1365later. If C<$length> is negative, counts from the end, and if C<$length> 1365later. If C<$length> is negative, counts from the end, and if C<$length>
1366is C<undef>, then it goes till the end of the string. The flags can be 1366is C<undef>, then it goes till the end of the string. The flags can be
1367a combination of C<IO::AIO::MS_ASYNC>, C<IO::AIO::MS_INVALIDATE> and 1367either C<IO::AIO::MS_ASYNC> or C<IO::AIO::MS_SYNC>, plus an optional
1368C<IO::AIO::MS_SYNC>. 1368C<IO::AIO::MS_INVALIDATE>.
1369 1369
1370=item aio_mtouch $scalar, $offset = 0, $length = undef, flags = 0, $callback->($status) 1370=item aio_mtouch $scalar, $offset = 0, $length = undef, flags = 0, $callback->($status)
1371 1371
1372This is a rather advanced IO::AIO call, which works best on mmap(2)ed 1372This is a rather advanced IO::AIO call, which works best on mmap(2)ed
1373scalars. 1373scalars.
2069manpage for details). The following advice constants are 2069manpage for details). The following advice constants are
2070available: C<IO::AIO::MADV_NORMAL>, C<IO::AIO::MADV_SEQUENTIAL>, 2070available: C<IO::AIO::MADV_NORMAL>, C<IO::AIO::MADV_SEQUENTIAL>,
2071C<IO::AIO::MADV_RANDOM>, C<IO::AIO::MADV_WILLNEED>, C<IO::AIO::MADV_DONTNEED>, 2071C<IO::AIO::MADV_RANDOM>, C<IO::AIO::MADV_WILLNEED>, C<IO::AIO::MADV_DONTNEED>,
2072C<IO::AIO::MADV_FREE>. 2072C<IO::AIO::MADV_FREE>.
2073 2073
2074If C<$offset> is negative, counts from the end. If C<$length> is negative,
2075the remaining length of the C<$scalar> is used. If possible, C<$length>
2076will be reduced to fit into the C<$scalar>.
2077
2074On systems that do not implement C<posix_madvise>, this function returns 2078On systems that do not implement C<posix_madvise>, this function returns
2075ENOSYS, otherwise the return value of C<posix_madvise>. 2079ENOSYS, otherwise the return value of C<posix_madvise>.
2076 2080
2077=item IO::AIO::mprotect $scalar, $offset, $len, $protect 2081=item IO::AIO::mprotect $scalar, $offset, $len, $protect
2078 2082
2079Simply calls the C<mprotect> function on the preferably AIO::mmap'ed 2083Simply calls the C<mprotect> function on the preferably AIO::mmap'ed
2080$scalar (see its manpage for details). The following protect 2084$scalar (see its manpage for details). The following protect
2081constants are available: C<IO::AIO::PROT_NONE>, C<IO::AIO::PROT_READ>, 2085constants are available: C<IO::AIO::PROT_NONE>, C<IO::AIO::PROT_READ>,
2082C<IO::AIO::PROT_WRITE>, C<IO::AIO::PROT_EXEC>. 2086C<IO::AIO::PROT_WRITE>, C<IO::AIO::PROT_EXEC>.
2083 2087
2088If C<$offset> is negative, counts from the end. If C<$length> is negative,
2089the remaining length of the C<$scalar> is used. If possible, C<$length>
2090will be reduced to fit into the C<$scalar>.
2091
2084On systems that do not implement C<mprotect>, this function returns 2092On systems that do not implement C<mprotect>, this function returns
2085ENOSYS, otherwise the return value of C<mprotect>. 2093ENOSYS, otherwise the return value of C<mprotect>.
2086 2094
2087=item IO::AIO::mmap $scalar, $length, $prot, $flags, $fh[, $offset] 2095=item IO::AIO::mmap $scalar, $length, $prot, $flags, $fh[, $offset]
2088 2096
2089Memory-maps a file (or anonymous memory range) and attaches it to the 2097Memory-maps a file (or anonymous memory range) and attaches it to the
2090given C<$scalar>, which will act like a string scalar. Returns true on 2098given C<$scalar>, which will act like a string scalar. Returns true on
2091success, and false otherwise. 2099success, and false otherwise.
2092 2100
2101The scalar must exist, but its contents do not matter - this means you
2102cannot use a nonexistant array or hash element. When in doubt, C<undef>
2103the scalar first.
2104
2093The only operations allowed on the scalar are C<substr>/C<vec> that don't 2105The only operations allowed on the mmapped scalar are C<substr>/C<vec>,
2094change the string length, and most read-only operations such as copying it 2106which don't change the string length, and most read-only operations such
2095or searching it with regexes and so on. 2107as copying it or searching it with regexes and so on.
2096 2108
2097Anything else is unsafe and will, at best, result in memory leaks. 2109Anything else is unsafe and will, at best, result in memory leaks.
2098 2110
2099The memory map associated with the C<$scalar> is automatically removed 2111The memory map associated with the C<$scalar> is automatically removed
2100when the C<$scalar> is destroyed, or when the C<IO::AIO::mmap> or 2112when the C<$scalar> is undef'd or destroyed, or when the C<IO::AIO::mmap>
2101C<IO::AIO::munmap> functions are called. 2113or C<IO::AIO::munmap> functions are called on it.
2102 2114
2103This calls the C<mmap>(2) function internally. See your system's manual 2115This calls the C<mmap>(2) function internally. See your system's manual
2104page for details on the C<$length>, C<$prot> and C<$flags> parameters. 2116page for details on the C<$length>, C<$prot> and C<$flags> parameters.
2105 2117
2106The C<$length> must be larger than zero and smaller than the actual 2118The C<$length> must be larger than zero and smaller than the actual

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines