… | |
… | |
61 | etc.), but can also be used to easily do operations in parallel that are |
61 | etc.), but can also be used to easily do operations in parallel that are |
62 | normally done sequentially, e.g. stat'ing many files, which is much faster |
62 | normally done sequentially, e.g. stat'ing many files, which is much faster |
63 | on a RAID volume or over NFS when you do a number of stat operations |
63 | on a RAID volume or over NFS when you do a number of stat operations |
64 | concurrently. |
64 | concurrently. |
65 | |
65 | |
66 | While this works on all types of file descriptors (for example sockets), |
66 | While most of this works on all types of file descriptors (for example |
67 | using these functions on file descriptors that support nonblocking |
67 | sockets), using these functions on file descriptors that support |
68 | operation (again, sockets, pipes etc.) is very inefficient. Use an event |
68 | nonblocking operation (again, sockets, pipes etc.) is very inefficient or |
|
|
69 | might not work (aio_read fails on sockets/pipes/fifos). Use an event loop |
69 | loop for that (such as the L<Event|Event> module): IO::AIO will naturally |
70 | for that (such as the L<Event|Event> module): IO::AIO will naturally fit |
70 | fit into such an event loop itself. |
71 | into such an event loop itself. |
71 | |
72 | |
72 | In this version, a number of threads are started that execute your |
73 | In this version, a number of threads are started that execute your |
73 | requests and signal their completion. You don't need thread support |
74 | requests and signal their completion. You don't need thread support |
74 | in perl, and the threads created by this module will not be visible |
75 | in perl, and the threads created by this module will not be visible |
75 | to perl. In the future, this module might make use of the native aio |
76 | to perl. In the future, this module might make use of the native aio |
… | |
… | |
188 | use strict 'vars'; |
189 | use strict 'vars'; |
189 | |
190 | |
190 | use base 'Exporter'; |
191 | use base 'Exporter'; |
191 | |
192 | |
192 | BEGIN { |
193 | BEGIN { |
193 | our $VERSION = '2.1'; |
194 | our $VERSION = '2.2'; |
194 | |
195 | |
195 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
196 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
196 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
197 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
197 | aio_fsync aio_fdatasync aio_readahead aio_rename aio_link aio_move |
198 | aio_readlink aio_fsync aio_fdatasync aio_readahead aio_rename aio_link |
198 | aio_copy aio_group aio_nop aio_mknod); |
199 | aio_move aio_copy aio_group aio_nop aio_mknod); |
199 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); |
200 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); |
200 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
201 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
201 | min_parallel max_parallel max_idle |
202 | min_parallel max_parallel max_idle |
202 | nreqs nready npending nthreads |
203 | nreqs nready npending nthreads |
203 | max_poll_time max_poll_reqs); |
204 | max_poll_time max_poll_reqs); |
… | |
… | |
416 | |
417 | |
417 | =item aio_symlink $srcpath, $dstpath, $callback->($status) |
418 | =item aio_symlink $srcpath, $dstpath, $callback->($status) |
418 | |
419 | |
419 | Asynchronously create a new symbolic link to the existing object at C<$srcpath> at |
420 | Asynchronously create a new symbolic link to the existing object at C<$srcpath> at |
420 | the path C<$dstpath> and call the callback with the result code. |
421 | the path C<$dstpath> and call the callback with the result code. |
|
|
422 | |
|
|
423 | =item aio_readlink $path, $callback->($link) |
|
|
424 | |
|
|
425 | Asynchronously read the symlink specified by C<$path> and pass it to |
|
|
426 | the callback. If an error occurs, nothing or undef gets passed to the |
|
|
427 | callback. |
421 | |
428 | |
422 | =item aio_rename $srcpath, $dstpath, $callback->($status) |
429 | =item aio_rename $srcpath, $dstpath, $callback->($status) |
423 | |
430 | |
424 | Asynchronously rename the object at C<$srcpath> to C<$dstpath>, just as |
431 | Asynchronously rename the object at C<$srcpath> to C<$dstpath>, just as |
425 | rename(2) and call the callback with the result code. |
432 | rename(2) and call the callback with the result code. |
… | |
… | |
964 | poll => 'r', nice => 1, |
971 | poll => 'r', nice => 1, |
965 | cb => &IO::AIO::poll_cb); |
972 | cb => &IO::AIO::poll_cb); |
966 | |
973 | |
967 | =item IO::AIO::poll_wait |
974 | =item IO::AIO::poll_wait |
968 | |
975 | |
969 | Wait till the result filehandle becomes ready for reading (simply does a |
976 | If there are any outstanding requests, wait till the result filehandle |
970 | C<select> on the filehandle. This is useful if you want to synchronously |
977 | becomes ready for reading (simply does a C<select> on the filehandle. This |
971 | wait for some requests to finish). |
978 | is useful if you want to synchronously wait for some requests to finish). |
972 | |
979 | |
973 | See C<nreqs> for an example. |
980 | See C<nreqs> for an example. |
974 | |
981 | |
975 | =item IO::AIO::poll |
982 | =item IO::AIO::poll |
976 | |
983 | |
977 | Waits until some requests have been handled. |
984 | Waits until some requests have been handled. |
978 | |
985 | |
|
|
986 | Returns the number of requests processed, but is otherwise strictly |
979 | Strictly equivalent to: |
987 | equivalent to: |
980 | |
988 | |
981 | IO::AIO::poll_wait, IO::AIO::poll_cb |
989 | IO::AIO::poll_wait, IO::AIO::poll_cb |
982 | if IO::AIO::nreqs; |
990 | if IO::AIO::nreqs; |
983 | |
991 | |
984 | =item IO::AIO::flush |
992 | =item IO::AIO::flush |