… | |
… | |
81 | |
81 | |
82 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
82 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
83 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
83 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
84 | aio_fsync aio_fdatasync aio_readahead aio_rename aio_link aio_move |
84 | aio_fsync aio_fdatasync aio_readahead aio_rename aio_link aio_move |
85 | aio_group aio_nop); |
85 | aio_group aio_nop); |
86 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri)); |
86 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); |
87 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
87 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
88 | min_parallel max_parallel max_outstanding nreqs); |
88 | min_parallel max_parallel max_outstanding nreqs); |
89 | |
89 | |
90 | @IO::AIO::GRP::ISA = 'IO::AIO::REQ'; |
90 | @IO::AIO::GRP::ISA = 'IO::AIO::REQ'; |
91 | |
91 | |
… | |
… | |
133 | respectively. Requests with higher priority will be serviced first. |
133 | respectively. Requests with higher priority will be serviced first. |
134 | |
134 | |
135 | The priority will be reset to C<0> after each call to one of the C<aio_> |
135 | The priority will be reset to C<0> after each call to one of the C<aio_> |
136 | functions. |
136 | functions. |
137 | |
137 | |
|
|
138 | Example: open a file with low priority, then read something from it with |
|
|
139 | higher priority so the read request is serviced before other low priority |
|
|
140 | open requests (potentially spamming the cache): |
|
|
141 | |
|
|
142 | aioreq_pri -3; |
|
|
143 | aio_open ..., sub { |
|
|
144 | return unless $_[0]; |
|
|
145 | |
|
|
146 | aioreq_pri -2; |
|
|
147 | aio_read $_[0], ..., sub { |
|
|
148 | ... |
|
|
149 | }; |
|
|
150 | }; |
|
|
151 | |
|
|
152 | =item aioreq_nice $pri_adjust |
|
|
153 | |
|
|
154 | Similar to C<aioreq_pri>, but subtracts the given value from the current |
|
|
155 | priority, so effects are cumulative. |
|
|
156 | |
138 | =item aio_open $pathname, $flags, $mode, $callback->($fh) |
157 | =item aio_open $pathname, $flags, $mode, $callback->($fh) |
139 | |
158 | |
140 | Asynchronously open or create a file and call the callback with a newly |
159 | Asynchronously open or create a file and call the callback with a newly |
141 | created filehandle for the file. |
160 | created filehandle for the file. |
142 | |
161 | |
… | |
… | |
193 | $_[0] > 0 or die "read error: $!"; |
212 | $_[0] > 0 or die "read error: $!"; |
194 | print "read $_[0] bytes: <$buffer>\n"; |
213 | print "read $_[0] bytes: <$buffer>\n"; |
195 | }; |
214 | }; |
196 | |
215 | |
197 | =item aio_move $srcpath, $dstpath, $callback->($status) |
216 | =item aio_move $srcpath, $dstpath, $callback->($status) |
198 | |
|
|
199 | [EXPERIMENTAL due to internal aio_group use] |
|
|
200 | |
217 | |
201 | Try to move the I<file> (directories not supported as either source or |
218 | Try to move the I<file> (directories not supported as either source or |
202 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
219 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
203 | the C<0> (error) or C<-1> ok. |
220 | the C<0> (error) or C<-1> ok. |
204 | |
221 | |
… | |
… | |
356 | |
373 | |
357 | The callback a single argument which is either C<undef> or an array-ref |
374 | The callback a single argument which is either C<undef> or an array-ref |
358 | with the filenames. |
375 | with the filenames. |
359 | |
376 | |
360 | =item aio_scandir $path, $maxreq, $callback->($dirs, $nondirs) |
377 | =item aio_scandir $path, $maxreq, $callback->($dirs, $nondirs) |
361 | |
|
|
362 | [EXPERIMENTAL due to internal aio_group use] |
|
|
363 | |
378 | |
364 | Scans a directory (similar to C<aio_readdir>) but additionally tries to |
379 | Scans a directory (similar to C<aio_readdir>) but additionally tries to |
365 | separate the entries of directory C<$path> into two sets of names, ones |
380 | separate the entries of directory C<$path> into two sets of names, ones |
366 | you can recurse into (directories or links to them), and ones you cannot |
381 | you can recurse into (directories or links to them), and ones you cannot |
367 | recurse into (everything else). |
382 | recurse into (everything else). |
… | |
… | |
529 | |
544 | |
530 | [EXPERIMENTAL] |
545 | [EXPERIMENTAL] |
531 | |
546 | |
532 | This is a very special aio request: Instead of doing something, it is a |
547 | This is a very special aio request: Instead of doing something, it is a |
533 | container for other aio requests, which is useful if you want to bundle |
548 | container for other aio requests, which is useful if you want to bundle |
534 | many requests into a single, composite, request. |
549 | many requests into a single, composite, request with a definite callback |
|
|
550 | and the ability to cancel the whole request with its subrequests. |
535 | |
551 | |
536 | Returns an object of class L<IO::AIO::GRP>. See its documentation below |
552 | Returns an object of class L<IO::AIO::GRP>. See its documentation below |
537 | for more info. |
553 | for more info. |
538 | |
554 | |
539 | Example: |
555 | Example: |
… | |
… | |
558 | phase and still requires a worker thread. Thus, the callback will not |
574 | phase and still requires a worker thread. Thus, the callback will not |
559 | be executed immediately but only after other requests in the queue have |
575 | be executed immediately but only after other requests in the queue have |
560 | entered their execution phase. This can be used to measure request |
576 | entered their execution phase. This can be used to measure request |
561 | latency. |
577 | latency. |
562 | |
578 | |
563 | =item IO::AIO::aio_sleep $fractional_seconds, $callback->() *NOT EXPORTED* |
579 | =item IO::AIO::aio_busy $fractional_seconds, $callback->() *NOT EXPORTED* |
564 | |
580 | |
565 | Mainly used for debugging and benchmarking, this aio request puts one of |
581 | Mainly used for debugging and benchmarking, this aio request puts one of |
566 | the request workers to sleep for the given time. |
582 | the request workers to sleep for the given time. |
567 | |
583 | |
568 | While it is theoretically handy to have simple I/O scheduling requests |
584 | While it is theoretically handy to have simple I/O scheduling requests |
569 | like sleep and file handle readable/writable, the overhead this creates |
585 | like sleep and file handle readable/writable, the overhead this creates is |
570 | is immense, so do not use this function except to put your application |
586 | immense (it blocks a thread for a long time) so do not use this function |
571 | under artificial I/O pressure. |
587 | except to put your application under artificial I/O pressure. |
572 | |
588 | |
573 | =back |
589 | =back |
574 | |
590 | |
575 | =head2 IO::AIO::REQ CLASS |
591 | =head2 IO::AIO::REQ CLASS |
576 | |
592 | |