… | |
… | |
306 | } else { |
306 | } else { |
307 | die "open failed: $!\n"; |
307 | die "open failed: $!\n"; |
308 | } |
308 | } |
309 | }; |
309 | }; |
310 | |
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". |
|
|
319 | |
311 | aio_close $fh, $callback->($status) |
320 | aio_close $fh, $callback->($status) |
312 | Asynchronously close a file and call the callback with the result |
321 | Asynchronously close a file and call the callback with the result |
313 | code. |
322 | code. |
314 | |
323 | |
315 | Unfortunately, you can't do this to perl. Perl *insists* very |
324 | Unfortunately, you can't do this to perl. Perl *insists* very |
… | |
… | |
569 | The flags are a combination of the following constants, ORed |
578 | The flags are a combination of the following constants, ORed |
570 | together (the flags will also be passed to the callback, possibly |
579 | together (the flags will also be passed to the callback, possibly |
571 | modified): |
580 | modified): |
572 | |
581 | |
573 | IO::AIO::READDIR_DENTS |
582 | IO::AIO::READDIR_DENTS |
574 | When this flag is off, then the callback gets an arrayref with |
583 | When this flag is off, then the callback gets an arrayref |
575 | of names only (as with "aio_readdir"), otherwise it gets an |
584 | consisting of names only (as with "aio_readdir"), otherwise it |
576 | arrayref with "[$name, $type, $inode]" arrayrefs, each |
585 | gets an arrayref with "[$name, $type, $inode]" arrayrefs, each |
577 | describing a single directory entry in more detail. |
586 | describing a single directory entry in more detail. |
578 | |
587 | |
579 | $name is the name of the entry. |
588 | $name is the name of the entry. |
580 | |
589 | |
581 | $type is one of the "IO::AIO::DT_xxx" constants: |
590 | $type is one of the "IO::AIO::DT_xxx" constants: |
… | |
… | |
594 | unspecified content on systems that do not deliver the inode |
603 | unspecified content on systems that do not deliver the inode |
595 | information. |
604 | information. |
596 | |
605 | |
597 | IO::AIO::READDIR_DIRS_FIRST |
606 | IO::AIO::READDIR_DIRS_FIRST |
598 | 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 |
599 | order where likely directories come first. This is useful when |
608 | order where likely directories come first, in optimal stat |
600 | you need to quickly find directories, or you want to find all |
609 | order. This is useful when you need to quickly find directories, |
601 | directories while avoiding to stat() each entry. |
610 | or you want to find all directories while avoiding to stat() |
|
|
611 | each entry. |
602 | |
612 | |
603 | If the system returns type information in readdir, then this is |
613 | If the system returns type information in readdir, then this is |
604 | used to find directories directly. Otherwise, likely directories |
614 | used to find directories directly. Otherwise, likely directories |
605 | are files beginning with ".", or otherwise files with no dots, |
615 | are names beginning with ".", or otherwise names with no dots, |
606 | of which files with short names are tried first. |
616 | of which names with short names are tried first. |
607 | |
617 | |
608 | IO::AIO::READDIR_STAT_ORDER |
618 | IO::AIO::READDIR_STAT_ORDER |
609 | 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 |
610 | 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 |
611 | to stat() all files in the given directory, then the returned |
621 | to stat() all files in the given directory, then the returned |
… | |
… | |
1022 | |
1032 | |
1023 | See "poll_cb" for an example. |
1033 | See "poll_cb" for an example. |
1024 | |
1034 | |
1025 | IO::AIO::poll_cb |
1035 | IO::AIO::poll_cb |
1026 | 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 |
1027 | 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 |
1028 | it returned earlier for whatever reason. Returns immediately when no |
1038 | were no events to process), or -1 if it returned earlier for |
1029 | events are outstanding. The amount of events processed depends on |
1039 | whatever reason. Returns immediately when no events are outstanding. |
1030 | the settings of "IO::AIO::max_poll_req" and |
1040 | The amount of events processed depends on the settings of |
1031 | "IO::AIO::max_poll_time". |
1041 | "IO::AIO::max_poll_req" and "IO::AIO::max_poll_time". |
1032 | |
1042 | |
1033 | If not all requests were processed for whatever reason, the |
1043 | If not all requests were processed for whatever reason, the |
1034 | filehandle will still be ready when "poll_cb" returns, so normally |
1044 | filehandle will still be ready when "poll_cb" returns, so normally |
1035 | 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. |
1036 | |
1053 | |
1037 | Example: Install an Event watcher that automatically calls |
1054 | Example: Install an Event watcher that automatically calls |
1038 | 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 |
1039 | the SYNOPSIS section, at the top of this document): |
1056 | the SYNOPSIS section, at the top of this document): |
1040 | |
1057 | |