… | |
… | |
22 | poll => 'r', |
22 | poll => 'r', |
23 | cb => \&IO::AIO::poll_cb); |
23 | cb => \&IO::AIO::poll_cb); |
24 | |
24 | |
25 | # Glib/Gtk2 |
25 | # Glib/Gtk2 |
26 | add_watch Glib::IO IO::AIO::poll_fileno, |
26 | add_watch Glib::IO IO::AIO::poll_fileno, |
27 | \&IO::AIO::poll_cb; |
27 | in => sub { IO::AIO::poll_cb, 1 }; |
28 | |
28 | |
29 | # Tk |
29 | # Tk |
30 | Tk::Event::IO->fileevent (IO::AIO::poll_fileno, "", |
30 | Tk::Event::IO->fileevent (IO::AIO::poll_fileno, "", |
31 | readable => \&IO::AIO::poll_cb); |
31 | readable => \&IO::AIO::poll_cb); |
32 | |
32 | |
… | |
… | |
129 | Reads or writes C<length> bytes from the specified C<fh> and C<offset> |
129 | Reads or writes C<length> bytes from the specified C<fh> and C<offset> |
130 | into the scalar given by C<data> and offset C<dataoffset> and calls the |
130 | into the scalar given by C<data> and offset C<dataoffset> and calls the |
131 | callback without the actual number of bytes read (or -1 on error, just |
131 | callback without the actual number of bytes read (or -1 on error, just |
132 | like the syscall). |
132 | like the syscall). |
133 | |
133 | |
134 | Example: Read 15 bytes at offset 7 into scalar C<$buffer>, strating at |
134 | Example: Read 15 bytes at offset 7 into scalar C<$buffer>, starting at |
135 | offset C<0> within the scalar: |
135 | offset C<0> within the scalar: |
136 | |
136 | |
137 | aio_read $fh, 7, 15, $buffer, 0, sub { |
137 | aio_read $fh, 7, 15, $buffer, 0, sub { |
138 | $_[0] > 0 or die "read error: $!"; |
138 | $_[0] > 0 or die "read error: $!"; |
139 | print "read $_[0] bytes: <$buffer>\n"; |
139 | print "read $_[0] bytes: <$buffer>\n"; |
140 | }; |
140 | }; |
141 | |
141 | |
142 | =item aio_readahead $fh,$offset,$length, $callback |
142 | =item aio_readahead $fh,$offset,$length, $callback |
143 | |
143 | |
144 | Asynchronously reads the specified byte range into the page cache, using |
144 | Asynchronously reads the specified byte range into the page cache, using |
145 | the C<readahead> syscall. If that syscall doesn't exist the status will be |
145 | the C<readahead> syscall. If that syscall doesn't exist (likely if your OS |
146 | C<-1> and C<$!> is set to ENOSYS. |
146 | isn't Linux) the status will be C<-1> and C<$!> is set to ENOSYS. |
147 | |
147 | |
148 | readahead() populates the page cache with data from a file so that |
148 | readahead() populates the page cache with data from a file so that |
149 | subsequent reads from that file will not block on disk I/O. The C<$offset> |
149 | subsequent reads from that file will not block on disk I/O. The C<$offset> |
150 | argument specifies the starting point from which data is to be read and |
150 | argument specifies the starting point from which data is to be read and |
151 | C<$length> specifies the number of bytes to be read. I/O is performed in |
151 | C<$length> specifies the number of bytes to be read. I/O is performed in |