--- AnyEvent/lib/AnyEvent.pm 2009/07/08 01:11:12 1.228 +++ AnyEvent/lib/AnyEvent.pm 2009/07/08 02:01:12 1.229 @@ -178,9 +178,9 @@ You can create an I/O watcher by calling the C<< AnyEvent->io >> method with the following mandatory key-value pairs as arguments: -C is the Perl I (I file descriptor, see below) to -watch for events (AnyEvent might or might not keep a reference to this -file handle). Note that only file handles pointing to things for which +C is the Perl I (or a naked file descriptor) to watch +for events (AnyEvent might or might not keep a reference to this file +handle). Note that only file handles pointing to things for which non-blocking operation makes sense are allowed. This includes sockets, most character devices, pipes, fifos and so on, but not for example files or block devices. @@ -211,29 +211,6 @@ undef $w; }); -=head3 GETTING A FILE HANDLE FROM A FILE DESCRIPTOR - -It is not uncommon to only have a file descriptor, while AnyEvent requires -a Perl file handle. - -There are basically two methods to convert a file descriptor into a file handle. If you own -the file descriptor, you can open it with C<&=>, as in: - - open my $fh, "<&=$fileno" or die "xxx: ยง!"; - -This will "own" the file descriptor, meaning that when C<$fh> is -destroyed, it will automatically close the C<$fileno>. Also, note that -the open mode (read, write, read/write) must correspond with how the -underlying file descriptor was opened. - -In many cases, taking over the file descriptor is now what you want, in -which case the only alternative is to dup the file descriptor: - - open my $fh, "<&$fileno" or die "xxx: $!"; - -This has the advantage of not closing the file descriptor and the -disadvantage of making a slow copy. - =head2 TIME WATCHERS You can create a time watcher by calling the C<< AnyEvent->timer >> @@ -1148,12 +1125,10 @@ my ($poll, $fh, $r, $w) = @_; # cygwin requires the fh mode to be matching, unix doesn't - my ($rw, $mode) = $poll eq "r" ? ($r, "<") - : $poll eq "w" ? ($w, ">") - : Carp::croak "AnyEvent->io requires poll set to either 'r' or 'w'"; + my ($rw, $mode) = $poll eq "r" ? ($r, "<") : ($w, ">"); - open my $fh2, "$mode&" . fileno $fh - or die "cannot dup() filehandle: $!,"; + open my $fh2, "$mode&", $fh + or die "AnyEvent->io: cannot dup() filehandle in mode '$poll': $!,"; # we assume CLOEXEC is already set by perl in all important cases