… | |
… | |
176 | =head2 I/O WATCHERS |
176 | =head2 I/O WATCHERS |
177 | |
177 | |
178 | You can create an I/O watcher by calling the C<< AnyEvent->io >> method |
178 | You can create an I/O watcher by calling the C<< AnyEvent->io >> method |
179 | with the following mandatory key-value pairs as arguments: |
179 | with the following mandatory key-value pairs as arguments: |
180 | |
180 | |
181 | C<fh> is the Perl I<file handle> (I<not> file descriptor) to watch |
181 | C<fh> is the Perl I<file handle> (or a naked file descriptor) to watch |
182 | for events (AnyEvent might or might not keep a reference to this file |
182 | for events (AnyEvent might or might not keep a reference to this file |
183 | handle). Note that only file handles pointing to things for which |
183 | handle). Note that only file handles pointing to things for which |
184 | non-blocking operation makes sense are allowed. This includes sockets, |
184 | non-blocking operation makes sense are allowed. This includes sockets, |
185 | most character devices, pipes, fifos and so on, but not for example files |
185 | most character devices, pipes, fifos and so on, but not for example files |
186 | or block devices. |
186 | or block devices. |
… | |
… | |
868 | |
868 | |
869 | |
869 | |
870 | =head1 OTHER MODULES |
870 | =head1 OTHER MODULES |
871 | |
871 | |
872 | The following is a non-exhaustive list of additional modules that use |
872 | The following is a non-exhaustive list of additional modules that use |
873 | AnyEvent and can therefore be mixed easily with other AnyEvent modules |
873 | AnyEvent as a client and can therefore be mixed easily with other AnyEvent |
874 | in the same program. Some of the modules come with AnyEvent, some are |
874 | modules and other event loops in the same program. Some of the modules |
875 | available via CPAN. |
875 | come with AnyEvent, most are available via CPAN. |
876 | |
876 | |
877 | =over 4 |
877 | =over 4 |
878 | |
878 | |
879 | =item L<AnyEvent::Util> |
879 | =item L<AnyEvent::Util> |
880 | |
880 | |
… | |
… | |
889 | |
889 | |
890 | =item L<AnyEvent::Handle> |
890 | =item L<AnyEvent::Handle> |
891 | |
891 | |
892 | Provide read and write buffers, manages watchers for reads and writes, |
892 | Provide read and write buffers, manages watchers for reads and writes, |
893 | supports raw and formatted I/O, I/O queued and fully transparent and |
893 | supports raw and formatted I/O, I/O queued and fully transparent and |
894 | non-blocking SSL/TLS. |
894 | non-blocking SSL/TLS (via L<AnyEvent::TLS>. |
895 | |
895 | |
896 | =item L<AnyEvent::DNS> |
896 | =item L<AnyEvent::DNS> |
897 | |
897 | |
898 | Provides rich asynchronous DNS resolver capabilities. |
898 | Provides rich asynchronous DNS resolver capabilities. |
899 | |
899 | |
… | |
… | |
927 | |
927 | |
928 | =item L<AnyEvent::GPSD> |
928 | =item L<AnyEvent::GPSD> |
929 | |
929 | |
930 | A non-blocking interface to gpsd, a daemon delivering GPS information. |
930 | A non-blocking interface to gpsd, a daemon delivering GPS information. |
931 | |
931 | |
|
|
932 | =item L<AnyEvent::IRC> |
|
|
933 | |
|
|
934 | AnyEvent based IRC client module family (replacing the older Net::IRC3). |
|
|
935 | |
|
|
936 | =item L<AnyEvent::XMPP> |
|
|
937 | |
|
|
938 | AnyEvent based XMPP (Jabber protocol) module family (replacing the older |
|
|
939 | Net::XMPP2>. |
|
|
940 | |
932 | =item L<AnyEvent::IGS> |
941 | =item L<AnyEvent::IGS> |
933 | |
942 | |
934 | A non-blocking interface to the Internet Go Server protocol (used by |
943 | A non-blocking interface to the Internet Go Server protocol (used by |
935 | L<App::IGS>). |
944 | L<App::IGS>). |
936 | |
945 | |
937 | =item L<AnyEvent::IRC> |
|
|
938 | |
|
|
939 | AnyEvent based IRC client module family (replacing the older Net::IRC3). |
|
|
940 | |
|
|
941 | =item L<Net::XMPP2> |
|
|
942 | |
|
|
943 | AnyEvent based XMPP (Jabber protocol) module family. |
|
|
944 | |
|
|
945 | =item L<Net::FCP> |
946 | =item L<Net::FCP> |
946 | |
947 | |
947 | AnyEvent-based implementation of the Freenet Client Protocol, birthplace |
948 | AnyEvent-based implementation of the Freenet Client Protocol, birthplace |
948 | of AnyEvent. |
949 | of AnyEvent. |
949 | |
950 | |
… | |
… | |
953 | |
954 | |
954 | =item L<Coro> |
955 | =item L<Coro> |
955 | |
956 | |
956 | Has special support for AnyEvent via L<Coro::AnyEvent>. |
957 | Has special support for AnyEvent via L<Coro::AnyEvent>. |
957 | |
958 | |
958 | =item L<IO::Lambda> |
|
|
959 | |
|
|
960 | The lambda approach to I/O - don't ask, look there. Can use AnyEvent. |
|
|
961 | |
|
|
962 | =back |
959 | =back |
963 | |
960 | |
964 | =cut |
961 | =cut |
965 | |
962 | |
966 | package AnyEvent; |
963 | package AnyEvent; |
… | |
… | |
968 | no warnings; |
965 | no warnings; |
969 | use strict qw(vars subs); |
966 | use strict qw(vars subs); |
970 | |
967 | |
971 | use Carp; |
968 | use Carp; |
972 | |
969 | |
973 | our $VERSION = 4.8; |
970 | our $VERSION = 4.801; |
974 | our $MODEL; |
971 | our $MODEL; |
975 | |
972 | |
976 | our $AUTOLOAD; |
973 | our $AUTOLOAD; |
977 | our @ISA; |
974 | our @ISA; |
978 | |
975 | |
… | |
… | |
1123 | # allow only one watcher per fd, so we dup it to get a different one). |
1120 | # allow only one watcher per fd, so we dup it to get a different one). |
1124 | sub _dupfh($$;$$) { |
1121 | sub _dupfh($$;$$) { |
1125 | my ($poll, $fh, $r, $w) = @_; |
1122 | my ($poll, $fh, $r, $w) = @_; |
1126 | |
1123 | |
1127 | # cygwin requires the fh mode to be matching, unix doesn't |
1124 | # cygwin requires the fh mode to be matching, unix doesn't |
1128 | my ($rw, $mode) = $poll eq "r" ? ($r, "<") |
1125 | 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 | |
1126 | |
1132 | open my $fh2, "$mode&" . fileno $fh |
1127 | open my $fh2, "$mode&", $fh |
1133 | or die "cannot dup() filehandle: $!,"; |
1128 | or die "AnyEvent->io: cannot dup() filehandle in mode '$poll': $!,"; |
1134 | |
1129 | |
1135 | # we assume CLOEXEC is already set by perl in all important cases |
1130 | # we assume CLOEXEC is already set by perl in all important cases |
1136 | |
1131 | |
1137 | ($fh2, $rw) |
1132 | ($fh2, $rw) |
1138 | } |
1133 | } |
… | |
… | |
1470 | |
1465 | |
1471 | =item C<PERL_ANYEVENT_MAX_FORKS> |
1466 | =item C<PERL_ANYEVENT_MAX_FORKS> |
1472 | |
1467 | |
1473 | The maximum number of child processes that C<AnyEvent::Util::fork_call> |
1468 | The maximum number of child processes that C<AnyEvent::Util::fork_call> |
1474 | will create in parallel. |
1469 | will create in parallel. |
|
|
1470 | |
|
|
1471 | =item C<PERL_ANYEVENT_MAX_OUTSTANDING_DNS> |
|
|
1472 | |
|
|
1473 | The default value for the C<max_outstanding> parameter for the default DNS |
|
|
1474 | resolver - this is the maximum number of parallel DNS requests that are |
|
|
1475 | sent to the DNS server. |
|
|
1476 | |
|
|
1477 | =item C<PERL_ANYEVENT_RESOLV_CONF> |
|
|
1478 | |
|
|
1479 | The file to use instead of F</etc/resolv.conf> (or OS-specific |
|
|
1480 | configuration) in the default resolver. When set to the empty string, no |
|
|
1481 | default config will be used. |
|
|
1482 | |
|
|
1483 | =item C<PERL_ANYEVENT_CA_FILE>, C<PERL_ANYEVENT_CA_PATH>. |
|
|
1484 | |
|
|
1485 | When neither C<ca_file> nor C<ca_path> was specified during |
|
|
1486 | L<AnyEvent::TLS> context creation, and either of these environment |
|
|
1487 | variables exist, they will be used to specify CA certificate locations |
|
|
1488 | instead of a system-dependent default. |
1475 | |
1489 | |
1476 | =back |
1490 | =back |
1477 | |
1491 | |
1478 | =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE |
1492 | =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE |
1479 | |
1493 | |
… | |
… | |
2102 | L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>. |
2116 | L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>. |
2103 | |
2117 | |
2104 | Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>, |
2118 | Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>, |
2105 | L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, |
2119 | L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, |
2106 | L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>, |
2120 | L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>, |
2107 | L<AnyEvent::Impl::POE>. |
2121 | L<AnyEvent::Impl::POE>, L<AnyEvent::Impl::IOAsync>. |
2108 | |
2122 | |
2109 | Non-blocking file handles, sockets, TCP clients and |
2123 | Non-blocking file handles, sockets, TCP clients and |
2110 | servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>. |
2124 | servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>. |
2111 | |
2125 | |
2112 | Asynchronous DNS: L<AnyEvent::DNS>. |
2126 | Asynchronous DNS: L<AnyEvent::DNS>. |
2113 | |
2127 | |
2114 | Coroutine support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, L<Coro::Event>, |
2128 | Coroutine support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, |
|
|
2129 | L<Coro::Event>, |
2115 | |
2130 | |
2116 | Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>, L<AnyEvent::DNS>. |
2131 | Nontrivial usage examples: L<AnyEvent::GPSD>, L<AnyEvent::XMPP>, |
|
|
2132 | L<AnyEvent::HTTP>. |
2117 | |
2133 | |
2118 | |
2134 | |
2119 | =head1 AUTHOR |
2135 | =head1 AUTHOR |
2120 | |
2136 | |
2121 | Marc Lehmann <schmorp@schmorp.de> |
2137 | Marc Lehmann <schmorp@schmorp.de> |