… | |
… | |
963 | |
963 | |
964 | my $class = shift; |
964 | my $class = shift; |
965 | $class->$func (@_); |
965 | $class->$func (@_); |
966 | } |
966 | } |
967 | |
967 | |
|
|
968 | # utility function to dup a filehandle. this is used by many backends |
|
|
969 | # to support binding more than one watcher per filehandle (they usually |
|
|
970 | # allow only one watcher per fd, so we dup it to get a different one). |
|
|
971 | sub _dupfh($$$$) { |
|
|
972 | my ($poll, $fh, $r, $w) = @_; |
|
|
973 | |
|
|
974 | require Fcntl; |
|
|
975 | |
|
|
976 | # cygwin requires the fh mode to be matching, unix doesn't |
|
|
977 | my ($rw, $mode) = $poll eq "r" ? ($r, "<") |
|
|
978 | : $poll eq "w" ? ($w, ">") |
|
|
979 | : Carp::croak "AnyEvent->io requires poll set to either 'r' or 'w'"; |
|
|
980 | |
|
|
981 | open my $fh2, "$mode&" . fileno $fh |
|
|
982 | or die "cannot dup() filehandle: $!"; |
|
|
983 | |
|
|
984 | # we assume CLOEXEC is already set by perl in all important cases |
|
|
985 | |
|
|
986 | ($fh2, $rw) |
|
|
987 | } |
|
|
988 | |
968 | package AnyEvent::Base; |
989 | package AnyEvent::Base; |
969 | |
990 | |
970 | # default implementation for now and time |
991 | # default implementation for now and time |
971 | |
992 | |
972 | use Time::HiRes (); |
993 | use Time::HiRes (); |