… | |
… | |
56 | |
56 | |
57 | =cut |
57 | =cut |
58 | |
58 | |
59 | package IO::AIO; |
59 | package IO::AIO; |
60 | |
60 | |
|
|
61 | no warnings; |
|
|
62 | |
61 | use base 'Exporter'; |
63 | use base 'Exporter'; |
62 | |
64 | |
63 | use Fcntl (); |
65 | use Fcntl (); |
64 | |
66 | |
65 | BEGIN { |
67 | BEGIN { |
66 | $VERSION = 0.9; |
68 | $VERSION = 1.1; |
67 | |
69 | |
68 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
70 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
69 | aio_fsync aio_fdatasync aio_readahead); |
71 | aio_fsync aio_fdatasync aio_readahead); |
70 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs); |
72 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs); |
71 | |
73 | |
… | |
… | |
83 | which must be a code reference. This code reference will get called with |
85 | which must be a code reference. This code reference will get called with |
84 | the syscall return code (e.g. most syscalls return C<-1> on error, unlike |
86 | the syscall return code (e.g. most syscalls return C<-1> on error, unlike |
85 | perl, which usually delivers "false") as it's sole argument when the given |
87 | perl, which usually delivers "false") as it's sole argument when the given |
86 | syscall has been executed asynchronously. |
88 | syscall has been executed asynchronously. |
87 | |
89 | |
88 | All functions that expect a filehandle will also accept a file descriptor. |
90 | All functions expecting a filehandle keep a copy of the filehandle |
|
|
91 | internally until the request has finished. |
89 | |
92 | |
90 | The filenames you pass to these routines I<must> be absolute. The reason |
93 | The filenames you pass to these routines I<must> be absolute. The reason |
91 | for this is that at the time the request is being executed, the current |
94 | for this is that at the time the request is being executed, the current |
92 | working directory could have changed. Alternatively, you can make sure |
95 | working directory could have changed. Alternatively, you can make sure |
93 | that you never change the current working directory. |
96 | that you never change the current working directory. |
… | |
… | |
310 | |
313 | |
311 | # support function to convert a fd into a perl filehandle |
314 | # support function to convert a fd into a perl filehandle |
312 | sub _fd2fh { |
315 | sub _fd2fh { |
313 | return undef if $_[0] < 0; |
316 | return undef if $_[0] < 0; |
314 | |
317 | |
315 | # try to be perl5.6-compatible |
318 | # try to generate nice filehandles |
316 | local *AIO_FH; |
319 | my $sym = "IO::AIO::fd#$_[0]"; |
317 | open AIO_FH, "+<&=$_[0]" |
320 | local *$sym; |
|
|
321 | |
|
|
322 | open *$sym, "+<&$_[0]" # usually under any unix |
|
|
323 | or open *$sym, "<&$_[0]" # cygwin needs this |
|
|
324 | or open *$sym, ">&$_[0]" # cygwin needs this |
318 | or return undef; |
325 | or return undef; |
319 | |
326 | |
320 | *AIO_FH |
327 | *$sym |
321 | } |
328 | } |
322 | |
329 | |
323 | min_parallel 4; |
330 | min_parallel 4; |
324 | |
331 | |
325 | END { |
332 | END { |