… | |
… | |
171 | use common::sense; |
171 | use common::sense; |
172 | |
172 | |
173 | use base 'Exporter'; |
173 | use base 'Exporter'; |
174 | |
174 | |
175 | BEGIN { |
175 | BEGIN { |
176 | our $VERSION = 4.35; |
176 | our $VERSION = 4.4; |
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 |
… | |
… | |
183 | aio_rename aio_rename2 aio_link aio_move aio_copy aio_group |
183 | aio_rename aio_rename2 aio_link aio_move aio_copy aio_group |
184 | aio_nop aio_mknod aio_load aio_rmtree aio_mkdir aio_chown |
184 | aio_nop aio_mknod aio_load aio_rmtree aio_mkdir aio_chown |
185 | aio_chmod aio_utime aio_truncate |
185 | aio_chmod aio_utime aio_truncate |
186 | aio_msync aio_mtouch aio_mlock aio_mlockall |
186 | aio_msync aio_mtouch aio_mlock aio_mlockall |
187 | aio_statvfs |
187 | aio_statvfs |
|
|
188 | aio_slurp |
188 | aio_wd); |
189 | aio_wd); |
189 | |
190 | |
190 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); |
191 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); |
191 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
192 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
192 | min_parallel max_parallel max_idle idle_timeout |
193 | min_parallel max_parallel max_idle idle_timeout |
… | |
… | |
926 | C<$type>'s are known, which can be used to speed up some algorithms. |
927 | C<$type>'s are known, which can be used to speed up some algorithms. |
927 | |
928 | |
928 | =back |
929 | =back |
929 | |
930 | |
930 | |
931 | |
|
|
932 | =item aio_slurp $pathname, $offset, $length, $data, $callback->($status) |
|
|
933 | |
|
|
934 | Opens, reads and closes the given file. The data is put into C<$data>, |
|
|
935 | which is resized as required. |
|
|
936 | |
|
|
937 | If C<$offset> is negative, then it is counted from the end of the file. |
|
|
938 | |
|
|
939 | If C<$length> is zero, then the remaining length of the file is |
|
|
940 | used. Also, in this case, the same limitations to modifying C<$data> apply |
|
|
941 | as when IO::AIO::mmap is used, i.e. it must only be modified in-place |
|
|
942 | with C<substr>. If the size of the file is known, specifying a non-zero |
|
|
943 | C<$length> results in a performance advantage. |
|
|
944 | |
|
|
945 | This request is similar to the older C<aio_load> request, but since it is |
|
|
946 | a single request, it might be more efficient to use. |
|
|
947 | |
|
|
948 | Example: load F</etc/passwd> into C<$passwd>. |
|
|
949 | |
|
|
950 | my $passwd; |
|
|
951 | aio_slurp "/etc/passwd", 0, 0, $passwd, sub { |
|
|
952 | $_[0] >= 0 |
|
|
953 | or die "/etc/passwd: $!\n"; |
|
|
954 | |
|
|
955 | printf "/etc/passwd is %d bytes long, and contains:\n", length $passwd; |
|
|
956 | print $passwd; |
|
|
957 | }; |
|
|
958 | IO::AIO::flush; |
|
|
959 | |
|
|
960 | |
931 | =item aio_load $pathname, $data, $callback->($status) |
961 | =item aio_load $pathname, $data, $callback->($status) |
932 | |
962 | |
933 | This is a composite request that tries to fully load the given file into |
963 | This is a composite request that tries to fully load the given file into |
934 | memory. Status is the same as with aio_read. |
964 | memory. Status is the same as with aio_read. |
|
|
965 | |
|
|
966 | Using C<aio_slurp> might be more efficient, as it is a single request. |
935 | |
967 | |
936 | =cut |
968 | =cut |
937 | |
969 | |
938 | sub aio_load($$;$) { |
970 | sub aio_load($$;$) { |
939 | my ($path, undef, $cb) = @_; |
971 | my ($path, undef, $cb) = @_; |