ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.pm
(Generate patch)

Comparing IO-AIO/AIO.pm (file contents):
Revision 1.13 by root, Mon Jul 11 01:49:14 2005 UTC vs.
Revision 1.18 by root, Mon Jul 11 03:29:39 2005 UTC

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
59use base 'Exporter'; 59use base 'Exporter';
60 60
61use Fcntl (); 61use Fcntl ();
62 62
63BEGIN { 63BEGIN {
64 $VERSION = 0.3; 64 $VERSION = 0.4;
65 65
66 @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink 66 @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink
67 aio_fsync aio_fdatasync aio_readahead); 67 aio_fsync aio_fdatasync aio_readahead);
68 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs); 68 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs);
69 69
75 75
76=head2 AIO FUNCTIONS 76=head2 AIO FUNCTIONS
77 77
78All the C<aio_*> calls are more or less thin wrappers around the syscall 78All the C<aio_*> calls are more or less thin wrappers around the syscall
79with the same name (sans C<aio_>). The arguments are similar or identical, 79with the same name (sans C<aio_>). The arguments are similar or identical,
80and they all accept an additional C<$callback> argument which must be 80and they all accept an additional (and optional) C<$callback> argument
81a code reference. This code reference will get called with the syscall 81which must be a code reference. This code reference will get called with
82return code (e.g. most syscalls return C<-1> on error, unlike perl, which 82the syscall return code (e.g. most syscalls return C<-1> on error, unlike
83usually delivers "false") as it's sole argument when the given syscall has 83perl, which usually delivers "false") as it's sole argument when the given
84been executed asynchronously. 84syscall has been executed asynchronously.
85 85
86All functions that expect a filehandle will also accept a file descriptor. 86All functions that expect a filehandle will also accept a file descriptor.
87 87
88The filenames you pass to these routines I<must> be absolute. The reason 88The filenames you pass to these routines I<must> be absolute. The reason
89is that at the time the request is being executed, the current working 89is that at the time the request is being executed, the current working
129Reads or writes C<length> bytes from the specified C<fh> and C<offset> 129Reads or writes C<length> bytes from the specified C<fh> and C<offset>
130into the scalar given by C<data> and offset C<dataoffset> and calls the 130into the scalar given by C<data> and offset C<dataoffset> and calls the
131callback without the actual number of bytes read (or -1 on error, just 131callback without the actual number of bytes read (or -1 on error, just
132like the syscall). 132like the syscall).
133 133
134Example: Read 15 bytes at offset 7 into scalar C<$buffer>, strating at 134Example: Read 15 bytes at offset 7 into scalar C<$buffer>, starting at
135offset C<0> within the scalar: 135offset 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
144Asynchronously reads the specified byte range into the page cache, using 144Asynchronously reads the specified byte range into the page cache, using
145the C<readahead> syscall. If that syscall doesn't exist the status will be 145the C<readahead> syscall. If that syscall doesn't exist (likely if your OS
146C<-1> and C<$!> is set to ENOSYS. 146isn't Linux) the status will be C<-1> and C<$!> is set to ENOSYS.
147 147
148readahead() populates the page cache with data from a file so that 148readahead() populates the page cache with data from a file so that
149subsequent reads from that file will not block on disk I/O. The C<$offset> 149subsequent reads from that file will not block on disk I/O. The C<$offset>
150argument specifies the starting point from which data is to be read and 150argument specifies the starting point from which data is to be read and
151C<$length> specifies the number of bytes to be read. I/O is performed in 151C<$length> specifies the number of bytes to be read. I/O is performed in

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines