ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.227 by root, Mon Jul 6 23:42:24 2009 UTC vs.
Revision 1.229 by root, Wed Jul 8 02:01:12 2009 UTC

176=head2 I/O WATCHERS 176=head2 I/O WATCHERS
177 177
178You can create an I/O watcher by calling the C<< AnyEvent->io >> method 178You can create an I/O watcher by calling the C<< AnyEvent->io >> method
179with the following mandatory key-value pairs as arguments: 179with the following mandatory key-value pairs as arguments:
180 180
181C<fh> is the Perl I<file handle> (I<not> file descriptor) to watch 181C<fh> is the Perl I<file handle> (or a naked file descriptor) to watch
182for events (AnyEvent might or might not keep a reference to this file 182for events (AnyEvent might or might not keep a reference to this file
183handle). Note that only file handles pointing to things for which 183handle). Note that only file handles pointing to things for which
184non-blocking operation makes sense are allowed. This includes sockets, 184non-blocking operation makes sense are allowed. This includes sockets,
185most character devices, pipes, fifos and so on, but not for example files 185most character devices, pipes, fifos and so on, but not for example files
186or block devices. 186or block devices.
1123# allow only one watcher per fd, so we dup it to get a different one). 1123# allow only one watcher per fd, so we dup it to get a different one).
1124sub _dupfh($$;$$) { 1124sub _dupfh($$;$$) {
1125 my ($poll, $fh, $r, $w) = @_; 1125 my ($poll, $fh, $r, $w) = @_;
1126 1126
1127 # cygwin requires the fh mode to be matching, unix doesn't 1127 # cygwin requires the fh mode to be matching, unix doesn't
1128 my ($rw, $mode) = $poll eq "r" ? ($r, "<") 1128 my ($rw, $mode) = $poll eq "r" ? ($r, "<") : ($w, ">");
1129 : $poll eq "w" ? ($w, ">")
1130 : Carp::croak "AnyEvent->io requires poll set to either 'r' or 'w'";
1131 1129
1132 open my $fh2, "$mode&" . fileno $fh 1130 open my $fh2, "$mode&", $fh
1133 or die "cannot dup() filehandle: $!,"; 1131 or die "AnyEvent->io: cannot dup() filehandle in mode '$poll': $!,";
1134 1132
1135 # we assume CLOEXEC is already set by perl in all important cases 1133 # we assume CLOEXEC is already set by perl in all important cases
1136 1134
1137 ($fh2, $rw) 1135 ($fh2, $rw)
1138} 1136}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines