… | |
… | |
39 | All functions that expect a filehandle will also accept a file descriptor. |
39 | All functions that expect a filehandle will also accept a file descriptor. |
40 | |
40 | |
41 | The filenames you pass to these routines I<must> be absolute. The reason |
41 | The filenames you pass to these routines I<must> be absolute. The reason |
42 | is that at the time the request is being executed, the current working |
42 | is that at the time the request is being executed, the current working |
43 | directory could have changed. Alternatively, you can make sure that you |
43 | directory could have changed. Alternatively, you can make sure that you |
44 | never change the current workign directory. |
44 | never change the current working directory. |
45 | |
45 | |
46 | =over 4 |
46 | =over 4 |
47 | |
47 | |
48 | =cut |
48 | =cut |
49 | |
49 | |
50 | package Linux::AIO; |
50 | package Linux::AIO; |
51 | |
51 | |
52 | use base 'Exporter'; |
52 | use base 'Exporter'; |
53 | |
53 | |
54 | BEGIN { |
54 | BEGIN { |
55 | $VERSION = 1.71; |
55 | $VERSION = 1.72; |
56 | |
56 | |
57 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
57 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
58 | aio_fsync aio_fdatasync aio_readahead); |
58 | aio_fsync aio_fdatasync aio_readahead); |
59 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); |
59 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); |
60 | |
60 | |
… | |
… | |
128 | |
128 | |
129 | Asynchronously open or create a file and call the callback with the |
129 | Asynchronously open or create a file and call the callback with the |
130 | filedescriptor (NOT a perl filehandle, sorry for that, but watch out, this |
130 | filedescriptor (NOT a perl filehandle, sorry for that, but watch out, this |
131 | might change in the future). |
131 | might change in the future). |
132 | |
132 | |
|
|
133 | The pathname passed to C<aio_open> must be absolute. See API NOTES, above, |
|
|
134 | for an explanation. |
|
|
135 | |
133 | The C<$mode> argument is a bitmask. See the C<Fcntl> module for a |
136 | The C<$mode> argument is a bitmask. See the C<Fcntl> module for a |
134 | list. They are the same as used in C<sysopen>. |
137 | list. They are the same as used in C<sysopen>. |
135 | |
138 | |
136 | Example: |
139 | Example: |
137 | |
140 | |
138 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
141 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
139 | if ($_[0] >= 0) { |
142 | if ($_[0] >= 0) { |
140 | open my $fh, "<&$_[0]"; # create a copy for perl |
143 | open my $fh, "<&=$_[0]"; |
141 | aio_close $_[0], sub { }; # close the aio handle |
|
|
142 | print "open successful, fh is $fh\n"; |
144 | print "open successful, fh is $fh\n"; |
143 | ... |
145 | ... |
144 | } else { |
146 | } else { |
145 | die "open failed: $!\n"; |
147 | die "open failed: $!\n"; |
146 | } |
148 | } |
… | |
… | |
237 | |
239 | |
238 | - aio_open gives a fd, but all other functions expect a perl filehandle. |
240 | - aio_open gives a fd, but all other functions expect a perl filehandle. |
239 | |
241 | |
240 | =head1 SEE ALSO |
242 | =head1 SEE ALSO |
241 | |
243 | |
242 | L<Coro>. |
244 | L<Coro>, L<IO::AIO>. |
243 | |
245 | |
244 | =head1 AUTHOR |
246 | =head1 AUTHOR |
245 | |
247 | |
246 | Marc Lehmann <schmorp@schmorp.de> |
248 | Marc Lehmann <schmorp@schmorp.de> |
247 | http://home.schmorp.de/ |
249 | http://home.schmorp.de/ |