… | |
… | |
204 | IO::AIO::max_poll_reqs $nreqs |
204 | IO::AIO::max_poll_reqs $nreqs |
205 | IO::AIO::max_poll_time $seconds |
205 | IO::AIO::max_poll_time $seconds |
206 | IO::AIO::min_parallel $nthreads |
206 | IO::AIO::min_parallel $nthreads |
207 | IO::AIO::max_parallel $nthreads |
207 | IO::AIO::max_parallel $nthreads |
208 | IO::AIO::max_idle $nthreads |
208 | IO::AIO::max_idle $nthreads |
|
|
209 | IO::AIO::idle_timeout $seconds |
209 | IO::AIO::max_outstanding $maxreqs |
210 | IO::AIO::max_outstanding $maxreqs |
210 | IO::AIO::nreqs |
211 | IO::AIO::nreqs |
211 | IO::AIO::nready |
212 | IO::AIO::nready |
212 | IO::AIO::npending |
213 | IO::AIO::npending |
213 | |
214 | |
… | |
… | |
304 | ... |
305 | ... |
305 | } else { |
306 | } else { |
306 | die "open failed: $!\n"; |
307 | die "open failed: $!\n"; |
307 | } |
308 | } |
308 | }; |
309 | }; |
|
|
310 | |
|
|
311 | In addition to all the common open modes/flags ("O_RDONLY", |
|
|
312 | "O_WRONLY", "O_RDWR", "O_CREAT", "O_TRUNC", "O_EXCL" and |
|
|
313 | "O_APPEND"), the following POSIX and non-POSIX constants are |
|
|
314 | available (missing ones on your system are, as usual, 0): |
|
|
315 | |
|
|
316 | "O_ASYNC", "O_DIRECT", "O_NOATIME", "O_CLOEXEC", "O_NOCTTY", |
|
|
317 | "O_NOFOLLOW", "O_NONBLOCK", "O_EXEC", "O_SEARCH", "O_DIRECTORY", |
|
|
318 | "O_DSYNC", "O_RSYNC", "O_SYNC" and "O_TTY_INIT". |
309 | |
319 | |
310 | aio_close $fh, $callback->($status) |
320 | aio_close $fh, $callback->($status) |
311 | Asynchronously close a file and call the callback with the result |
321 | Asynchronously close a file and call the callback with the result |
312 | code. |
322 | code. |
313 | |
323 | |
… | |
… | |
413 | |
423 | |
414 | Currently, the stats are always 64-bit-stats, i.e. instead of |
424 | Currently, the stats are always 64-bit-stats, i.e. instead of |
415 | returning an error when stat'ing a large file, the results will be |
425 | returning an error when stat'ing a large file, the results will be |
416 | silently truncated unless perl itself is compiled with large file |
426 | silently truncated unless perl itself is compiled with large file |
417 | support. |
427 | support. |
|
|
428 | |
|
|
429 | To help interpret the mode and dev/rdev stat values, IO::AIO offers |
|
|
430 | the following constants and functions (if not implemented, the |
|
|
431 | constants will be 0 and the functions will either "croak" or fall |
|
|
432 | back on traditional behaviour). |
|
|
433 | |
|
|
434 | "S_IFMT", "S_IFIFO", "S_IFCHR", "S_IFBLK", "S_IFLNK", "S_IFREG", |
|
|
435 | "S_IFDIR", "S_IFWHT", "S_IFSOCK", "IO::AIO::major $dev_t", |
|
|
436 | "IO::AIO::minor $dev_t", "IO::AIO::makedev $major, $minor". |
418 | |
437 | |
419 | Example: Print the length of /etc/passwd: |
438 | Example: Print the length of /etc/passwd: |
420 | |
439 | |
421 | aio_stat "/etc/passwd", sub { |
440 | aio_stat "/etc/passwd", sub { |
422 | $_[0] and die "stat failed: $!"; |
441 | $_[0] and die "stat failed: $!"; |
… | |
… | |
511 | |
530 | |
512 | The only (POSIX-) portable way of calling this function is: |
531 | The only (POSIX-) portable way of calling this function is: |
513 | |
532 | |
514 | aio_mknod $path, IO::AIO::S_IFIFO | $mode, 0, sub { ... |
533 | aio_mknod $path, IO::AIO::S_IFIFO | $mode, 0, sub { ... |
515 | |
534 | |
|
|
535 | See "aio_stat" for info about some potentially helpful extra |
|
|
536 | constants and functions. |
|
|
537 | |
516 | aio_link $srcpath, $dstpath, $callback->($status) |
538 | aio_link $srcpath, $dstpath, $callback->($status) |
517 | Asynchronously create a new link to the existing object at $srcpath |
539 | Asynchronously create a new link to the existing object at $srcpath |
518 | at the path $dstpath and call the callback with the result code. |
540 | at the path $dstpath and call the callback with the result code. |
519 | |
541 | |
520 | aio_symlink $srcpath, $dstpath, $callback->($status) |
542 | aio_symlink $srcpath, $dstpath, $callback->($status) |
… | |
… | |
556 | The flags are a combination of the following constants, ORed |
578 | The flags are a combination of the following constants, ORed |
557 | together (the flags will also be passed to the callback, possibly |
579 | together (the flags will also be passed to the callback, possibly |
558 | modified): |
580 | modified): |
559 | |
581 | |
560 | IO::AIO::READDIR_DENTS |
582 | IO::AIO::READDIR_DENTS |
561 | When this flag is off, then the callback gets an arrayref with |
583 | When this flag is off, then the callback gets an arrayref |
562 | of names only (as with "aio_readdir"), otherwise it gets an |
584 | consisting of names only (as with "aio_readdir"), otherwise it |
563 | arrayref with "[$name, $type, $inode]" arrayrefs, each |
585 | gets an arrayref with "[$name, $type, $inode]" arrayrefs, each |
564 | describing a single directory entry in more detail. |
586 | describing a single directory entry in more detail. |
565 | |
587 | |
566 | $name is the name of the entry. |
588 | $name is the name of the entry. |
567 | |
589 | |
568 | $type is one of the "IO::AIO::DT_xxx" constants: |
590 | $type is one of the "IO::AIO::DT_xxx" constants: |
… | |
… | |
581 | unspecified content on systems that do not deliver the inode |
603 | unspecified content on systems that do not deliver the inode |
582 | information. |
604 | information. |
583 | |
605 | |
584 | IO::AIO::READDIR_DIRS_FIRST |
606 | IO::AIO::READDIR_DIRS_FIRST |
585 | When this flag is set, then the names will be returned in an |
607 | When this flag is set, then the names will be returned in an |
586 | order where likely directories come first. This is useful when |
608 | order where likely directories come first, in optimal stat |
587 | you need to quickly find directories, or you want to find all |
609 | order. This is useful when you need to quickly find directories, |
588 | directories while avoiding to stat() each entry. |
610 | or you want to find all directories while avoiding to stat() |
|
|
611 | each entry. |
589 | |
612 | |
590 | If the system returns type information in readdir, then this is |
613 | If the system returns type information in readdir, then this is |
591 | used to find directories directly. Otherwise, likely directories |
614 | used to find directories directly. Otherwise, likely directories |
592 | are files beginning with ".", or otherwise files with no dots, |
615 | are names beginning with ".", or otherwise names with no dots, |
593 | of which files with short names are tried first. |
616 | of which names with short names are tried first. |
594 | |
617 | |
595 | IO::AIO::READDIR_STAT_ORDER |
618 | IO::AIO::READDIR_STAT_ORDER |
596 | When this flag is set, then the names will be returned in an |
619 | When this flag is set, then the names will be returned in an |
597 | order suitable for stat()'ing each one. That is, when you plan |
620 | order suitable for stat()'ing each one. That is, when you plan |
598 | to stat() all files in the given directory, then the returned |
621 | to stat() all files in the given directory, then the returned |
… | |
… | |
1009 | |
1032 | |
1010 | See "poll_cb" for an example. |
1033 | See "poll_cb" for an example. |
1011 | |
1034 | |
1012 | IO::AIO::poll_cb |
1035 | IO::AIO::poll_cb |
1013 | Process some outstanding events on the result pipe. You have to call |
1036 | Process some outstanding events on the result pipe. You have to call |
1014 | this regularly. Returns 0 if all events could be processed, or -1 if |
1037 | this regularly. Returns 0 if all events could be processed (or there |
1015 | it returned earlier for whatever reason. Returns immediately when no |
1038 | were no events to process), or -1 if it returned earlier for |
1016 | events are outstanding. The amount of events processed depends on |
1039 | whatever reason. Returns immediately when no events are outstanding. |
1017 | the settings of "IO::AIO::max_poll_req" and |
1040 | The amount of events processed depends on the settings of |
1018 | "IO::AIO::max_poll_time". |
1041 | "IO::AIO::max_poll_req" and "IO::AIO::max_poll_time". |
1019 | |
1042 | |
1020 | If not all requests were processed for whatever reason, the |
1043 | If not all requests were processed for whatever reason, the |
1021 | filehandle will still be ready when "poll_cb" returns, so normally |
1044 | filehandle will still be ready when "poll_cb" returns, so normally |
1022 | you don't have to do anything special to have it called later. |
1045 | you don't have to do anything special to have it called later. |
|
|
1046 | |
|
|
1047 | Apart from calling "IO::AIO::poll_cb" when the event filehandle |
|
|
1048 | becomes ready, it can be beneficial to call this function from loops |
|
|
1049 | which submit a lot of requests, to make sure the results get |
|
|
1050 | processed when they become available and not just when the loop is |
|
|
1051 | finished and the event loop takes over again. This function returns |
|
|
1052 | very fast when there are no outstanding requests. |
1023 | |
1053 | |
1024 | Example: Install an Event watcher that automatically calls |
1054 | Example: Install an Event watcher that automatically calls |
1025 | IO::AIO::poll_cb with high priority (more examples can be found in |
1055 | IO::AIO::poll_cb with high priority (more examples can be found in |
1026 | the SYNOPSIS section, at the top of this document): |
1056 | the SYNOPSIS section, at the top of this document): |
1027 | |
1057 | |
… | |
… | |
1121 | |
1151 | |
1122 | Under normal circumstances you don't need to call this function. |
1152 | Under normal circumstances you don't need to call this function. |
1123 | |
1153 | |
1124 | IO::AIO::max_idle $nthreads |
1154 | IO::AIO::max_idle $nthreads |
1125 | Limit the number of threads (default: 4) that are allowed to idle |
1155 | Limit the number of threads (default: 4) that are allowed to idle |
1126 | (i.e., threads that did not get a request to process within 10 |
1156 | (i.e., threads that did not get a request to process within the idle |
1127 | seconds). That means if a thread becomes idle while $nthreads other |
1157 | timeout (default: 10 seconds). That means if a thread becomes idle |
1128 | threads are also idle, it will free its resources and exit. |
1158 | while $nthreads other threads are also idle, it will free its |
|
|
1159 | resources and exit. |
1129 | |
1160 | |
1130 | This is useful when you allow a large number of threads (e.g. 100 or |
1161 | This is useful when you allow a large number of threads (e.g. 100 or |
1131 | 1000) to allow for extremely high load situations, but want to free |
1162 | 1000) to allow for extremely high load situations, but want to free |
1132 | resources under normal circumstances (1000 threads can easily |
1163 | resources under normal circumstances (1000 threads can easily |
1133 | consume 30MB of RAM). |
1164 | consume 30MB of RAM). |
1134 | |
1165 | |
1135 | The default is probably ok in most situations, especially if thread |
1166 | The default is probably ok in most situations, especially if thread |
1136 | creation is fast. If thread creation is very slow on your system you |
1167 | creation is fast. If thread creation is very slow on your system you |
1137 | might want to use larger values. |
1168 | might want to use larger values. |
|
|
1169 | |
|
|
1170 | IO::AIO::idle_timeout $seconds |
|
|
1171 | Sets the minimum idle timeout (default 10) after which worker |
|
|
1172 | threads are allowed to exit. SEe "IO::AIO::max_idle". |
1138 | |
1173 | |
1139 | IO::AIO::max_outstanding $maxreqs |
1174 | IO::AIO::max_outstanding $maxreqs |
1140 | This is a very bad function to use in interactive programs because |
1175 | This is a very bad function to use in interactive programs because |
1141 | it blocks, and a bad way to reduce concurrency because it is |
1176 | it blocks, and a bad way to reduce concurrency because it is |
1142 | inexact: Better use an "aio_group" together with a feed callback. |
1177 | inexact: Better use an "aio_group" together with a feed callback. |