… | |
… | |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use IO::AIO; |
7 | use IO::AIO; |
8 | |
8 | |
9 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
9 | aio_open "/etc/passwd", IO::AIO::O_RDONLY, 0, sub { |
10 | my $fh = shift |
10 | my $fh = shift |
11 | or die "/etc/passwd: $!"; |
11 | or die "/etc/passwd: $!"; |
12 | ... |
12 | ... |
13 | }; |
13 | }; |
14 | |
14 | |
… | |
… | |
76 | |
76 | |
77 | # register the IO::AIO callback with EV |
77 | # register the IO::AIO callback with EV |
78 | my $aio_w = EV::io IO::AIO::poll_fileno, EV::READ, \&IO::AIO::poll_cb; |
78 | my $aio_w = EV::io IO::AIO::poll_fileno, EV::READ, \&IO::AIO::poll_cb; |
79 | |
79 | |
80 | # queue the request to open /etc/passwd |
80 | # queue the request to open /etc/passwd |
81 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
81 | aio_open "/etc/passwd", IO::AIO::O_RDONLY, 0, sub { |
82 | my $fh = shift |
82 | my $fh = shift |
83 | or die "error while opening: $!"; |
83 | or die "error while opening: $!"; |
84 | |
84 | |
85 | # stat'ing filehandles is generally non-blocking |
85 | # stat'ing filehandles is generally non-blocking |
86 | my $size = -s $fh; |
86 | my $size = -s $fh; |
… | |
… | |
352 | by the umask in effect then the request is being executed, so better never |
352 | by the umask in effect then the request is being executed, so better never |
353 | change the umask. |
353 | change the umask. |
354 | |
354 | |
355 | Example: |
355 | Example: |
356 | |
356 | |
357 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
357 | aio_open "/etc/passwd", IO::AIO::O_RDONLY, 0, sub { |
358 | if ($_[0]) { |
358 | if ($_[0]) { |
359 | print "open successful, fh is $_[0]\n"; |
359 | print "open successful, fh is $_[0]\n"; |
360 | ... |
360 | ... |
361 | } else { |
361 | } else { |
362 | die "open failed: $!\n"; |
362 | die "open failed: $!\n"; |